detect-indent
Advanced tools
Comparing version 1.0.0 to 1.0.1
20
index.js
'use strict'; | ||
var strip = require('strip-comments'); | ||
@@ -14,9 +13,11 @@ | ||
// Strip multi-line comments, and normalize | ||
var re = /^([ \t]*)/; | ||
var result = []; | ||
var t = 0; | ||
var s = 0; | ||
// strip multi-line comments and normalize | ||
str = strip.block(str).replace(/\r/g, ''); | ||
var re = /^([ \t]*)/; | ||
var result = [], t = 0, s = 0; | ||
str.split(/\n/g).forEach(function(line) { | ||
str.split(/\n/g).forEach(function (line) { | ||
/^\t/.test(line) ? t++ : s++; | ||
@@ -30,2 +31,3 @@ | ||
} | ||
result.push(len); | ||
@@ -45,3 +47,7 @@ }); | ||
return {amount: amount, type: type, indent: actual}; | ||
return { | ||
amount: amount, | ||
type: type, | ||
indent: actual | ||
}; | ||
}; |
{ | ||
"name": "detect-indent", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Detect the indentation of code", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -35,3 +35,3 @@ # detect-indent [![Build Status](https://travis-ci.org/sindresorhus/detect-indent.svg?branch=master)](https://travis-ci.org/sindresorhus/detect-indent) | ||
// tries to detect the indentation and falls back to a default if it can't | ||
var detected = detectIndent(file) || ' '; | ||
var indent = detectIndent(file).indent || ' '; | ||
var json = JSON.parse(file); | ||
@@ -41,3 +41,3 @@ | ||
fs.writeFileSync('foo.json', JSON.stringify(json, null, detected.indent)); | ||
fs.writeFileSync('foo.json', JSON.stringify(json, null, indent)); | ||
/* | ||
@@ -79,4 +79,9 @@ { | ||
## Algorithm | ||
It first strips off multi-line comments. Then goes through each line counting whether it's tabs or spaces and the indent size coerced to an even number. The resulting indent size is the GCD (Greates Common Divisor) of the gathered line indent sizes and the type is the most used type. | ||
## License | ||
MIT © [Sindre Sorhus](http://sindresorhus.com) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4695
86
85