What is trim-off-newlines?
The trim-off-newlines npm package is a utility that allows you to trim newlines from the start and end of a string. It is useful for cleaning up strings that may have extraneous newline characters.
What are trim-off-newlines's main functionalities?
Trim newlines from the start and end of a string
This feature removes all newline characters from the beginning and end of the input string, leaving the core content intact.
const trimOffNewlines = require('trim-off-newlines');
const input = '\n\nHello, World!\n\n';
const output = trimOffNewlines(input);
console.log(output); // 'Hello, World!'
Trim newlines from the start of a string
This feature removes newline characters only from the beginning of the input string.
const trimOffNewlines = require('trim-off-newlines');
const input = '\n\nHello, World!\n\n';
const output = trimOffNewlines.start(input);
console.log(output); // 'Hello, World!\n\n'
Trim newlines from the end of a string
This feature removes newline characters only from the end of the input string.
const trimOffNewlines = require('trim-off-newlines');
const input = '\n\nHello, World!\n\n';
const output = trimOffNewlines.end(input);
console.log(output); // '\n\nHello, World!'
Other packages similar to trim-off-newlines
trim-newlines
The trim-newlines package provides similar functionality by allowing you to trim newlines from the start and end of a string. It offers a straightforward API for removing extraneous newline characters.
strip-newlines
The strip-newlines package removes all newline characters from a string, not just from the start and end. This can be useful if you need to completely eliminate newlines from a string.
trim-off-newlines
Similar to String#trim()
but removes only newlines
Install
$ npm install --save trim-off-newlines
Usage
var trimOffNewlines = require('trim-off-newlines');
trimOffNewlines('\n\nunicorns\n\n');
Related
trim-left
- Similar to String#trim()
but removes only whitespace on the lefttrim-right
- Similar to String#trim()
but removes only whitespace on the right
License
MIT © Steve Mao