Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

normalize-newline

sindresorhus276.9kMIT5.0.0TypeScript support: included

Normalize the newline characters in a string to \n

newline, linebreak, line, lf, crlf, eol, linefeed, character, char, normalize, convert, replace

readme

normalize-newline

Normalize the 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

npm install normalize-newline

Usage

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.