Urara-Blog/node_modules/.pnpm-store/v3/files/80/690b168374ad51f739b268432ceaa850bbc62daec7f3b762210700ebc4e1e3698a208678fb2e0df01488bac060fc3bb6345c107dbee163a81b5f336ed8cc9c
2022-08-14 01:14:53 +08:00

50 lines
945 B
Text

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;