detect-formatting
v0.1.0
Published
Detect the indentation, newline style, quotes style, and usage of semicolons of a JavaScript file.
Downloads
4
Readme
detect-formatting
Detect the indentation, newline style, quotes style, and usage of semicolons of a JavaScript file.
Installation
npm i detect-formatting
pnpm add detect-formatting
yarn add detect-formatting
bun add detect-formatting
Usage
import { detectIndent, detectNewline, detectSemicolon, detectQuotes } from 'detect-formatting';
import { readFileSync } from 'node:fs';
const file = readFileSync('index.js', 'utf-8');
detectIndent(file);
// { type: 'space' | 'tab', amount: number, indent: string } | undefined
detectNewline(file);
// { type: 'lf' | 'crlf', newline: '\n' | '\r\n' } | undefined
detectSemicolon(file);
// boolean | undefined
detectQuotes(file);
// { type: 'single' | 'double', quotes: "'" | '"' } | undefined
License
[!NOTE] The
detectIndent()
anddetectNewline()
functions are largely based on Sindre Sorhus' packages,detect-indent
anddetect-newline
. Licences for the two can be found inCOPYING.md
.