Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/uncenter/detect-formatting
🔍 Detect the indentation, newline style, quotes style, and usage of semicolons of a JavaScript file.
https://github.com/uncenter/detect-formatting
Last synced: 30 days ago
JSON representation
🔍 Detect the indentation, newline style, quotes style, and usage of semicolons of a JavaScript file.
- Host: GitHub
- URL: https://github.com/uncenter/detect-formatting
- Owner: uncenter
- License: mit
- Created: 2023-12-24T22:46:10.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-03-01T01:36:31.000Z (9 months ago)
- Last Synced: 2024-10-04T07:41:38.378Z (about 2 months ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/detect-formatting
- Size: 120 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: COPYING.md
Awesome Lists containing this project
README
# detect-formatting
Detect the indentation, newline style, quotes style, and usage of semicolons of a JavaScript file.
## Installation
```sh
npm i detect-formatting
pnpm add detect-formatting
yarn add detect-formatting
bun add detect-formatting
```## Usage
```ts
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](LICENSE)
> [!NOTE]
> The `detectIndent()` and `detectNewline()` functions are largely based on Sindre Sorhus' packages, [`detect-indent`](https://github.com/sindresorhus/detect-indent) and [`detect-newline`](https://github.com/sindresorhus/detect-newline). Licences for the two can be found in [`COPYING.md`](COPYING.md).