From 6848e413caef4f43284bd10cd946775416952379 Mon Sep 17 00:00:00 2001 From: Sped0n Date: Sun, 29 Oct 2023 14:54:52 +0800 Subject: [PATCH] chore(utils.ts): add custom helpers and types for better code organization and reusability --- assets/ts/utils.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/assets/ts/utils.ts b/assets/ts/utils.ts index e2e21e7..9717d03 100644 --- a/assets/ts/utils.ts +++ b/assets/ts/utils.ts @@ -1,3 +1,7 @@ +/** + * custom helpers + */ + export function increment(num: number, length: number): number { return (num + 1) % length } @@ -14,6 +18,14 @@ export function isMobile(): boolean { return window.matchMedia('(hover: none)').matches } +export function getRandom(min: number, max: number) { + return Math.floor(Math.random() * (max - min + 1)) + min +} + +/** + * custom types + */ + export class Watchable { constructor(private obj: T) {} private watchers: (() => void)[] = []