# trim-trailing-lines

> Remove final line feeds from a string

Latest version **2.1.0** (published 2022-11-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install trim-trailing-lines
pnpm add trim-trailing-lines
yarn add trim-trailing-lines
bun add trim-trailing-lines
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2022-11-14 |
| First published | 2015-07-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Titus Wormer |
| Maintainers | wooorm |
| Keywords | trim, final, line, newline, characters |

## Links

- npm: https://www.npmjs.com/package/trim-trailing-lines
- Repository: https://github.com/wooorm/trim-trailing-lines
- Homepage: https://github.com/wooorm/trim-trailing-lines#readme
- Issues: https://github.com/wooorm/trim-trailing-lines/issues
- Funding: https://github.com/sponsors/wooorm
- npm.io page: https://npm.io/package/trim-trailing-lines

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 2.1.0 (latest) — 2022-11-14
- 2.0.0 — 2021-03-10
- 1.1.4 — 2020-10-28
- 1.1.3 — 2020-01-25
- 1.1.2 — 2019-05-11
- 1.1.1 — 2018-04-28
- 1.1.0 — 2016-11-23
- 1.0.0 — 2015-07-12

## 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
<script type="module">
  import {trimTrailingLines} from 'https://esm.sh/trim-trailing-lines@2?bundle'
</script>
```

## 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]

<!-- Definitions -->

[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

---
_Source: https://npm.io/package/trim-trailing-lines · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
