Gathering detailed insights and metrics for detect-indent
Gathering detailed insights and metrics for detect-indent
Gathering detailed insights and metrics for detect-indent
Gathering detailed insights and metrics for detect-indent
npm install detect-indent
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.8
Supply Chain
99.5
Quality
75.9
Maintenance
100
Vulnerability
100
License
JavaScript (95.69%)
CSS (2.22%)
TypeScript (2.09%)
Total Downloads
3,432,117,958
Last Day
2,609,117
Last Week
11,804,833
Last Month
52,607,989
Last Year
713,519,570
196 Stars
72 Commits
27 Forks
9 Watching
1 Branches
13 Contributors
Minified
Minified + Gzipped
Latest Version
7.0.1
Package Id
detect-indent@7.0.1
Unpacked Size
9.52 kB
Size
3.96 kB
File Count
5
NPM Version
8.3.2
Node Version
14.19.3
Cumulative downloads
Total Downloads
Last day
-2.4%
2,609,117
Compared to previous day
Last week
-13.2%
11,804,833
Compared to previous week
Last month
1.2%
52,607,989
Compared to previous month
Last year
11.6%
713,519,570
Compared to previous year
4
Detect the indentation of code
Pass in a string of any kind of text and get the indentation.
$ npm install detect-indent
Here we modify a JSON file while persisting the indentation:
1import fs from 'node:fs'; 2import detectIndent from 'detect-indent'; 3 4/* 5{ 6 "ilove": "pizza" 7} 8*/ 9const file = fs.readFileSync('foo.json', 'utf8'); 10 11// Tries to detect the indentation and falls back to a default if it can't 12const indent = detectIndent(file).indent || ' '; 13 14const json = JSON.parse(file); 15 16json.ilove = 'unicorns'; 17 18fs.writeFileSync('foo.json', JSON.stringify(json, undefined, indent)); 19/* 20{ 21 "ilove": "unicorns" 22} 23*/
Accepts a string and returns an object with stats about the indentation:
amount
{number} - Amount of indentation, for example 2
type
{'tab' | 'space' | undefined} - Type of indentation. Possible values are 'tab'
, 'space'
or undefined
if no indentation is detectedindent
{string} - Actual indentationThe current algorithm looks for the most common difference between two consecutive non-empty lines.
In 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:
1html { 2 box-sizing: border-box; 3} 4 5body { 6 background: gray; 7} 8 9p { 10 line-height: 1.3em; 11 margin-top: 1em; 12 text-indent: 2em; 13}
Furthermore, if there are more than one most used difference, the indentation with the most lines is selected.
In the following example, the indentation is detected as 4-spaces:
1body { 2 background: gray; 3} 4 5p { 6 line-height: 1.3em; 7 margin-top: 1em; 8 text-indent: 2em; 9}
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
security policy file detected
Details
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 9/30 approved changesets -- score normalized to 3
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More@gwhitney/detect-indent
Detect the indentation of code (commonjs fork)
@types/detect-indent
Stub TypeScript definitions entry for detect-indent, which provides its own types definitions
string-detect-indent
simple detect string indent
detect-indentation
Utility to detect the indentation used in a string