summaryrefslogtreecommitdiff
path: root/lib/string.fnl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/string.fnl')
-rw-r--r--lib/string.fnl13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/string.fnl b/lib/string.fnl
index 466dac9..d82c658 100644
--- a/lib/string.fnl
+++ b/lib/string.fnl
@@ -8,4 +8,15 @@
(fn ends-with [string end]
(= (string.sub string (- (# end))) end))
-{: split : ends-with}
+(fn trim [str]
+ (str:match "^%s*(.-)%s*$"))
+
+(fn truncate [str len ellipsis]
+ (if (and (= (type str) "string")
+ (< 0 (# str)))
+ (if (< (# str) len)
+ str
+ (.. (trim (luna.utf.sub str 1 len)) (or ellipsis "...")))
+ ""))
+
+{: split : ends-with : truncate}