https://github.com/wooorm/trim-trailing-lines
Remove final newline characters from a string
https://github.com/wooorm/trim-trailing-lines
end line newline right tail trail trim
Last synced: about 2 months ago
JSON representation
Remove final newline characters from a string
- Host: GitHub
- URL: https://github.com/wooorm/trim-trailing-lines
- Owner: wooorm
- License: mit
- Created: 2015-07-12T15:40:42.000Z (almost 10 years ago)
- Default Branch: main
- Last Pushed: 2022-11-14T09:33:50.000Z (over 2 years ago)
- Last Synced: 2025-04-12T18:53:20.230Z (about 2 months ago)
- Topics: end, line, newline, right, tail, trail, trim
- Language: JavaScript
- Homepage:
- Size: 56.6 KB
- Stars: 5
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# trim-trailing-lines
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]Remove final line endings from a string.
## Contents
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`trimTrailingLines(value)`](#trimtrailinglinesvalue)
* [Types](#types)
* [Compatibility](#compatibility)
* [Contribute](#contribute)
* [Security](#security)
* [License](#license)## What is this?
This is a tiny package that removes final line endings (CR, LF, CR+LF) from a
string.## When should I use this?
This package is rather niche, I found myself repeating this code when working
with a lot of markdown.## Install
This package is [ESM only][esm].
In Node.js (version 14.14+, 16.0+), install with [npm][]:```sh
npm install trim-trailing-lines
```In Deno with [`esm.sh`][esmsh]:
```js
import {trimTrailingLines} from 'https://esm.sh/trim-trailing-lines@2'
```In browsers with [`esm.sh`][esmsh]:
```html
import {trimTrailingLines} from 'https://esm.sh/trim-trailing-lines@2?bundle'
```
## Use
```js
import {trimTrailingLines} from 'trim-trailing-lines'trimTrailingLines('foo\nbar') // => 'foo\nbar'
trimTrailingLines('foo\nbar\n') // => 'foo\nbar'
trimTrailingLines('foo\nbar\n\n') // => 'foo\nbar'
```## API
This package exports the identifier `trimTrailingLines`.
There is no default export.### `trimTrailingLines(value)`
Remove final line endings from `value`.
##### Parameters
###### `valeu`
Value with trailing line endings, coerced to string (`unknown`).
##### Returns
Value without trailing line endings (`string`).
## Types
This package is fully typed with [TypeScript][].
It exports no additional types.## Compatibility
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.## Contribute
Yes please!
See [How to Contribute to Open Source][contribute].## Security
This package is safe.
## License
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/wooorm/trim-trailing-lines/workflows/main/badge.svg
[build]: https://github.com/wooorm/trim-trailing-lines/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/trim-trailing-lines.svg
[coverage]: https://codecov.io/github/wooorm/trim-trailing-lines
[downloads-badge]: https://img.shields.io/npm/dm/trim-trailing-lines.svg
[downloads]: https://www.npmjs.com/package/trim-trailing-lines
[size-badge]: https://img.shields.io/bundlephobia/minzip/trim-trailing-lines.svg
[size]: https://bundlephobia.com/result?p=trim-trailing-lines
[npm]: https://docs.npmjs.com/cli/install
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[esmsh]: https://esm.sh
[typescript]: https://www.typescriptlang.org
[contribute]: https://opensource.guide/how-to-contribute/
[license]: license
[author]: https://wooorm.com