Newline character converter for JavaScript. Available on npm.
npm install eol --save
require
or import
const eol = require('eol')
import eol from 'eol'
eol.auto(text)
\r\n
or \n
eol.crlf(text)
\r\n
eol.lf(text)
\n
eol.cr(text)
\r
eol.before(text)
eol.after(text)
eol.split(text)
Coercing eol.auto
|eol.crlf
|eol.lf
|eol.cr
to string yields the appropriate character. This is useful for joining.
String(eol.lf) // "\n"
eol.split(text).join(eol.auto) // same as eol.auto(text)
eol.split(text).filter(line => line).join(eol.auto) // text joined after removing empty lines
eol.split(text).slice(-3).join(eol.auto) // last 3 lines joined
MIT
Copyright 2013 - present © cnpmjs.org