detect-formatting
v0.1.0
Published
Detect the indentation, newline style, quotes style, and usage of semicolons of a JavaScript file.
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-formattingUsage
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: "'" | '"' } | undefinedLicense
[!NOTE] The
detectIndent()anddetectNewline()functions are largely based on Sindre Sorhus' packages,detect-indentanddetect-newline. Licences for the two can be found inCOPYING.md.
