aboutsummaryrefslogtreecommitdiff
path: root/src/lib/utils.ts
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-01-24 13:09:50 +0000
committerFuwn <[email protected]>2026-01-24 13:09:50 +0000
commit396acf3bbbe00a192cb0ea0a9ccf91b1d8d2850b (patch)
treeb9df4ca6a70db45cfffbae6fdd7252e20fb8e93c /src/lib/utils.ts
downloadumami-main.tar.xz
umami-main.zip
Initial commitHEADmain
Created from https://vercel.com/new
Diffstat (limited to 'src/lib/utils.ts')
-rw-r--r--src/lib/utils.ts46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/lib/utils.ts b/src/lib/utils.ts
new file mode 100644
index 0000000..2b0d9ff
--- /dev/null
+++ b/src/lib/utils.ts
@@ -0,0 +1,46 @@
+export function hook(
+ _this: { [x: string]: any },
+ method: string | number,
+ callback: (arg0: any) => void,
+) {
+ const orig = _this[method];
+
+ return (...args: any) => {
+ callback.apply(_this, args);
+
+ return orig.apply(_this, args);
+ };
+}
+
+export function sleep(ms: number | undefined) {
+ return new Promise(resolve => setTimeout(resolve, ms));
+}
+
+export function shuffleArray(a) {
+ const arr = a.slice();
+ for (let i = arr.length - 1; i > 0; i--) {
+ const j = Math.floor(Math.random() * (i + 1));
+ const temp = arr[i];
+ arr[i] = arr[j];
+ arr[j] = temp;
+ }
+ return arr;
+}
+
+export function chunkArray(arr: any[], size: number) {
+ const chunks: any[] = [];
+
+ let index = 0;
+ while (index < arr.length) {
+ chunks.push(arr.slice(index, size + index));
+ index += size;
+ }
+
+ return chunks;
+}
+
+export function ensureArray(arr?: any) {
+ if (arr === undefined || arr === null) return [];
+ if (Array.isArray(arr)) return arr;
+ return [arr];
+}