« get me outta code hell

upd8, util, cli: factor out help internals; no default build mode - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util/sugar.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-05-29 16:54:43 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-29 19:40:03 -0300
commite07a89b56b65f96295f421141f5b02e360d2e7d0 (patch)
treeda751f7eb08282a488eb47cae7fd34cf65fca6b8 /src/util/sugar.js
parent323cb695015b21ba55513f9e615ecf2a95d7ca80 (diff)
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:
Diffstat (limited to 'src/util/sugar.js')
-rw-r--r--src/util/sugar.js21
1 files changed, 21 insertions, 0 deletions
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:
 //