mirror of
https://github.com/Sped0n/bridget.git
synced 2026-04-21 13:39:30 -07:00
chore(utils.ts): add custom helpers and types for better code organization and reusability
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
/**
|
||||||
|
* custom helpers
|
||||||
|
*/
|
||||||
|
|
||||||
export function increment(num: number, length: number): number {
|
export function increment(num: number, length: number): number {
|
||||||
return (num + 1) % length
|
return (num + 1) % length
|
||||||
}
|
}
|
||||||
@@ -14,6 +18,14 @@ export function isMobile(): boolean {
|
|||||||
return window.matchMedia('(hover: none)').matches
|
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> {
|
export class Watchable<T> {
|
||||||
constructor(private obj: T) {}
|
constructor(private obj: T) {}
|
||||||
private watchers: (() => void)[] = []
|
private watchers: (() => void)[] = []
|
||||||
|
|||||||
Reference in New Issue
Block a user