Skip to content
Trim newlines from the start and/or end of a string
JavaScript TypeScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Tidelift tasks May 31, 2019
.editorconfig
.gitattributes
.gitignore
.npmrc Require Node.js 8, add TypeScript definition (#1) Apr 29, 2019
.travis.yml
index.d.ts Require Node.js 8, add TypeScript definition (#1) Apr 29, 2019
index.js Improve the regex (#2) May 28, 2019
index.test-d.ts
license Require Node.js 8, add TypeScript definition (#1) Apr 29, 2019
package.json 3.0.0 Apr 29, 2019
readme.md Tidelift tasks May 31, 2019
test.js

readme.md

trim-newlines Build Status

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

Install

$ npm install trim-newlines

Usage

const trimNewlines = require('trim-newlines');

trimNewlines('\n🦄\r\n');
//=> '🦄'

trimNewlines.start('\n🦄\r\n');
//=> '🦄\r\n'

trimNewlines.end('\n🦄\r\n');
//=> '\n🦄'

API

trimNewlines(string)

Trim from the start and end of a string.

trimNewlines.start(string)

Trim from the start of a string.

trimNewlines.end(string)

Trim from the end of a string.

Related

  • trim-left - Similar to String#trim() but removes only whitespace on the left
  • trim-right - Similar to String#trim() but removes only whitespace on the right.

Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
You can’t perform that action at this time.