« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/sugar.js14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/util/sugar.js b/src/util/sugar.js
index 344ddfd4..58a2c3e9 100644
--- a/src/util/sugar.js
+++ b/src/util/sugar.js
@@ -282,7 +282,19 @@ export function typeAppearance(value) {
 // if it cuts any text off.
 export function cut(text, length = 40) {
   if (text.length >= length) {
-    return text.slice(0, Math.max(1, length - 3)) + '...';
+    const index = Math.max(1, length - 3);
+    return text.slice(0, index) + '...';
+  } else {
+    return text;
+  }
+}
+
+// Limits a string to the desired length, filling in an ellipsis at the start
+// if it cuts any text off.
+export function cutStart(text, length = 40) {
+  if (text.length >= length) {
+    const index = Math.min(text.length - 1, text.length - length + 3);
+    return '...' + text.slice(index);
   } else {
     return text;
   }