lib/log/format.js
/**
 * Format a string to fit a given length with a custom prefix.
 *
 * The format is as follow:
 *
 * @param {string} str The string to format
 * @param {string} prefix The prefix to add to the formated string
 * @param {Function} formater A chalk function to format lines
 * @param {number} lineLength The max length of the string
 * @returns {Array} All the string chuncks properly prefixed
 */
Format a string to fit a given length with a custom prefix.
The format is as follow.


Format a string to fit a given length with a custom prefix . The format is as follow .
function format (str, prefix, formater, lineLength) {
  const fn = formater || (s => { return s })
  const len = lineLength - strip(prefix).length
  const blank = ` `.repeat(strip(prefix).length)
  return str
    .split(`\n`)
    .reduce((acc, line) => {
      return [...acc, ...limitStringLength(line, len)]
    }, [])
    .map((line, index) => `${index === 0 ? prefix : blank}${fn(line)}`)
}
function format ( str , prefix , formater , lineLength ) { const fn = formater || ( s => { return s } ) const len = lineLength - strip ( prefix ) . length const blank = ` ` . repeat ( strip ( prefix ) . length ) return str . split ( ` \n ` ) . reduce ( ( acc , line ) => { return [ ... acc , ... limitStringLength ( line , len ) ] } , [ ] ) . map ( ( line , index ) => ` ${ index === 0 ? prefix : blank } ${ fn ( line ) } ` ) }
Format a string to fit a given length with a custom prefix.
Format a string to fit a given length with a custom prefix .