detect-eol
TypeScript icon, indicating that this package has built-in type declarations

3.0.1 • Public • Published

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

Package Sidebar

Install

npm i detect-eol

Weekly Downloads

204

Version

3.0.1

License

none

Unpacked Size

8.37 kB

Total Files

16

Last publish

Collaborators

  • fabiospampinato