Security News
The Dark Side of Open Source
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
trim-newlines
Advanced tools
Package description
The trim-newlines npm package is used to remove newlines from the start and/or end of a string. It provides a simple way to trim newline characters from the beginning, end, or both ends of a string, which can be useful when processing text data.
Start
Removes newline characters from the start of a string.
const trimNewlines = require('trim-newlines');
console.log(trimNewlines.start('\n\nUnicorn\n'));
//=> 'Unicorn\n'
End
Removes newline characters from the end of a string.
const trimNewlines = require('trim-newlines');
console.log(trimNewlines.end('Unicorn\n\n'));
//=> 'Unicorn'
Start and End
Removes newline characters from both the start and end of a string.
const trimNewlines = require('trim-newlines');
console.log(trimNewlines('\n\nUnicorn\n\n'));
//=> 'Unicorn'
The 'trim' package is similar to 'trim-newlines' but it trims all whitespace characters from the beginning and end of a string, not just newlines.
The 'lodash.trim' function from the Lodash library is another alternative that trims whitespace from the beginning and end of a string. It is part of a larger utility library and offers more customization options than 'trim-newlines'.
The 'string.prototype.trim' package is a polyfill for the native JavaScript String.prototype.trim method, which removes whitespace from both ends of a string. It is similar to 'trim-newlines' but targets all whitespace, not just newlines.
Readme
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()
.
npm install trim-newlines
import {trimNewlines, trimNewlinesStart, trimNewlinesEnd} from 'trim-newlines';
trimNewlines('\n🦄\n🦄\r\n');
//=> '🦄\n🦄'
trimNewlinesStart('\n🦄\r\n');
//=> '🦄\r\n'
trimNewlinesEnd('\n🦄\r\n');
//=> '\n🦄'
Trim from the start and end of a string.
Trim from the start of a string.
Trim from the end of a string.
FAQs
Trim newlines from the start and/or end of a string
The npm package trim-newlines receives a total of 14,209,300 weekly downloads. As such, trim-newlines popularity was classified as popular.
We found that trim-newlines demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.