Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
trim-newlines
Advanced tools
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.
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 10,852,188 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.