@jswork/next-nl2br

1.0.2 • Public • Published

next-nl2br

Replace \n with <br /> in JavaScript.

version license size download

installation

npm install -S @jswork/next-nl2br

usage

import '@jswork/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.

Readme

Keywords

Package Sidebar

Install

npm i @jswork/next-nl2br

Homepage

js.work

Weekly Downloads

5

Version

1.0.2

License

MIT

Unpacked Size

8.71 kB

Total Files

6

Last publish

Collaborators

  • afeiship
  • yujiao.luo