-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.ts
31 lines (24 loc) · 896 Bytes
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
export function blink(el: string, className: string, interval: number = 300): void {
document.querySelector(el)?.classList.toggle(className)
setTimeout(() => document.querySelector(el)?.classList.toggle(className), interval)
}
export function isWorker(): boolean {
// return self instanceof DedicatedWorkerGlobalScope
return self.document == undefined && self.window == undefined
}
export function hashObject(obj: object): string {
let str: string = ''
for (const key in obj) {
str += `#${key}:${obj[key]}`
}
return str
}
export function now(): number {
return performance.now() || Date.now()
}
export function ApiIsSupported(APIname: string): boolean {
return window && APIname in window
}
export function windowIsLoaded(): boolean {
return /complete|interactive|loaded/.test(document.readyState) && (window as any).unrailEngineLoaded
}