This commit is contained in:
Tutur33
2023-11-24 22:35:41 +01:00
parent 3c0b507a93
commit 7644b2a0f7
45165 changed files with 4803356 additions and 3 deletions
+30
View File
@@ -0,0 +1,30 @@
declare namespace splitLines {
interface Options {
/**
Preserve the line separator at the end of every line, except the last line, which will never contain one.
@default false
*/
preserveNewlines?: boolean;
}
}
/**
Split lines into an array of lines.
@param string - String to split.
@example
```
import splitLines = require('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']
```
*/
declare function splitLines(string: string, options?: splitLines.Options): string[];
export = splitLines;
+24
View File
@@ -0,0 +1,24 @@
'use strict';
module.exports = (string, options) => {
options = Object.assign({
preserveNewLines: false
}, options);
if (typeof string !== 'string') {
throw new TypeError(`Expected input to be of type \`string\`, got \`${typeof string}\``);
}
if (!options.preserveNewlines) {
return string.split(/\r?\n/);
}
const parts = string.split(/(\r?\n)/);
const lines = [];
for (let i = 0; i < parts.length; i += 2) {
lines.push(parts[i] + (parts[i + 1] || ''));
}
return lines;
};
+9
View File
@@ -0,0 +1,9 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+43
View File
@@ -0,0 +1,43 @@
{
"name": "split-lines",
"version": "2.1.0",
"description": "Split lines into an array of lines",
"license": "MIT",
"repository": "sindresorhus/split-lines",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=6"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"split",
"lines",
"line",
"string",
"str",
"newline",
"newlines",
"linebreak",
"line-break",
"lf",
"crlf",
"eol",
"linefeed"
],
"devDependencies": {
"ava": "^2.4.0",
"tsd": "^0.14.0",
"xo": "^0.38.2"
}
}
+42
View File
@@ -0,0 +1,42 @@
# split-lines
> Split lines into an array of lines
## Install
```
$ npm install split-lines
```
## Usage
```js
const splitLines = require('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(input, options?)
#### input
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.