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

Package detail

split-lines

sindresorhus506.3kMIT3.0.0TypeScript support: included

Split lines into an array of lines

split, lines, line, string, str, newline, newlines, linebreak, line-break, lf, crlf, eol, linefeed

readme

split-lines

Split lines into an array of lines

Install

$ npm install split-lines

Usage

import splitLines from 'split-lines';

splitLines('foo\r\nbar\r\nbaz\nrainbow');
//=> ['foo', 'bar', 'baz', 'rainbow']

splitLines('foo\r\nbar\r\nbaz\nrainbow', {preserveNewlines: true});
//=> ['foo\r\n', 'bar\r\n', 'baz\n', 'rainbow']

API

splitLines(string, options?)

string

Type: string

String to split.

options

Type: object

preserveNewlines

Type: boolean\ Default: false

Preserve the line separator at the end of every line, except the last line, which will never contain one.