eol opensource newline conversion

eol is an opensource newline conversion node module. eol helps you smoothly convert line endings in node applications. eol is written in JavaScript and supports TypeScript too. The words newline, linebreak, line ending are used interchangeably here. They mark an end of line. Feel free to play with eol in the console on this page for learning purposes.

methods

eol.auto(text)
Normalize text to match the current operating system
Returns string with line endings normalized accordingly
eol.crlf(text)
Normalize line endings in text to CRLF (Windows, DOS)
Returns string normalized to \r\n line endings
eol.lf(text)
Normalize line endings in text to LF (Unix, OS X)
Returns string normalized to \n line endings
eol.cr(text)
Normalize line endings in text to CR (Mac OS)
Returns string normalized to \r line endings
eol.dub(text)
Generate normalizer that replaces line endings with text
Returns composed pure function like methods above
Normalizers are usable as glue to join arrays
eol.before(text)
Add linebreak before text
Returns string with linebreak added before text
eol.after(text)
Add linebreak after text
Returns string with linebreak added after text
eol.match(text)
Detect or inspect linebreaks in text
Returns array of matched linebreaks
eol.split(text)
Split text by newline
Returns array of lines

samples

normalizing

eol.lf("hello\r\nworld\r\n")
// "hello\nworld\n"

remove empty lines

eol.split(text).filter(line => line).join(eol.lf)

detect or inspect

eol.match("hello\nworld\n")
// ["\n","\n"]

coercion

String(eol.lf) // "\n"
String(eol.cr) // "\r"
String(eol.crlf) // "\r\n"

generating normalizers

let lflf = eol.dub("\n\n")
lflf("hello\nworld\n")
// "hello\n\nworld\n\n"