JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 79952
  • Score
    100M100P100Q156695F
  • License MIT

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

Package Exports

  • normalize-newline

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.