Files
bridget/assets/ts/resources.ts
Sped0n ead0a84ac7 refactor(main.ts): improve code readability by adding conditional check for ijs length before initializing stage or collection
fix(resources.ts): handle case when imagesJson element is not found to prevent error and return empty array
2023-10-30 15:54:36 +08:00

25 lines
489 B
TypeScript

// data structure for images info
export interface ImageJSON {
index: number
url: string
imgH: number
imgW: number
pColor: string
sColor: string
}
export function initResources(): ImageJSON[] {
const imagesJson = document.getElementById('imagesSource')
if (!imagesJson) {
return []
}
return JSON.parse(imagesJson.textContent as string).sort(
(a: ImageJSON, b: ImageJSON) => {
if (a.index < b.index) {
return -1
}
return 1
}
)
}