# normalize-newline

> Normalize the newline characters in a string to `\n`

Latest version **5.0.0** (published 2025-09-16) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 55/100 (C)** — status: stable.

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

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 5.0.0 |
| Published | 2025-09-16 |
| First published | 2014-06-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=20 |
| Dependencies | 0 |
| Unpacked size | 3.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 30 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | newline, linebreak, line, lf, crlf, eol, linefeed, character, char, normalize, convert, replace |

## Links

- npm: https://www.npmjs.com/package/normalize-newline
- Repository: https://github.com/sindresorhus/normalize-newline
- Homepage: https://github.com/sindresorhus/normalize-newline#readme
- Issues: https://github.com/sindresorhus/normalize-newline/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/normalize-newline

## Alternatives

- [d3-force-3d](https://npm.io/package/d3-force-3d.md) — 1.0M weekly downloads
- [ng2-charts](https://npm.io/package/ng2-charts.md) — 486.8K weekly downloads
- [@arcgis/core](https://npm.io/package/@arcgis/core.md) — 257.8K weekly downloads
- [react-sparklines](https://npm.io/package/react-sparklines.md) — 249.3K weekly downloads
- [react-native-gifted-charts](https://npm.io/package/react-native-gifted-charts.md) — 182.3K weekly downloads

## Recent versions

- 5.0.0 (latest) — 2025-09-16
- 4.1.0 — 2021-05-09
- 4.0.0 — 2021-04-07
- 3.0.0 — 2016-09-06
- 2.1.0 — 2016-09-06
- 2.0.0 — 2015-12-22
- 1.0.2 — 2015-02-16
- 1.0.1 — 2014-08-17
- 1.0.0 — 2014-08-14
- 0.1.0 — 2014-06-28

## README

# normalize-newline

> Normalize the [newline](https://en.wikipedia.org/wiki/Newline) characters in a string to `\n`

Converts Windows-style CRLF (`\r\n`) line endings to Unix-style LF (`\n`). Works in both Node.js and browsers.

## Install

```sh
npm install normalize-newline
```

## Usage

```js
import normalizeNewline from 'normalize-newline';

normalizeNewline('foo\r\nbar\nbaz');
//=> 'foo\nbar\nbaz'

const uint8Array = new TextEncoder().encode('foo\r\nbar\nbaz');
const normalized = normalizeNewline(uint8Array);
new TextDecoder().decode(normalized);
//=> 'foo\nbar\nbaz'
```

## API

### normalizeNewline(input)

Normalizes CRLF (`\r\n`) to LF (`\n`). Other newline characters (`\r` or `\n` alone) are left unchanged.

#### input

Type: `string | Uint8Array`

Input to normalize.

## Related

- [normalize-newline-cli](https://github.com/sindresorhus/normalize-newline-cli) - CLI for this module

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