An open API service indexing awesome lists of open source software.

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.

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