mrmBot-Matrix/utils/wrap.js

12 lines
356 B
JavaScript
Raw Normal View History

export default (str) => {
2019-09-13 20:02:41 +00:00
var regexString = ".{1,15}([\\s\u200B]+|$)|[^\\s\u200B]+?([\\s\u200B]+|$)";
var re = new RegExp(regexString, "g");
var lines = str.match(re) || [];
var result = lines.map((line) => {
if (line.slice(-1) === "\n") {
line = line.slice(0, line.length - 1);
}
return line;
}).join("\n");
return result;
};