Miss any of our Open RFC calls?Watch the recordings here! »

detect-eol

1.0.0 • Public • Published

Detect EOL

Quickly detect the EOL used in a string.

It assumes EOLs are used consistenly, for performance, if instead you want some kind of statistical analisys you can use detect-newline, which runs about 150 times slower than this even for short strings though.

Install

npm install --save detect-eol

Usage

The function has the following shape:

function ( str: string, fallback: string = '\n' ): string;

You can use it like this:

import detectEOL from 'detect-eol';
import * as OS from 'os';
 
detectEOL ( 'foo\nbar' ); // => '\n'
detectEOL ( 'foo\r\nbar' ); // => '\r\n'
detectEOL ( 'foo\rbar' ); // => '\r'
detectEOL ( '' ); // => '\n'
detectEOL ( '', OS.EOL ); // => OS.EOL

License

MIT © Fabio Spampinato

Install

npm i detect-eol

DownloadsWeekly Downloads

4

Version

1.0.0

License

MIT

Unpacked Size

6.79 kB

Total Files

10

Last publish

Collaborators

  • avatar