From e07a89b56b65f96295f421141f5b02e360d2e7d0 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 29 May 2024 16:54:43 -0300 Subject: upd8, util, cli: factor out help internals; no default build mode Sorry these changes are packed together in one commit! We have no excuse. :+1: --- src/util/sugar.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/util/sugar.js') diff --git a/src/util/sugar.js b/src/util/sugar.js index e060f458..d0b7ffab 100644 --- a/src/util/sugar.js +++ b/src/util/sugar.js @@ -315,6 +315,27 @@ export function cutStart(text, length = 40) { } } +// Wrapper function around wrap(), ha, ha - this requires the Node module +// 'node-wrap'. +export function indentWrap(str, { + wrap, + spaces = 0, + width = 60, + bullet = false, +}) { + const wrapped = + wrap(str, { + width: width - spaces, + indent: ' '.repeat(spaces), + }); + + if (bullet) { + return wrapped.trimStart(); + } else { + return wrapped; + } +} + // Annotates {index, length} results from another iterator with contextual // details, including: // -- cgit 1.3.0-6-gf8a5