Ninja Pumpkin Mutants

    divide-lines
    TypeScript icon, indicating that this package has built-in type declarations

    0.1.0 • Public • Published

    divide-lines

    Divide the lines of a string in a lines object array

    Coverage Status version node-version downloads

    MIT License PRs Welcome Code of Conduct XO code style

    Watch on GitHub Star on GitHub

    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

    Install

    npm i divide-lines

    DownloadsWeekly Downloads

    0

    Version

    0.1.0

    License

    MIT

    Unpacked Size

    8.12 kB

    Total Files

    5

    Last publish

    Collaborators

    • forresst17