
Security News
Open Source CAI Framework Handles Pen Testing Tasks up to 3,600× Faster Than Humans
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
trim-trailing-lines
Advanced tools
The npm package 'trim-trailing-lines' is designed to remove trailing newline characters from a string. This is particularly useful in text processing where consistent formatting is required, or when preparing output for further processing that does not handle trailing newlines well.
Trim trailing newlines
This feature allows you to remove all trailing newline characters from the end of a string. It is useful for cleaning up text data before saving or processing it further.
const trimTrailingLines = require('trim-trailing-lines');
const result = trimTrailingLines('Hello World\n\n');
console.log(result); // 'Hello World'
Similar to 'trim-trailing-lines', 'trim-newlines' offers functionality to trim newlines from the start, end, or both ends of a string. It provides a bit more flexibility compared to 'trim-trailing-lines' which only removes trailing newlines.
This package also removes trailing newlines from strings. It is quite similar to 'trim-trailing-lines' but differs slightly in implementation. Users might choose one over the other based on specific project dependencies or slight differences in performance.
Remove final line endings from a string.
This is a tiny package that removes final line endings (CR, LF, CR+LF) from a string.
This package is rather niche, I found myself repeating this code when working with a lot of markdown.
This package is ESM only. In Node.js (version 14.14+, 16.0+), install with npm:
npm install trim-trailing-lines
In Deno with esm.sh
:
import {trimTrailingLines} from 'https://esm.sh/trim-trailing-lines@2'
In browsers with esm.sh
:
<script type="module">
import {trimTrailingLines} from 'https://esm.sh/trim-trailing-lines@2?bundle'
</script>
import {trimTrailingLines} from 'trim-trailing-lines'
trimTrailingLines('foo\nbar') // => 'foo\nbar'
trimTrailingLines('foo\nbar\n') // => 'foo\nbar'
trimTrailingLines('foo\nbar\n\n') // => 'foo\nbar'
This package exports the identifier trimTrailingLines
.
There is no default export.
trimTrailingLines(value)
Remove final line endings from value
.
valeu
Value with trailing line endings, coerced to string (unknown
).
Value without trailing line endings (string
).
This package is fully typed with TypeScript. It exports no additional types.
This package is at least compatible with all maintained versions of Node.js. As of now, that is Node.js 14.14+ and 16.0+. It also works in Deno and modern browsers.
Yes please! See How to Contribute to Open Source.
This package is safe.
FAQs
Remove final line feeds from a string
The npm package trim-trailing-lines receives a total of 2,213,514 weekly downloads. As such, trim-trailing-lines popularity was classified as popular.
We found that trim-trailing-lines 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
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.