https://github.com/fabiospampinato/detect-eol
Quickly detect the EOL used in a string.
https://github.com/fabiospampinato/detect-eol
detect eol fast newline nl quick
Last synced: 7 months ago
JSON representation
Quickly detect the EOL used in a string.
- Host: GitHub
- URL: https://github.com/fabiospampinato/detect-eol
- Owner: fabiospampinato
- License: mit
- Created: 2020-01-29T16:51:08.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-04-04T22:32:00.000Z (over 1 year ago)
- Last Synced: 2025-03-01T23:16:26.525Z (7 months ago)
- Topics: detect, eol, fast, newline, nl, quick
- Language: TypeScript
- Size: 11.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# Detect EOL
Quickly detect the EOL used in a string.
## Features
- This returns the most common type of EOL found in the string within a given window length, or the first EOL found after that, or the fallback EOL.
- You can set the window length to 0 to just assume consistent EOLs, for maximum performance.
- You can set the window length to Infinity to scan the entire string, for maximum accuracy.## Install
```sh
npm install --save detect-eol
```## Usage
The function has the following interface:
```ts
function ( string: string, options: { fallback: string = '\n', window: number = 1024 } ): string;
```You can use it like this:
```ts
import detectEOL from 'detect-eol';
import os from 'os';detectEOL ( 'foo\nbar' ); // => '\n'
detectEOL ( 'foo\r\nbar' ); // => '\r\n'
detectEOL ( 'foo\rbar' ); // => '\r'
detectEOL ( '' ); // => '\n'
detectEOL ( '', { fallback: os.EOL } ); // => os.EOL
```## License
MIT © Fabio Spampinato