Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including breaklines with all npm packages installed. Try it out:

var breaklines = require("breaklines")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

breaklines v1.0.1

A utility to easily replace \n with <br> in single-line strings (such as from JSON data)


A simple utility to add <br> tags into strings containing \n.

Created as my first NPM module, I've needed to create this when building static sites through Wintersmith, as when creating pages via .json files the newlines were not displayed.
Calling this function allowed them to be displayed correctly.


$ npm install breaklines --save


const breaklines = require('breaklines');
const string = 'Testing \n adding \n\n newlines';
//=> 'Testing <br> adding <br><br> newlines'
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free