0.1.0 • Published 5 months ago

detect-formatting v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

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

MIT

!NOTE The detectIndent() and detectNewline() functions are largely based on Sindre Sorhus' packages, detect-indent and detect-newline. Licences for the two can be found in COPYING.md.

0.1.0

5 months ago