File size: 945 Bytes
be5030f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
declare namespace detectIndent {
	interface Indent {
		/**
		Type of indentation. Is `undefined` if no indentation is detected.
		*/
		type: 'tab' | 'space' | undefined;

		/**
		Amount of indentation, for example `2`.
		*/
		amount: number;

		/**
		Actual indentation.
		*/
		indent: string;
	}
}

/**
Detect the indentation of code.

@param string - A string of any kind of text.

@example
```
import * as fs from 'fs';
import detectIndent = require('detect-indent');

// {
//     "ilove": "pizza"
// }
const file = fs.readFileSync('foo.json', 'utf8');

// Tries to detect the indentation and falls back to a default if it can't
const indent = detectIndent(file).indent || '    ';

const json = JSON.parse(file);

json.ilove = 'unicorns';

fs.writeFileSync('foo.json', JSON.stringify(json, null, indent));
// {
//     "ilove": "unicorns"
// }
```
*/
declare function detectIndent(string: string): detectIndent.Indent;

export = detectIndent;