source: frontend/node_modules/prompts/dist/util/wrap.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 717 bytes
Line 
1'use strict';
2/**
3 * @param {string} msg The message to wrap
4 * @param {object} opts
5 * @param {number|string} [opts.margin] Left margin
6 * @param {number} opts.width Maximum characters per line including the margin
7 */
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};
Note: See TracBrowser for help on using the repository browser.