{"name":"detect-indent","version":"3.0.1","description":"Detect the indentation of code","license":"MIT","repository":{"type":"git","url":"https://github.com/sindresorhus/detect-indent"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"http://sindresorhus.com"},"bin":{"detect-indent":"cli.js"},"engines":{"node":">=0.10.0"},"scripts":{"test":"mocha"},"files":["index.js","cli.js"],"keywords":["cli","bin","indent","indentation","detect","infer","identify","code","string","text","source","space","tab"],"dependencies":{"get-stdin":"^4.0.1","minimist":"^1.1.0","repeating":"^1.1.0"},"devDependencies":{"mocha":"*"},"readme":"# detect-indent [![Build Status](https://travis-ci.org/sindresorhus/detect-indent.svg?branch=master)](https://travis-ci.org/sindresorhus/detect-indent)\n\n> Detect the indentation of code\n\nPass in a string of any kind of text and get the indentation.\n\n\n## Use cases\n\n- Persisting the indentation when modifying a file.\n- Have new content match the existing indentation.\n- Setting the right indentation in your editor.\n\n\n## Install\n\n```sh\n$ npm install --save detect-indent\n```\n\n\n## Usage\n\n```js\n// modify a JSON file while persisting the indentation in Node\nvar fs = require('fs');\nvar detectIndent = require('detect-indent');\n/*\n{\n    \"ilove\": \"pizza\"\n}\n*/\nvar file = fs.readFileSync('foo.json', 'utf8');\n// tries to detect the indentation and falls back to a default if it can't\nvar indent = detectIndent(file).indent || '    ';\nvar json = JSON.parse(file);\n\njson.ilove = 'unicorns';\n\nfs.writeFileSync('foo.json', JSON.stringify(json, null, indent));\n/*\n{\n    \"ilove\": \"unicorns\"\n}\n*/\n```\n\n\n## API\n\nAccepts a string and returns an object with stats about the indentation:  \n\n* `amount`: {Number} the amount of indentation, e.g. `2`  \n* `type`: {String|Null} the type of indentation. Possible values are `tab`, `space` or `null` if no indentation is detected  \n* `indent`: {String} the actual indentation\n\n\n## CLI\n\n```sh\n$ npm install --global detect-indent\n```\n\n```\n$ detect-indent --help\n\n  Usage\n    detect-indent <file>\n    echo <string> | detect-indent\n\n  Example\n    echo '  foo\\n  bar' | detect-indent | wc --chars\n    2\n```\n\n\n## Algorithm\n\nThe current algorithm looks for the most common difference between two consecutive non-empty lines.\n\nIn the following example, even if the 4-space indentation is used 3 times whereas the 2-space one is used 2 times, it is detected as less used because there were only 2 differences with this value instead of 4 for the 2-space indentation:\n\n```css\nhtml {\n  box-sizing: border-box;\n}\n\nbody {\n  background: grey;\n}\n\np {\n    line-height: 1.3em;\n    margin-top: 1em;\n    text-indent: 2em;\n}\n```\n\n[Source](https://medium.com/@heatherarthur/detecting-code-indentation-eff3ed0fb56b#3918).\n\nFurthermore, if there are more than one most used difference, the indentation with the most lines is selected.\n\nIn the following example, the indentation is detected as 4-spaces:\n\n```css\nbody {\n  background: grey;\n}\n\np {\n    line-height: 1.3em;\n    margin-top: 1em;\n    text-indent: 2em;\n}\n```\n\n\n## License\n\nMIT © [Sindre Sorhus](http://sindresorhus.com)\n","readmeFilename":"readme.md","bugs":{"url":"https://github.com/sindresorhus/detect-indent/issues"},"homepage":"https://github.com/sindresorhus/detect-indent","_id":"detect-indent@3.0.1","_shasum":"9dc5e5ddbceef8325764b9451b02bc6d54084f75","_from":"https://registry.npmjs.org/detect-indent/-/detect-indent-3.0.1.tgz","_resolved":"https://registry.npmjs.org/detect-indent/-/detect-indent-3.0.1.tgz"}