27 lines
905 B
TypeScript
Raw Normal View History

2017-07-01 11:35:21 +00:00
export function* findAll(className: string): IterableIterator<HTMLElement> {
2017-06-26 10:32:07 +00:00
let elements = document.getElementsByClassName(className)
2017-06-21 16:44:20 +00:00
2017-06-20 10:41:26 +00:00
for(let i = 0; i < elements.length; ++i) {
yield elements[i] as HTMLElement
}
2017-06-26 01:57:29 +00:00
}
export function delay<T>(millis: number, value?: T): Promise<T> {
return new Promise(resolve => setTimeout(() => resolve(value), millis))
2017-07-01 11:35:21 +00:00
}
export function plural(count: number, singular: string): string {
2017-07-08 13:40:13 +00:00
return (count === 1 || count === -1) ? (count + " " + singular) : (count + " " + singular + "s")
}
export function canUseWebP(): boolean {
let canvas = document.createElement("canvas")
if(!!(canvas.getContext && canvas.getContext("2d"))) {
// WebP representation possible
return canvas.toDataURL("image/webp").indexOf("data:image/webp") === 0
} else {
// In very old browsers (IE 8) canvas is not supported
return false
}
2017-06-20 10:41:26 +00:00
}