CoolFace
Datasetpublic

basant307/AI_Governance_Project

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