Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

detect-indent

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

detect-indent - npm Package Compare versions

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)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc