Quickly detect the EOL used in a string.
- 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.
npm install --save detect-eol
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
MIT © Fabio Spampinato