What is eol?
The eol npm package is designed to handle end-of-line (EOL) characters in strings, making it easier to manage cross-platform newline characters in a consistent manner. It provides utilities to convert, detect, and remove line endings.
What are eol's main functionalities?
Convert to specific EOL type
Converts all end-of-line characters in a string to Unix line endings (LF). Useful for ensuring consistent EOL characters in a multi-platform development environment.
const eol = require('eol');
let unixText = eol.lf('Hello\r\nWorld'); // Converts to LF (\n) line endings
Auto-detect and normalize EOL
Automatically detects and normalizes the end-of-line characters in a string to the system's default EOL setting. This is particularly useful for handling text input from various sources with differing EOL conventions.
const eol = require('eol');
let normalizedText = eol.auto('Hello\r\nWorld'); // Normalizes to the default system EOL
Remove all EOL characters
Strips all end-of-line characters from a string, which can be useful for creating single-line strings from multiline input.
const eol = require('eol');
let cleanText = eol.strip('Hello\r\nWorld'); // Removes all EOL characters
Other packages similar to eol
newline-remove
Similar to the 'strip' functionality of eol, newline-remove provides a method to remove all newline characters from a string. It does not, however, offer conversion between different types of EOL characters.
crlf-helper
This package offers conversion between LF and CRLF line endings, similar to eol's conversion features. However, crlf-helper focuses specifically on these two types of line endings and does not include automatic detection or normalization to the system's default EOL.
Newline character converter node module for JavaScript or TypeScript
npm install eol
let eol = require("eol")
import eol from "eol"
eol.auto(text)
- Normalize line endings in text to match the current operating system
- Returns string with line endings normalized to
\r\n
or \n
eol.crlf(text)
- Normalize line endings in text to CRLF (Windows, DOS)
- Returns string with line endings normalized to
\r\n
eol.lf(text)
- Normalize line endings in text to LF (Unix, OS X)
- Returns string with line endings normalized to
\n
eol.cr(text)
- Normalize line endings in text to CR (Mac OS)
- Returns string with line endings normalized to
\r
eol.dub(text)
eol.before(text)
- Add linebreak before text
- Returns string with linebreak added before text
- Uses
eol.auto
linebreak eol.lf(eol.before(text))
⋮
eol.after(text)
- Add linebreak after text
- Returns string with linebreak added after text
- Uses
eol.auto
linebreak eol.lf(eol.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
Joining
Coercing normalizers to string yields the appropriate character...useful glue for joining
String(eol.lf)
eol.split(text).join(eol.auto)
eol.split(text).filter(line => line).join(eol.auto)
eol.split(text).slice(-3).join(eol.auto)
Matching
Detect or inspect via match
eol.match(" ")
eol.match("world\nwide\nweb")
Dubbing
Generate alternate normalizers
let extra = eol.dub("\n\n\n")
extra("...")
let huh = eol.dub("???")
huh("...")
modularitY
let eol = require("eol")
let edit = require("edit-file")
edit("sample.txt", eol.lf)
let eol = require("eol")
let map = require("map-file")
map({
from: "from.txt",
to: "to.txt",
map: eol.lf
})
let ssv = require("ssv")
let eol = require("eol")
let deep = eol.split("spaced.txt").map(ssv.split)
Yours
Have an eol
sample to share?
Then please do :test_tube: :test_tube: :test_tube: :test_tube:
MIT License
∞/0