divide-lines
v0.1.0
Published
Divide the lines of a string in a lines object
Downloads
4
Maintainers
Readme
divide-lines
Divide the lines of a string in a lines object array
Table of Contents
Installation
This module is distributed via npm which is bundled with node and should be installed as one of your project's devDependencies
:
npm install --save-dev divide-lines
Usage
Node.js
const divideLines = require('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 array Returns a array
.
input
Type: string
The string to divide.
return
Type: array
The lines object array.
Example
index.js
:
const divideLines = require('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