aboutsummaryrefslogtreecommitdiff
path: root/src/utils/misc.tsx
diff options
context:
space:
mode:
authorVendicated <vendicated@riseup.net>2022-09-01 21:41:00 +0200
committerVendicated <vendicated@riseup.net>2022-09-01 21:41:00 +0200
commit9951e0bcc51cc8eabfbbce81e4671f94fd433513 (patch)
treeaa7ae974bc4c58ad4ab705c87264e112b129a083 /src/utils/misc.tsx
parent78deb0ebad40e4746796994345143120e3566b6b (diff)
downloadVencord-9951e0bcc51cc8eabfbbce81e4671f94fd433513.tar.gz
Vencord-9951e0bcc51cc8eabfbbce81e4671f94fd433513.tar.bz2
Vencord-9951e0bcc51cc8eabfbbce81e4671f94fd433513.zip
Settings: Calculate dependencies
Diffstat (limited to 'src/utils/misc.tsx')
-rw-r--r--src/utils/misc.tsx30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/utils/misc.tsx b/src/utils/misc.tsx
index aca7661..9d4c001 100644
--- a/src/utils/misc.tsx
+++ b/src/utils/misc.tsx
@@ -69,4 +69,32 @@ export function mergeDefaults<T>(obj: T, defaults: T): T {
}
}
return obj;
-} \ No newline at end of file
+}
+
+
+/**
+ * Join an array of strings in a human readable way (1, 2 and 3)
+ * @param elements Elements
+ */
+export function humanFriendlyJoin(elements: string[]): string;
+/**
+ * Join an array of strings in a human readable way (1, 2 and 3)
+ * @param elements Elements
+ * @param mapper Function that converts elements to a string
+ */
+export function humanFriendlyJoin<T>(elements: T[], mapper: (e: T) => string): string;
+export function humanFriendlyJoin(elements: any[], mapper: (e: any) => string = s => s): string {
+ const { length } = elements;
+ if (length === 0) return "";
+ if (length === 1) return mapper(elements[0]);
+
+ let s = "";
+
+ for (let i = 0; i < length; i++) {
+ s += mapper(elements[i]);
+ if (length - i > 2) s += ", ";
+ else if (length - i > 1) s += " and ";
+ }
+
+ return s;
+}