Security News
New Proposed CISA Mandate Would Require Critical Infrastructure to Report Ransom Payments Within 24 Hours
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
strip-final-newline
Advanced tools
Strip the final newline character from a string/buffer
Weekly downloads
Package description
The strip-final-newline npm package is a simple utility that removes the final newline character from a string. This can be useful when you want to process text data and ensure that it does not end with a newline character, which might affect the handling of the text in certain situations.
Strip final newline from a string
This feature allows you to remove the final newline character from a given string. The code sample demonstrates how to use the strip-final-newline package to strip the newline from the end of a string.
const stripFinalNewline = require('strip-final-newline');
const stringWithNewline = 'Hello World!\n';
const stringWithoutNewline = stripFinalNewline(stringWithNewline);
console.log(stringWithoutNewline); // 'Hello World!'
The newline-remove package is similar to strip-final-newline in that it is designed to remove newline characters from strings. However, it may offer different options or behaviors, such as removing all newline characters, not just the final one.
The trim-newlines package offers functionality to trim newline characters from the start and/or end of a string. It provides more options than strip-final-newline, which only removes the final newline character.
Readme
Strip the final newline character from a string/buffer
Can be useful when parsing the output of, for example, ChildProcess#execFile
, as binaries usually output a newline at the end. Normally, you would use stdout.trim()
, but that would also remove newlines at the start and whitespace.
$ npm install strip-final-newline
import stripFinalNewline from 'strip-final-newline';
stripFinalNewline('foo\nbar\n\n');
//=> 'foo\nbar\n'
stripFinalNewline(Buffer.from('foo\nbar\n\n')).toString();
//=> 'foo\nbar\n'
FAQs
Strip the final newline character from a string or Uint8Array
The npm package strip-final-newline receives a total of 34,782,255 weekly downloads. As such, strip-final-newline popularity was classified as popular.
We found that strip-final-newline demonstrated a healthy version release cadence and project activity because the last version was released less than 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
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
Security News
Redis is no longer OSS, breaking its explicit commitment to remain under the BSD 3-Clause License forever. This has angered contributors who are now working to fork the software.
Product
Socket AI now enables 'AI detected potential malware' alerts by default, ensuring users benefit from AI-powered state-of-the-art malware detection without needing to opt-in.