{"_id":"@gwhitney/detect-indent","_rev":"2-f5f879f9182c0472fd066888ab94adae","name":"@gwhitney/detect-indent","dist-tags":{"latest":"7.0.2"},"versions":{"7.0.1":{"name":"@gwhitney/detect-indent","version":"7.0.1","keywords":["indent","indentation","detect","infer","identify","code","string","text","source","space","tab"],"author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"license":"MIT","_id":"@gwhitney/detect-indent@7.0.1","maintainers":[{"name":"gwhitney","email":"glen@studioinfinity.org"}],"homepage":"https://github.com/gwhitney/detect-indent#readme","bugs":{"url":"https://github.com/gwhitney/detect-indent/issues"},"xo":{"rules":{"unicorn/prefer-module":"off"},"ignores":["fixture"]},"dist":{"shasum":"db16d7fe6d13b26dc792442e5156677b44cc428e","tarball":"https://registry.npmjs.org/@gwhitney/detect-indent/-/detect-indent-7.0.1.tgz","fileCount":5,"integrity":"sha512-7bQW+gkKa2kKZPeJf6+c6gFK9ARxQfn+FKy9ScTBppyKRWH2KzsmweXUoklqeEiHiNVWaeP5csIdsNq6w7QhzA==","signatures":[{"sig":"MEUCIENKDSeBQRgHVyQ5PGOlU9IsQtvtFPvpIOj2Avkt7+VFAiEAtgcsNaW5NBo1d4+RW3XhlmmcDKArFaIU/9kH8pRZIZs=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":10374,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjfNeaACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmo+2Q//cvoxt/8uHTnwRC1ONovVwo5V3+krfw6U5c1e9ErUL9PhyqJ8\r\nR63tJm1wYXcqgKExiV52+gRq5G/s6nanUVYbqR+ZdzTQJKuDKMW1p5o9DpUt\r\nyQe3EllVtwoMKni9GTLdabynr80zsFGhjQKr26PPQ86S8dlfQAaY8PgJFc+g\r\nzGHHsOdVu6iePDB1AwUqKXZhKXbyA+WFoA/8EH+F20RXR7FEBTEUWeM3lgwn\r\ntbDRv3cf4/QKtfJLmo8yS1BI0RFu0fS1odXOK7pFTdZP9B1zrkL8wKFwsORY\r\nDlR/D7ljqPae3edfxOi84jUUg4xLX09g3aUjzcoiKFHlluUzDD4PnCAgmF2/\r\nou/233CoqrU3o4wmu1jP0Kkp0e5JQYNBnAUmAKOwGVJbI8z8f9pvVxsKzY+g\r\nUzbVTpOD2Eg4tV/uLvWlK6lCYDiaMS3wV6lukDb1kJqeBJWqEOrV8hFUEJaJ\r\nYpFW+rMmmlWm5wHwiR2JEO2jnKYFeNDn/chpDEDgWaRMX2SPEWD4clOUDlR1\r\n7SxRX148vHBZisSqm7JXK5jdFN0bRZDfYWufx3hZqDSlU/nj98c1/CP6xffL\r\nRYfTCgvfu+rKN5EKC2qcqzwgy4Crf9ZipVPAJ5LulDuDsoCZxVcVBkTDc8TT\r\nqROmvI+OPIdj66i6hkV49PRIaeq6iRpETFA=\r\n=h01G\r\n-----END PGP SIGNATURE-----\r\n"},"types":"./index.d.ts","engines":{"node":">=12.20"},"exports":"./index.js","gitHead":"9a9832f0c96f8d3c70f000c11d9da5a8ef15c1bf","scripts":{"test":"xo && ava && tsd"},"_npmUser":{"name":"gwhitney","email":"glen@studioinfinity.org"},"repository":{"url":"git+https://github.com/gwhitney/detect-indent.git","type":"git"},"_npmVersion":"8.19.3","description":"Detect the indentation of code (commonjs fork)","directories":{},"_nodeVersion":"19.1.0","_hasShrinkwrap":false,"devDependencies":{"xo":"^0.44.0","ava":"^3.15.0","tsd":"^0.17.0","typescript":"^4.3.5"},"_npmOperationalInternal":{"tmp":"tmp/detect-indent_7.0.1_1669126042187_0.8578880263789046","host":"s3://npm-registry-packages"}},"7.0.2":{"name":"@gwhitney/detect-indent","version":"7.0.2","description":"Detect the indentation of code (commonjs fork)","license":"MIT","repository":{"type":"git","url":"git+https://github.com/gwhitney/detect-indent.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"exports":"./index.js","types":"./index.d.ts","sideEffects":false,"engines":{"node":">=12.20"},"scripts":{"test":"xo && ava && tsd"},"keywords":["indent","indentation","detect","infer","identify","code","string","text","source","space","tab"],"devDependencies":{"ava":"^3.15.0","tsd":"^0.17.0","xo":"^0.44.0"},"xo":{"ignores":["fixture"],"rules":{"unicorn/prefer-module":"off"}},"gitHead":"bdbf0593684e3ac666a7a1bb8485eb69540ba2ba","_id":"@gwhitney/detect-indent@7.0.2","bugs":{"url":"https://github.com/gwhitney/detect-indent/issues"},"homepage":"https://github.com/gwhitney/detect-indent#readme","_nodeVersion":"22.15.1","_npmVersion":"11.6.4","dist":{"integrity":"sha512-8TggvKn5pKu1Yt7BkcLEmxeDU0CmbBCaHVgDqs0RPbbOFIi3pJEX6Qv+H/v6V21D/hvBPcR0b+1SnDbK0xZnEg==","shasum":"00286252010f899b6a30b8f69791e25be52e1f60","tarball":"https://registry.npmjs.org/@gwhitney/detect-indent/-/detect-indent-7.0.2.tgz","fileCount":5,"unpackedSize":10529,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIEMY/62j/qKHybnEZj/pS2ibyjkoL5wjESnnmzSMDtdfAiBdalcTXpTyb4KVjtBMjmAOVZ2dtDSLCH0uPV8kr7GWyQ=="}]},"_npmUser":{"name":"gwhitney","email":"glen@studioinfinity.org"},"directories":{},"maintainers":[{"name":"gwhitney","email":"glen@studioinfinity.org"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/detect-indent_7.0.2_1765225900990_0.7981507743160015"},"_hasShrinkwrap":false}},"time":{"created":"2022-11-22T14:07:22.147Z","modified":"2025-12-08T20:31:41.381Z","7.0.1":"2022-11-22T14:07:22.341Z","7.0.2":"2025-12-08T20:31:41.189Z"},"bugs":{"url":"https://github.com/gwhitney/detect-indent/issues"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"license":"MIT","homepage":"https://github.com/gwhitney/detect-indent#readme","keywords":["indent","indentation","detect","infer","identify","code","string","text","source","space","tab"],"repository":{"type":"git","url":"git+https://github.com/gwhitney/detect-indent.git"},"description":"Detect the indentation of code (commonjs fork)","maintainers":[{"name":"gwhitney","email":"glen@studioinfinity.org"}],"readme":"# detect-indent\n\n> Detect the indentation of code (commonjs fork)\n\n> **NOTE:** This is a fork of sindresorhus/detect-indent modified solely\n> to revert to providing CommonJS exports. It was created only to provide\n> an upgrade path for detect-indent in the `pnpm` Node package manager.\n> It is intended to be kept in sync with the upstream `detect-indent` and\n> use identical version numbers. The creator of this fork neither endorses\n> nor criticizes the convention decisions on the part of the maintainers/\n> authors of `pnpm` and `detect-indent` that led to the necessity of this\n> fork.\n\nPass in a string of any kind of text and get the indentation.\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## Install\n\n```sh\nnpm install detect-indent\n```\n\n## Usage\n\nHere we modify a JSON file while persisting the indentation:\n\n```js\nconst fs = require('node: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, undefined, indent));\n/*\n{\n    \"ilove\": \"unicorns\"\n}\n*/\n```\n\n## API\n\nAccepts a string and returns an object with stats about the indentation:\n\n- `type` {'tab' | 'space' | undefined} - The type of indentation. It is `undefined` if no indentation is detected.\n- `amount` {number} - The amount of indentation. For example, `2`.\n- `indent` {string} - The actual indentation.\n\n## Algorithm\n\nThe current algorithm looks for the most common difference between two consecutive non-empty lines. Single-space indentations and changes are ignored by default to prevent common false positives from comment alignment.\n\nIn the following example, even if 4-space indentation appears 3 times while 2-space appears only 2 times, the 2-space indentation is detected because there are 4 indent changes of 2 spaces vs only 2 changes of 4 spaces:\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 multiple indent differences with the same usage count, 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## 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- [detect-indent-rs](https://github.com/stefanpenner/detect-indent-rs) - Rust port\n- [detect-indent-py](https://github.com/Ethan-Vanderheijden/detect-indent-py) - Python port\n","readmeFilename":"readme.md"}