CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
wrap.js28 linesDownload Raw Back to util
1'use strict';2 3/**4 * @param {string} msg The message to wrap5 * @param {object} opts6 * @param {number|string} [opts.margin] Left margin7 * @param {number} opts.width Maximum characters per line including the margin8 */9module.exports = (msg, opts = {}) => {10  const tab = Number.isSafeInteger(parseInt(opts.margin))11    ? new Array(parseInt(opts.margin)).fill(' ').join('')12    : (opts.margin || '');13 14  const width = opts.width;15 16  return (msg || '').split(/\r?\n/g)17    .map(line => line18      .split(/\s+/g)19      .reduce((arr, w) => {20        if (w.length + tab.length >= width || arr[arr.length - 1].length + w.length + 1 < width)21          arr[arr.length - 1] += ` ${w}`;22        else arr.push(`${tab}${w}`);23        return arr;24      }, [ tab ])25      .join('\n'))26    .join('\n');27};28 
basant307/AI_Governance_Project · CoolFace