# terminating-newline

> Add or remove a terminating newline

Latest version **2.0.0** (published 2023-01-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install terminating-newline
pnpm add terminating-newline
yarn add terminating-newline
bun add terminating-newline
```

## 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.0.0 |
| Published | 2023-01-10 |
| First published | 2020-08-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^14.13.1 \|\| >=16.0.0 |
| Dependencies | 2 |
| Unpacked size | 9.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Connor White |
| Maintainers | bconnorwhite |
| Keywords | terminating, newline, add, remove, last, end, one, carriage, return, line, feed, unix, mac, windows, os |

## Links

- npm: https://www.npmjs.com/package/terminating-newline
- Repository: https://github.com/bconnorwhite/terminating-newline
- npm.io page: https://npm.io/package/terminating-newline

## Dependencies (2)

- [detect-newline](https://npm.io/package/detect-newline.md) ^4.0.0
- [ends-with-string](https://npm.io/package/ends-with-string.md) ^2.0.0

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 2.0.0 (latest) — 2023-01-10
- 1.2.4 — 2020-10-03
- 1.2.3 — 2020-10-03
- 1.2.2 — 2020-09-06
- 1.2.1 — 2020-09-05
- 1.2.0 — 2020-09-05
- 1.1.2 — 2020-09-05
- 1.1.1 — 2020-09-05
- 1.1.0 — 2020-09-05
- 1.0.1 — 2020-09-03
- 1.0.0 — 2020-08-29

## README

<!--BEGIN HEADER-->
<div id="top" align="center">
  <h1>terminating-newline</h1>
  <a href="https://npmjs.com/package/terminating-newline">
    <img alt="NPM" src="https://img.shields.io/npm/v/terminating-newline.svg">
  </a>
  <a href="https://github.com/bconnorwhite/terminating-newline">
    <img alt="TypeScript" src="https://img.shields.io/github/languages/top/bconnorwhite/terminating-newline.svg">
  </a>
  <a href="https://coveralls.io/github/bconnorwhite/terminating-newline?branch=master">
    <img alt="Coverage Status" src="https://img.shields.io/coveralls/github/bconnorwhite/terminating-newline.svg?branch=master">
  </a>
</div>

<br />

<blockquote align="center">Add or remove a terminating newline.</blockquote>

<br />

_If I should maintain this repo, please ⭐️_
<a href="https://github.com/bconnorwhite/terminating-newline">
  <img align="right" alt="GitHub stars" src="https://img.shields.io/github/stars/bconnorwhite/terminating-newline?label=%E2%AD%90%EF%B8%8F&style=social">
</a>

_DM me on [Twitter](https://twitter.com/bconnorwhite) if you have questions or suggestions._
<a href="https://twitter.com/bconnorwhite">
  <img align="right" alt="Twitter" src="https://img.shields.io/twitter/url?label=%40bconnorwhite&style=social&url=https%3A%2F%2Ftwitter.com%2Fbconnorwhite">
</a>

---
<!--END HEADER-->

Supports both line feeds (/n) and carriage return line feeds (/r/n). Will only add a newline if one does not already exist.

## Installation

```sh
yarn add terminating-newline
```

```sh
npm install terminating-newline
```

```sh
pnpm add terminating-newline
```

## API

### Usage
```ts
import {
  addTerminatingNewline,
  removeTerminatingNewline,
  lineFeed, // "\n"
  carriageReturnLineFeed // "/r/n"
} from "terminating-newline";

addTerminatingNewline("abc", { default: lineFeed }); // "abc/n"

addTerminatingNewline("abc\n", { default: lineFeed }); // "abc/n"

removeTerminatingNewline("abc\n"); // "abc"

```
### Types
```ts
function addTerminatingNewline(string: string, options?: Options): string;
function addTerminatingNewline(buffer: Buffer, options?: Options): Buffer;

function removeTerminatingNewline(string: string): string;
function removeTerminatingNewline(buffer: Buffer): Buffer;

type Options = {
  // Fallback if newline type cannot be determined. Default: "\n"
  default?: LineFeed | CarriageReturnLineFeed;
}

type LineFeed = "\n";

type CarriageReturnLineFeed = "\r\n";
```

<!--BEGIN FOOTER-->

<br />

<h2 id="dependencies">Dependencies<a href="https://www.npmjs.com/package/terminating-newline?activeTab=dependencies"><img align="right" alt="dependencies" src="https://img.shields.io/librariesio/release/npm/terminating-newline.svg"></a></h2>

- [detect-newline](https://www.npmjs.com/package/detect-newline): Detect the dominant newline character of a string
- [ends-with-string](https://www.npmjs.com/package/ends-with-string): Check if a string or buffer ends with a given string

<br />

<h3>Dev Dependencies</h3>

- [autorepo](https://www.npmjs.com/package/autorepo): Autorepo abstracts away your dev dependencies, providing a single command to run all of your scripts.

<br />

<h2 id="license">License <a href="https://opensource.org/licenses/MIT"><img align="right" alt="license" src="https://img.shields.io/npm/l/terminating-newline.svg"></a></h2>

[MIT](https://opensource.org/licenses/MIT)
<!--END FOOTER-->

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