Socket
Socket
Sign inDemoInstall

eol

Package Overview
Dependencies
0
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    eol

Newline character converter


Version published
Weekly downloads
1.3M
increased by2.92%
Maintainers
1
Install size
12.8 kB
Created
Weekly downloads
 

Package description

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

Readme

Source

eol

Newline character converter for JavaScript. Available on npm.

npm install eol --save

require or import

const eol = require('eol')
import eol from 'eol'

API

eol.auto(text)

  • Normalize line endings in text for the current operating system
  • @return string with line endings normalized to \r\n or \n

eol.crlf(text)

  • Normalize line endings in text to CRLF (Windows, DOS)
  • @return string with line endings normalized to \r\n

eol.lf(text)

  • Normalize line endings in text to LF (Unix, OS X)
  • @return string with line endings normalized to \n

eol.cr(text)

  • Normalize line endings in text to CR (Mac OS)
  • @return string with line endings normalized to \r

eol.before(text)

  • Add linebreak before text
  • @return string with linebreak added before text

eol.after(text)

  • Add linebreak after text
  • @return string with linebreak added after text

eol.split(text)

  • Split text by newline
  • @return array of lines

Joining

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

License

MIT

Keywords

FAQs

Last updated on 06 Sep 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc