* @param [options.width] {number} - the max column width in characters (defaults to 30).
* @param [options.break] {boolean} - if true, words exceeding the specified `width` will be forcefully broken
* @param [options.noTrim] {boolean} - By default, each line output is trimmed. If `noTrim` is set, no line-trimming occurs - all whitespace from the input text is left in.
* @return {string}
*/
static wrap (text, options) {
const block = new this(text, options)
return block.wrap()
}
/**
* Wraps the input text, returning an array of strings (lines).
* @param {string} - input text
* @param {object} - Accepts same options as constructor.
*/
static lines (text, options) {
const block = new this(text, options)
return block.lines()
}
/**
* Returns true if the input text would be wrapped if passed into `.wrap()`.
* @param {string} - input text
* @return {boolean}
*/
static isWrappable (text) {
if (t.isDefined(text)) {
text = String(text)
var matches = text.match(re.chunk)
return matches ? matches.length > 1 : false
}
}
/**
* Splits the input text into an array of words and whitespace.
* @param {string} - input text
* @returns {string[]}
*/
static getChunks (text) {
return text.match(re.chunk) || []
}
}
function trimLine (line) {
return this.options.noTrim ? line : line.trim()
}
function replaceAnsi (string) {
return string.replace(re.ansiEscapeSequence, '')
}
/* break a word into several pieces */
function breakWord (word) {
if (replaceAnsi(word).length > this.options.width) {
const letters = word.split('')
let piece
const pieces = []
while ((piece = letters.splice(0, this.options.width)).length) {