Nemo's Parental Misguidance

    @jswork/next-nl2br

    1.0.0 • Public • Published

    next-nl2br

    Replace \n with <br /> in JavaScript.

    version license size download

    installation

    npm install -S @jswork/next-nl2br

    usage

    import '@feizheng/next-nl2br';
    //   example 1: nl2br('Kevin\nvan\nZonneveld')
    //   returns 1: 'Kevin<br />\nvan<br />\nZonneveld'
    //   example 2: nl2br("\nOne\nTwo\n\nThree\n", false)
    //   returns 2: '<br>\nOne<br>\nTwo<br>\n<br>\nThree<br>\n'
    //   example 3: nl2br("\nOne\nTwo\n\nThree\n", true)
    //   returns 3: '<br />\nOne<br />\nTwo<br />\n<br />\nThree<br />\n'
    //   example 4: nl2br(null)
    //   returns 4: ''

    other solution

    while (message.indexOf("\\n") !== -1) {
       message = message.replace("\\n", "<br />");
    }

    resources

    license

    Code released under the MIT license.

    Keywords

    Install

    npm i @jswork/next-nl2br

    DownloadsWeekly Downloads

    2

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    6.33 kB

    Total Files

    5

    Last publish

    Collaborators

    • afeiship