2 * word-wrap <https://github.com/jonschlinkert/word-wrap>
4 * Copyright (c) 2014-2017, Jon Schlinkert.
5 * Released under the MIT License.
8 module.exports = function(str, options) {
9 options = options || {};
14 var width = options.width || 50;
15 var indent = (typeof options.indent === 'string')
19 var newline = options.newline || '\n' + indent;
20 var escape = typeof options.escape === 'function'
24 var regexString = '.{1,' + width + '}';
25 if (options.cut !== true) {
26 regexString += '([\\s\u200B]+|$)|[^\\s\u200B]+?([\\s\u200B]+|$)';
29 var re = new RegExp(regexString, 'g');
30 var lines = str.match(re) || [];
31 var result = indent + lines.map(function(line) {
32 if (line.slice(-1) === '\n') {
33 line = line.slice(0, line.length - 1);
38 if (options.trim === true) {
39 result = result.replace(/[ \t]*$/gm, '');
44 function identity(str) {