chore(utils.ts): add custom helpers and types for better code organization and reusability

This commit is contained in:
Sped0n
2023-10-29 14:54:52 +08:00
parent 8af74ecbaf
commit 6848e413ca

View File

@@ -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<T> {
constructor(private obj: T) {}
private watchers: (() => void)[] = []