Socket
Socket
Sign inDemoInstall

detect-indent

Package Overview
Dependencies
1
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.1 to 4.0.0

5

index.js

@@ -0,1 +1,2 @@

/* eslint-disable guard-for-in */
'use strict';

@@ -21,3 +22,3 @@ var repeating = require('repeating');

maxWeight = w;
result = +n;
result = Number(n);
}

@@ -96,3 +97,3 @@ }

// if the last action was an indent, increment the weight
current[1] += +isIndent;
current[1] += Number(isIndent);
}

@@ -99,0 +100,0 @@ });

26

package.json
{
"name": "detect-indent",
"version": "3.0.1",
"version": "4.0.0",
"description": "Detect the indentation of code",

@@ -10,7 +10,4 @@ "license": "MIT",

"email": "sindresorhus@gmail.com",
"url": "http://sindresorhus.com"
"url": "sindresorhus.com"
},
"bin": {
"detect-indent": "cli.js"
},
"engines": {

@@ -20,11 +17,8 @@ "node": ">=0.10.0"

"scripts": {
"test": "mocha"
"test": "xo && ava"
},
"files": [
"index.js",
"cli.js"
"index.js"
],
"keywords": [
"cli",
"bin",
"indent",

@@ -43,9 +37,13 @@ "indentation",

"dependencies": {
"get-stdin": "^4.0.1",
"minimist": "^1.1.0",
"repeating": "^1.1.0"
"repeating": "^2.0.0"
},
"devDependencies": {
"mocha": "*"
"ava": "*",
"xo": "*"
},
"xo": {
"ignores": [
"fixture/**"
]
}
}

@@ -17,3 +17,3 @@ # detect-indent [![Build Status](https://travis-ci.org/sindresorhus/detect-indent.svg?branch=master)](https://travis-ci.org/sindresorhus/detect-indent)

```sh
```
$ npm install --save detect-indent

@@ -25,6 +25,8 @@ ```

Here we modify a JSON file while persisting the indentation:
```js
// modify a JSON file while persisting the indentation in Node
var fs = require('fs');
var detectIndent = require('detect-indent');
/*

@@ -36,4 +38,6 @@ {

var file = fs.readFileSync('foo.json', 'utf8');
// tries to detect the indentation and falls back to a default if it can't
var indent = detectIndent(file).indent || ' ';
var json = JSON.parse(file);

@@ -56,26 +60,7 @@

* `amount`: {Number} the amount of indentation, e.g. `2`
* `type`: {String|Null} the type of indentation. Possible values are `tab`, `space` or `null` if no indentation is detected
* `indent`: {String} the actual indentation
* `amount` {number} - Amount of indentation, e.g. `2`
* `type` {string|null} - Type of indentation. Possible values are `tab`, `space` or `null` if no indentation is detected
* `indent` {string} - Actual indentation
## CLI
```sh
$ npm install --global detect-indent
```
```
$ detect-indent --help
Usage
detect-indent <file>
echo <string> | detect-indent
Example
echo ' foo\n bar' | detect-indent | wc --chars
2
```
## Algorithm

@@ -93,3 +78,3 @@

body {
background: grey;
background: gray;
}

@@ -104,3 +89,3 @@

[Source](https://medium.com/@heatherarthur/detecting-code-indentation-eff3ed0fb56b#3918).
[Source.](https://medium.com/@heatherarthur/detecting-code-indentation-eff3ed0fb56b#3918)

@@ -113,3 +98,3 @@ Furthermore, if there are more than one most used difference, the indentation with the most lines is selected.

body {
background: grey;
background: gray;
}

@@ -125,4 +110,9 @@

## Related
- [detect-indent-cli](https://github.com/sindresorhus/detect-indent-cli) - CLI for this module
## License
MIT © [Sindre Sorhus](http://sindresorhus.com)
SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc