mirror of
https://github.com/Sped0n/bridget.git
synced 2026-04-17 11:39:29 -07:00
fix(resources.ts): handle case when imagesJson element is not found to prevent error and return empty array
25 lines
489 B
TypeScript
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
|
|
}
|
|
)
|
|
}
|