JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 13918915
  • Score
    100M100P100Q220348F
  • License MIT

Detect the indentation of code

Package Exports

  • detect-indent

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (detect-indent) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

detect-indent Build Status

Detect the indentation of code

Pass in a string and get the indentation. Works in Node.js and the browser on any kind of text.

Use cases

  • Persisting the indentation when modifying a file.
  • Setting the right indentation in your editor.

Install

Download the library manually or with a package-manager.

npm

npm install --save detect-indent

Bower

bower install --save detect-indent

Component

component install sindresorhus/detect-indent

API

Accepts a string and returns the indentation or null if it can't be detected.

Example

Modify a JSON file while persisting the indentation in Node.js.

var fs = require('fs');
var detectIndent = require('detect-indent');
/*
{
    "ilove": "pizza"
}
*/
var file = fs.readFileSync('foo.json', 'utf8');
// tries to detect the indentation and falls back to a default if it can't
var indent = detectIndent(file) || '    ';
var json = JSON.parse(file);

json.ilove = 'unicorns';

fs.writeFileSync('foo.json', JSON.stringify(json, null, indent));
/*
{
    "ilove": "unicorns"
}
*/

License

MIT License • © Sindre Sorhus