{"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"keywords":["indent","indentation","detect","infer","identify","code","string","text","source","space","tab"],"dist-tags":{"latest":"5.0.0"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"description":"Detect the indentation of code","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```\n$ npm install --save detect-indent\n```\n\n\n## Usage\n\nHere we modify a JSON file while persisting the indentation:\n\n```js\nconst fs = require('fs');\nconst detectIndent = require('detect-indent');\n\n/*\n{\n    \"ilove\": \"pizza\"\n}\n*/\nconst file = fs.readFileSync('foo.json', 'utf8');\n\n// tries to detect the indentation and falls back to a default if it can't\nconst indent = detectIndent(file).indent || '    ';\n\nconst 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} - Amount of indentation, for example `2`\n* `type` {string|null} - Type of indentation. Possible values are `tab`, `space` or `null` if no indentation is detected\n* `indent` {string} - Actual indentation\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: gray;\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: gray;\n}\n\np {\n    line-height: 1.3em;\n    margin-top: 1em;\n    text-indent: 2em;\n}\n```\n\n\n## Related\n\n- [detect-indent-cli](https://github.com/sindresorhus/detect-indent-cli) - CLI for this module\n- [detect-newline](https://github.com/sindresorhus/detect-newline) - Detect the dominant newline character of a string\n\n\n## License\n\nMIT © [Sindre Sorhus](https://sindresorhus.com)\n","repository":{"type":"git","url":"git+https://github.com/sindresorhus/detect-indent.git"},"users":{"passy":true,"johnnyscript":true,"demian_dark":true,"rocket0191":true},"bugs":{"url":"https://github.com/sindresorhus/detect-indent/issues"},"license":"MIT","versions":{"0.1.0":{"name":"detect-indent","version":"0.1.0","description":"Detect the indentation of code","keywords":["indent","indentation","detect","infer","identify","code","string","text","source","space","tab"],"homepage":"https://github.com/sindresorhus/detect-indent","bugs":{"url":"https://github.com/sindresorhus/detect-indent/issues"},"license":"MIT","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"http://sindresorhus.com"},"files":["detect-indent.js"],"main":"detect-indent","repository":{"type":"git","url":"git://github.com/sindresorhus/detect-indent.git"},"scripts":{"test":"mocha && phantomjs node_modules/mocha-phantomjs/lib/mocha-phantomjs.coffee test/test.html"},"devDependencies":{"mocha":"~1.12.0","chai":"~1.7.2","phantomjs":"~1.9.1","mocha-phantomjs":"~3.1.0"},"engines":{"node":">=0.8.0"},"_id":"detect-indent@0.1.0","dist":{"shasum":"b071bdece3312b9669147950e7aefb2e5d392327","tarball":"http://nexus.dui88.com:8081/nexus/content/groups/npm-all/detect-indent/-/detect-indent-0.1.0.tgz"},"_from":".","_npmVersion":"1.2.32","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{}},"0.1.1":{"name":"detect-indent","version":"0.1.1","description":"Detect the indentation of code","keywords":["indent","indentation","detect","infer","identify","code","string","text","source","space","tab"],"homepage":"https://github.com/sindresorhus/detect-indent","bugs":{"url":"https://github.com/sindresorhus/detect-indent/issues"},"license":"MIT","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"http://sindresorhus.com"},"files":["detect-indent.js"],"main":"detect-indent","repository":{"type":"git","url":"git://github.com/sindresorhus/detect-indent.git"},"scripts":{"test":"mocha && phantomjs node_modules/mocha-phantomjs/lib/mocha-phantomjs.coffee test/test.html"},"devDependencies":{"mocha":"~1.12.0","chai":"~1.7.2","phantomjs":"~1.9.1","mocha-phantomjs":"~3.1.0"},"engines":{"node":">=0.8.0"},"_id":"detect-indent@0.1.1","dist":{"shasum":"55316047de5171c613a3a205af6a6fcfcda2710d","tarball":"http://nexus.dui88.com:8081/nexus/content/groups/npm-all/detect-indent/-/detect-indent-0.1.1.tgz"},"_from":".","_npmVersion":"1.2.32","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{}},"0.1.2":{"name":"detect-indent","version":"0.1.2","description":"Detect the indentation of code","keywords":["indent","indentation","detect","infer","identify","code","string","text","source","space","tab"],"homepage":"https://github.com/sindresorhus/detect-indent","bugs":{"url":"https://github.com/sindresorhus/detect-indent/issues"},"license":"MIT","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"http://sindresorhus.com"},"files":["detect-indent.js"],"main":"detect-indent","repository":{"type":"git","url":"git://github.com/sindresorhus/detect-indent.git"},"scripts":{"test":"mocha && phantomjs node_modules/mocha-phantomjs/lib/mocha-phantomjs.coffee test/test.html"},"devDependencies":{"mocha":"~1.12.0","chai":"~1.7.2","phantomjs":"~1.9.1","mocha-phantomjs":"~3.1.0"},"engines":{"node":">=0.8.0"},"_id":"detect-indent@0.1.2","dist":{"shasum":"b9c31d35d514df22a8ec3725783da824c5f23c03","tarball":"http://nexus.dui88.com:8081/nexus/content/groups/npm-all/detect-indent/-/detect-indent-0.1.2.tgz"},"_from":".","_npmVersion":"1.3.8","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{}},"0.1.3":{"name":"detect-indent","version":"0.1.3","description":"Detect the indentation of code","keywords":["indent","indentation","detect","infer","identify","code","string","text","source","space","tab"],"homepage":"https://github.com/sindresorhus/detect-indent","bugs":{"url":"https://github.com/sindresorhus/detect-indent/issues"},"license":"MIT","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"http://sindresorhus.com"},"files":["detect-indent.js"],"main":"detect-indent","repository":{"type":"git","url":"git://github.com/sindresorhus/detect-indent.git"},"scripts":{"test":"mocha && phantomjs node_modules/mocha-phantomjs/lib/mocha-phantomjs.coffee test/test.html"},"devDependencies":{"mocha":"~1.12.0","chai":"~1.7.2","phantomjs":"~1.9.1","mocha-phantomjs":"~3.1.0"},"engines":{"node":">=0.8.0"},"_id":"detect-indent@0.1.3","dist":{"shasum":"76e6cf5a5fc734e3b4eec4060a43ecd32ecad9f9","tarball":"http://nexus.dui88.com:8081/nexus/content/groups/npm-all/detect-indent/-/detect-indent-0.1.3.tgz"},"_from":".","_npmVersion":"1.3.10","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{}},"0.1.4":{"name":"detect-indent","version":"0.1.4","description":"Detect the indentation of code","keywords":["indent","indentation","detect","infer","identify","code","string","text","source","space","tab"],"license":"MIT","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"http://sindresorhus.com"},"files":["detect-indent.js"],"main":"detect-indent","repository":{"type":"git","url":"git://github.com/sindresorhus/detect-indent.git"},"scripts":{"test":"mocha && phantomjs node_modules/mocha-phantomjs/lib/mocha-phantomjs.coffee test/test.html"},"devDependencies":{"mocha":"~1.12.0","chai":"~1.7.2","phantomjs":"~1.9.1","mocha-phantomjs":"~3.1.0"},"engines":{"node":">=0.8.0"},"bugs":{"url":"https://github.com/sindresorhus/detect-indent/issues"},"homepage":"https://github.com/sindresorhus/detect-indent","_id":"detect-indent@0.1.4","dist":{"shasum":"c28e1303c1c4ad5ce0549902b884043afc5906b0","tarball":"http://nexus.dui88.com:8081/nexus/content/groups/npm-all/detect-indent/-/detect-indent-0.1.4.tgz"},"_from":".","_npmVersion":"1.4.6","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{}},"0.2.0":{"name":"detect-indent","version":"0.2.0","description":"Detect the indentation of code","license":"MIT","repository":{"type":"git","url":"git://github.com/sindresorhus/detect-indent"},"bin":{"detect-indent":"cli.js"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"http://sindresorhus.com"},"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":"^0.1.0","minimist":"^0.1.0"},"devDependencies":{"mocha":"*"},"bugs":{"url":"https://github.com/sindresorhus/detect-indent/issues"},"homepage":"https://github.com/sindresorhus/detect-indent","_id":"detect-indent@0.2.0","_shasum":"042914498979ac2d9f3c73e4ff3e6877d3bc92b6","_from":".","_npmVersion":"1.4.9","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"dist":{"shasum":"042914498979ac2d9f3c73e4ff3e6877d3bc92b6","tarball":"http://nexus.dui88.com:8081/nexus/content/groups/npm-all/detect-indent/-/detect-indent-0.2.0.tgz"},"directories":{}},"1.0.0":{"name":"detect-indent","version":"1.0.0","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":"^3.0.0","minimist":"^1.1.0","strip-comments":"^0.3.2"},"devDependencies":{"mocha":"*"},"gitHead":"86440344bcefa5245076e6c6516ac1b2d80a4ef1","bugs":{"url":"https://github.com/sindresorhus/detect-indent/issues"},"homepage":"https://github.com/sindresorhus/detect-indent","_id":"detect-indent@1.0.0","_shasum":"17f17ae5b44c740ae89bd386b495187b378a0456","_from":".","_npmVersion":"1.4.23","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"dist":{"shasum":"17f17ae5b44c740ae89bd386b495187b378a0456","tarball":"http://nexus.dui88.com:8081/nexus/content/groups/npm-all/detect-indent/-/detect-indent-1.0.0.tgz"},"directories":{}},"1.0.1":{"name":"detect-indent","version":"1.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":"^3.0.0","minimist":"^1.1.0","strip-comments":"^0.3.2"},"devDependencies":{"mocha":"*"},"gitHead":"e9caef6f10d89963f55fc0d42e061d770e96683e","bugs":{"url":"https://github.com/sindresorhus/detect-indent/issues"},"homepage":"https://github.com/sindresorhus/detect-indent","_id":"detect-indent@1.0.1","_shasum":"86f3496242b52c910d49876cb993add8bed1f1bd","_from":".","_npmVersion":"2.1.2","_nodeVersion":"0.10.32","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"dist":{"shasum":"86f3496242b52c910d49876cb993add8bed1f1bd","tarball":"http://nexus.dui88.com:8081/nexus/content/groups/npm-all/detect-indent/-/detect-indent-1.0.1.tgz"},"directories":{}},"2.0.0":{"name":"detect-indent","version":"2.0.0","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":"^3.0.0","minimist":"^1.1.0","repeating":"^1.1.0"},"devDependencies":{"mocha":"*"},"gitHead":"401f402f06ecc897ba6726440ec93375673d4cc0","bugs":{"url":"https://github.com/sindresorhus/detect-indent/issues"},"homepage":"https://github.com/sindresorhus/detect-indent","_id":"detect-indent@2.0.0","_shasum":"720ff51e4d97b76884f6bf57292348b13dfde939","_from":".","_npmVersion":"2.1.4","_nodeVersion":"0.10.32","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"dist":{"shasum":"720ff51e4d97b76884f6bf57292348b13dfde939","tarball":"http://nexus.dui88.com:8081/nexus/content/groups/npm-all/detect-indent/-/detect-indent-2.0.0.tgz"},"directories":{}},"3.0.0":{"name":"detect-indent","version":"3.0.0","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":"^3.0.0","minimist":"^1.1.0","repeating":"^1.1.0"},"devDependencies":{"mocha":"*"},"gitHead":"303b97bc44497bbfeb01eb4ea27753c82156aef6","bugs":{"url":"https://github.com/sindresorhus/detect-indent/issues"},"homepage":"https://github.com/sindresorhus/detect-indent","_id":"detect-indent@3.0.0","_shasum":"7a12c4b61be4ebc170cd6d416ce43754124637d8","_from":".","_npmVersion":"2.1.5","_nodeVersion":"0.10.32","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"dist":{"shasum":"7a12c4b61be4ebc170cd6d416ce43754124637d8","tarball":"http://nexus.dui88.com:8081/nexus/content/groups/npm-all/detect-indent/-/detect-indent-3.0.0.tgz"},"directories":{}},"3.0.1":{"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":"*"},"gitHead":"c046bec94ac5eefeb67ae4501d556c8dcec2914e","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":".","_npmVersion":"2.5.1","_nodeVersion":"0.12.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"dist":{"shasum":"9dc5e5ddbceef8325764b9451b02bc6d54084f75","tarball":"http://nexus.dui88.com:8081/nexus/content/groups/npm-all/detect-indent/-/detect-indent-3.0.1.tgz"},"directories":{}},"4.0.0":{"name":"detect-indent","version":"4.0.0","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":"sindresorhus.com"},"engines":{"node":">=0.10.0"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["indent","indentation","detect","infer","identify","code","string","text","source","space","tab"],"dependencies":{"repeating":"^2.0.0"},"devDependencies":{"ava":"*","xo":"*"},"xo":{"ignores":["fixture/**"]},"gitHead":"dbbc78fcb37907116eb120a8324070a1df0e8d86","bugs":{"url":"https://github.com/sindresorhus/detect-indent/issues"},"homepage":"https://github.com/sindresorhus/detect-indent","_id":"detect-indent@4.0.0","_shasum":"f76d064352cdf43a1cb6ce619c4ee3a9475de208","_from":".","_npmVersion":"2.13.3","_nodeVersion":"3.0.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"f76d064352cdf43a1cb6ce619c4ee3a9475de208","tarball":"http://nexus.dui88.com:8081/nexus/content/groups/npm-all/detect-indent/-/detect-indent-4.0.0.tgz"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"directories":{}},"5.0.0":{"name":"detect-indent","version":"5.0.0","description":"Detect the indentation of code","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/detect-indent.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=4"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["indent","indentation","detect","infer","identify","code","string","text","source","space","tab"],"devDependencies":{"ava":"*","xo":"*"},"xo":{"esnext":true},"gitHead":"6c7485c2e5b74abc11a8870b550a9d385beac9e0","bugs":{"url":"https://github.com/sindresorhus/detect-indent/issues"},"homepage":"https://github.com/sindresorhus/detect-indent#readme","_id":"detect-indent@5.0.0","_shasum":"3871cc0a6a002e8c3e5b3cf7f336264675f06b9d","_from":".","_npmVersion":"2.15.9","_nodeVersion":"4.6.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"3871cc0a6a002e8c3e5b3cf7f336264675f06b9d","tarball":"http://nexus.dui88.com:8081/nexus/content/groups/npm-all/detect-indent/-/detect-indent-5.0.0.tgz"},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/detect-indent-5.0.0.tgz_1476992892715_0.3219247553497553"},"directories":{}}},"name":"detect-indent","time":{"modified":"2017-03-27T00:35:35.971Z","created":"2013-08-11T00:28:27.860Z","0.1.0":"2013-08-11T00:28:31.046Z","0.1.1":"2013-08-13T17:54:38.934Z","0.1.2":"2013-08-30T08:34:24.581Z","0.1.3":"2013-09-25T22:03:28.005Z","0.1.4":"2014-04-29T19:20:03.852Z","0.2.0":"2014-06-16T16:40:58.661Z","1.0.0":"2014-09-11T11:02:05.021Z","1.0.1":"2014-10-03T22:36:45.242Z","2.0.0":"2014-10-26T03:05:04.210Z","3.0.0":"2014-11-23T03:45:43.877Z","3.0.1":"2015-02-16T17:31:25.306Z","4.0.0":"2015-09-07T09:38:01.807Z","5.0.0":"2016-10-20T19:48:14.523Z"},"readmeFilename":"readme.md","homepage":"https://github.com/sindresorhus/detect-indent#readme"}