Git Product home page Git Product logo

eol's Introduction

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.dub(text)

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.match(text)

  • Detect or inspect linebreaks in text
  • @return array of matched linebreaks

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

Matching

Detect or inspect via match

eol.match(' ') // []
eol.match('world\nwide\nweb') // ['\n','\n']

Dubbing

Mixin friendly

let lflf = eol.dub("\n\n")
lflf("...")

got space?

MIT License

eol's People

Contributors

chrismbarr avatar ryanve avatar usergenic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

eol's Issues

Split functions into modules

Most often, only some of the functions in the library are used...

Can we divide the eol.js into separate modules?
Then we can only use the functions we need here like this:

import split from 'eol/split';

Backward compatibility will be, if we leave the assembled version of the entry point.

Exclude index.html from published NPM package

This issue stems from the presence of index.html within the project, which serves as an example. This file includes a vulnerable version of jQuery ([email protected]). Considering that this HTML file is merely an example and is not intended for direct usage within projects, its inclusion tends to pop up in vulnerability scanners like MEND (which is the case for me).

Proposed Solution:
excluding index.html from the npm package by adding it to the .npmignore file.

Base branch update

Context

Currently the base is gh-pages because I was working on a web UI. Github Pages can now work from master . Having master as the base seems more standard.

Plan

  1. Change base branch to be master
  2. Delete gh-pages branch

Inverse functions

After the eol.split() and the machinations with the lines, I need to collect an array of lines back into the string...
The problem is that I do not know what linebreak to use for array.join()...

Maybe we will add support eol.getLinebreak() or/and eol.join(array)?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.