Refactor scripts
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
export function bytesHumanReadable(fileSize: number): string {
|
||||
export default function bytesHumanReadable(fileSize: number): string {
|
||||
let unit = "bytes"
|
||||
|
||||
if(fileSize >= 1024) {
|
||||
|
@ -1,3 +1,3 @@
|
||||
export function delay<T>(millis: number, value?: T): Promise<T> {
|
||||
export default function delay<T>(millis: number, value?: T): Promise<T> {
|
||||
return new Promise(resolve => setTimeout(() => resolve(value), millis))
|
||||
}
|
||||
|
1
scripts/Utils/emptyPixel.ts
Normal file
1
scripts/Utils/emptyPixel.ts
Normal file
@ -0,0 +1 @@
|
||||
export default "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="
|
@ -1,15 +1,7 @@
|
||||
export function* findAll(className: string): IterableIterator<HTMLElement> {
|
||||
export default function* findAll(className: string): IterableIterator<HTMLElement> {
|
||||
const elements = document.getElementsByClassName(className)
|
||||
|
||||
for(let i = 0; i < elements.length; ++i) {
|
||||
yield elements[i] as HTMLElement
|
||||
}
|
||||
}
|
||||
|
||||
export function* findAllInside(className: string, root: HTMLElement): IterableIterator<HTMLElement> {
|
||||
const elements = root.getElementsByClassName(className)
|
||||
|
||||
for(let i = 0; i < elements.length; ++i) {
|
||||
yield elements[i] as HTMLElement
|
||||
for(const element of elements) {
|
||||
yield element as HTMLElement
|
||||
}
|
||||
}
|
||||
|
7
scripts/Utils/findAllInside.ts
Normal file
7
scripts/Utils/findAllInside.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export default function* findAllInside(className: string, root: HTMLElement): IterableIterator<HTMLElement> {
|
||||
const elements = root.getElementsByClassName(className)
|
||||
|
||||
for(const element of elements) {
|
||||
yield element as HTMLElement
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
export function hexToHSL(hex: string) {
|
||||
export default function hexToHSL(hex: string) {
|
||||
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
|
||||
|
||||
if(!result) {
|
||||
@ -20,7 +20,7 @@ export function hexToHSL(hex: string) {
|
||||
let s = 0
|
||||
const l = (max + min) / 2
|
||||
|
||||
if(max == min) {
|
||||
if(max === min) {
|
||||
h = s = 0
|
||||
} else {
|
||||
const d = max - min
|
||||
|
@ -1,9 +0,0 @@
|
||||
export * from "./supportsWebP"
|
||||
export * from "./delay"
|
||||
export * from "./findAll"
|
||||
export * from "./hexToHSL"
|
||||
export * from "./plural"
|
||||
export * from "./requestIdleCallback"
|
||||
export * from "./swapElements"
|
||||
export * from "./uploadWithProgress"
|
||||
export * from "./bytesHumanReadable"
|
@ -2,7 +2,7 @@ const specialized = {
|
||||
"new activity": "new activities"
|
||||
}
|
||||
|
||||
export function plural(count: number, singular: string): string {
|
||||
export default function plural(count: number, singular: string): string {
|
||||
if(count === 1 || count === -1) {
|
||||
return count + " " + singular
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
export function requestIdleCallback(func: Function) {
|
||||
export default function requestIdleCallback(func: Function) {
|
||||
if("requestIdleCallback" in window) {
|
||||
(window["requestIdleCallback"] as Function)(func)
|
||||
} else {
|
||||
|
@ -1,4 +1,4 @@
|
||||
export async function supportsWebP(): Promise<boolean> {
|
||||
export default async function supportsWebP(): Promise<boolean> {
|
||||
if(!window.createImageBitmap) {
|
||||
return false
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// swapElements assumes that both elements have valid parent nodes.
|
||||
export function swapElements(a: Node, b: Node) {
|
||||
export default function swapElements(a: Node, b: Node) {
|
||||
const bParent = b.parentNode as Node
|
||||
const bNext = b.nextSibling
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
export function uploadWithProgress(url, options: RequestInit, onProgress: ((ev: ProgressEvent) => any) | null): Promise<string> {
|
||||
export default function uploadWithProgress(url, options: RequestInit, onProgress: ((ev: ProgressEvent) => any) | null): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest()
|
||||
|
||||
|
Reference in New Issue
Block a user