https://github.com/forresst/divide-lines
Divide the lines of a string in a lines object
https://github.com/forresst/divide-lines
divide line lines object split string
Last synced: 4 months ago
JSON representation
Divide the lines of a string in a lines object
- Host: GitHub
- URL: https://github.com/forresst/divide-lines
- Owner: forresst
- License: mit
- Created: 2020-03-11T14:52:22.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2025-02-13T15:02:26.000Z (over 1 year ago)
- Last Synced: 2025-09-28T23:47:16.968Z (9 months ago)
- Topics: divide, line, lines, object, split, string
- Language: TypeScript
- Size: 24.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: license
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# divide-lines
Divide the lines of a string in a lines object array
[](https://coveralls.io/github/forresst/divide-lines)
[](https://www.npmjs.com/package/divide-lines)
[](https://nodejs.org)
[](http://npm-stat.com/charts.html?package=divide-lines)
[](https://github.com/forresst/divide-lines/blob/master/LICENSE)
[](http://makeapullrequest.com)
[](https://github.com/forresst/divide-lines/blob/master/CODE_OF_CONDUCT.md)
[](https://github.com/xojs/xo)
[](https://github.com/forresst/divide-lines/watchers)
[](https://github.com/forresst/divide-lines/stargazers)
## Table of Contents
- [Installation](#installation)
- [Usage](#usage)
* [Node.js](#nodejs)
- [API](#api)
* [divideLines(input)](#dividelinesinput)
+ [input](#input)
+ [return](#return)
+ [Example](#example)
- [LICENSE](#license)
## Installation
This module is distributed via [npm](https://www.npmjs.com/) which is bundled with [node](https://nodejs.org) and should be installed as one of your project's `devDependencies`:
```console
npm install --save-dev divide-lines
```
## Usage
### Node.js
```js
import divideLines from 'divide-lines';
console.log(divideLines('\n\rHello \r\n\n The\n\nNice World '));
/* =>
{
originalString: '\n\rHello \r\n\n The\n\nNice World ',
lines: [
{
lineBreak: '\n',
originalLine: '\n'
},
{
whitespaceStart: '\r',
whitespaceEnd: ' ',
content: 'Hello',
lineBreak: '\r\n',
originalLine: '\rHello \r\n'
},
{
lineBreak: '\n',
originalLine: '\n'
},
{
whitespaceStart: ' ',
content: 'The',
lineBreak: '\n',
originalLine: ' The\n'
},
{
lineBreak: '\n',
originalLine: '\n'
},
{
whitespaceEnd: ' ',
content: 'Nice World',
originalLine: 'Nice World '
}
]
}
*/
```
## API
### divideLines(input)
Divide the lines of a string in a lines object Returns a `object`.
#### input
Type: `string`
The string to divide.
#### return
Type: `object`
The lines object.
#### Example
`index.js`:
> ```js
>
> import divideLines from 'divide-lines';
>
> console.log(divideLines(''));
> //=> { originalString: '', lines: [ { originalLine: '' } ] }
>
> console.log(divideLines('a'));
> /* =>
> {
> originalString: 'a',
> lines: [
> {
> content: 'a',
> originalLine: 'a'
> }
> ]
> }
> */
>
> console.log(divideLines('\n\rHello \r\n\n The\n\nNice World '));
> /* =>
> {
> originalString: '\n\rHello \r\n\n The\n\nNice World ',
> lines: [
> {
> lineBreak: '\n',
> originalLine: '\n'
> },
> {
> whitespaceStart: '\r',
> whitespaceEnd: ' ',
> content: 'Hello',
> lineBreak: '\r\n',
> originalLine: '\rHello \r\n'
> },
> {
> lineBreak: '\n',
> originalLine: '\n'
> },
> {
> whitespaceStart: ' ',
> content: 'The',
> lineBreak: '\n',
> originalLine: ' The\n'
> },
> {
> lineBreak: '\n',
> originalLine: '\n'
> },
> {
> whitespaceEnd: ' ',
> content: 'Nice World',
> originalLine: 'Nice World '
> }
> ]
> }
> */
> ```
## LICENSE
MIT