3.0.1 • Published 1 month ago

detect-eol v3.0.1

Weekly downloads
3
License
-
Repository
github
Last release
1 month ago

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

npm install --save detect-eol

Usage

The function has the following interface:

function ( string: string, options: { fallback: string = '\n', window: number = 1024 } ): string;

You can use it like this:

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