GithubHelp home page GithubHelp logo

trim-newlines's Introduction

trim-newlines

Trim newlines from the start and/or end of a string

Looking to trim all whitespace, not just newlines? Use String#trim(), String#trimStart(), or String#trimEnd().

Install

npm install trim-newlines

Usage

import {trimNewlines, trimNewlinesStart, trimNewlinesEnd} from 'trim-newlines';

trimNewlines('\n๐Ÿฆ„\n๐Ÿฆ„\r\n');
//=> '๐Ÿฆ„\n๐Ÿฆ„'

trimNewlinesStart('\n๐Ÿฆ„\r\n');
//=> '๐Ÿฆ„\r\n'

trimNewlinesEnd('\n๐Ÿฆ„\r\n');
//=> '\n๐Ÿฆ„'

API

trimNewlines(string)

Trim from the start and end of a string.

trimNewlinesStart(string)

Trim from the start of a string.

trimNewlinesEnd(string)

Trim from the end of a string.

trim-newlines's People

Contributors

bendingbender avatar mickstar avatar richienb avatar sindresorhus avatar tommy-mitchell 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

trim-newlines's Issues

v5 could export default trimNewlines

v5 causes an unnecessary breakage where you could still provide a default export of trimNewlines so that people don't get things like:

โœ– stylelint scss:
file:///home/neale/dev/solum/solum-xplain-ui/node_modules/stylelint/node_modules/meow/index.js:9
import trimNewlines from 'trim-newlines';
       ^^^^^^^^^^^^
SyntaxError: The requested module 'trim-newlines' does not provide an export named 'default'

Use named exports instead

  • trimNewlines
  • trimNewlinesStart
  • trimNewlinesEnd

I'm unlikely to do this anytime soon, but this is a reminder for the next major version.

The risk of CVE-2021-33623 could not be assessed

I received some security warnings

`trim-newlines` before 3.0.1 and 4.x before 4.0.1 for Node.js has an issue related to regular expression denial-of-service (ReDoS) for the .end() method.
$ npm ls trim-newlines

...
โ””โ”€โ”ฌ@commitlint/[email protected]
  โ””โ”€โ”ฌ @commitlint/[email protected]
    โ””โ”€โ”ฌ @commitlint/[email protected]
      โ”œโ”€โ”ฌ [email protected]
        โ””โ”€โ”€ [email protected]

โ””โ”€โ”ฌ [email protected]
  โ””โ”€โ”ฌ [email protected]
    โ””โ”€โ”€ [email protected]

โ””โ”€โ”ฌ [email protected]
  โ””โ”€โ”ฌ @lerna/[email protected]
    โ””โ”€โ”ฌ @lerna/[email protected]
      โ”œโ”€โ”ฌ [email protected]
      โ”‚ โ”œโ”€โ”ฌ [email protected]
      โ”‚ โ”‚ โ””โ”€โ”ฌ [email protected]
      โ”‚ โ”‚   โ””โ”€โ”€ [email protected] 
      โ”‚ โ”œโ”€โ”ฌ [email protected]
      โ”‚ โ”‚ โ””โ”€โ”ฌ [email protected]
      โ”‚ โ”‚   โ””โ”€โ”€ [email protected] 
      โ”‚ โ””โ”€โ”ฌ [email protected]
      โ”‚   โ””โ”€โ”ฌ [email protected]
      โ”‚     โ””โ”€โ”€ [email protected] 
      โ””โ”€โ”ฌ [email protected]
        โ””โ”€โ”ฌ [email protected]
          โ””โ”€โ”€ [email protected] 

For many web projects @commitlint/cli,stylelint, lerna are common and basic dependencies

I have some questions about this and whether we need to spend so much effort to upgrade

Even lerna doesn't have an available version to solve this problem


I want to make sure that this is really a serious problem ?



Add support for both CJS and ESM

Using this package in Node JS with any other packages written in CJS is hardly possible.
Would be cool to have both formats in one package.

It's as easy as adding to package.json:

"exports": {
    ".": {
      "require": "./index.cjs", // CJS
      "import": "./index.mjs"   // ESM
    }
}

Source: https://antfu.me/posts/publish-esm-and-cjs

I see a lot of packages, that migrate to ESM without providing any backward compatibility, rendering those packages almost impossible to use in a real dev environment.

If you are not sure, that still supporting CJS is a good thing, take a look at package statistics:
image

It's 17x more downloads for CJS version than ESM one.

CVE-2021-33623 is a lie

Hi! I'm here because of a dependabot alert on a project using stylelint which ends up depending on this package.

$ npm ls trim-newlines
...
โ””โ”€โ”ฌ [email protected]
  โ””โ”€โ”ฌ [email protected]
    โ””โ”€โ”€ [email protected]

essence The security issue that claims to have been fixed in 25246c6 does not exist.

Rather than diving into the details of how exponential backtracking can happen with regexps (and whether that's really worth a CVE in the first place), it's pretty easy to show the original code was not affected. Just revert your implementation change and re-run the tests you added - they still pass. Get them to print timings - the time for all input sizes is ~0ms.

It's not clear to me how CVE-2021-33623 was reported and assigned. Some kind of external CVE stuffing exercise?

As this just seems to be a library you made to help your own projects I'm not going wave left-pad around too much, but will point out the original (and perfectly fine) implementation is 4 lines of code.

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.