Remove final line endings from a string.
- What is this?
- When should I use this?
- Install
- Use
- API
- Types
- Compatibility
- Contribute
- Security
- License
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.
Remove final line endings from value
.
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.