UNPKG

react-newline-to-break

Version:

Convert newlines '\n' to break '< brreact-newline-to-break >'. Made for React

25 lines (20 loc) 447 B
'use strict'; import React from 'react'; const newline = '\n'; function nl2br(text) { if (typeof text === 'number') { return text; } else if (typeof text !== 'string') { return ''; } let lines = text.split(newline); return lines.map(function(line, i) { return ( <span key={i}> {line} <br/> </span> ); }); } module.exports = nl2br;