]> git.localhorst.tv Git - alttp.git/blob - resources/js/helpers/nl2br.js
try to respond more appropriately
[alttp.git] / resources / js / helpers / nl2br.js
1 import React from 'react';
2
3 const nl2br = str => {
4         if (typeof str !== 'string') {
5                 return str;
6         }
7         const nl = /(\r\n|\r|\n)/g;
8         return str.split(nl).map((line, index) => {
9                 if (line.match(nl)) {
10                         return <br key={index} />;
11                 }
12                 return line;
13         });
14 };
15
16 export default nl2br;