/
githubmirror
/
pixijs
Обзор
Документация
Войти
/
githubmirror
/
pixijs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
src/assets/detections/utils/testImageFormat.ts
46 строк
1 KB
Ulysses Zhan
chore: add lint rule to prevent using `document` and `Image` (#11600)
19 авг 2025, 10:36
Не верифицирован
19 авг 2025, 10:36
3995c1c
Код
Авторство
О чём код?
/** * @param imageData * @internal */ export async function testImageFormat(imageData: string): Promise<boolean> { // Some browsers currently do not support createImageBitmap with Blob, so new Image() is preferred when exist. // See https://caniuse.com/createimagebitmap for more information. if ('Image' in globalThis) { return new Promise<boolean>((resolve) => { // eslint-disable-next-line no-restricted-globals const image = new Image(); image.onload = () => { resolve(true); }; image.onerror = () => { resolve(false); }; image.src = imageData; }); } if ('createImageBitmap' in globalThis && 'fetch' in globalThis) { try { const blob = await (await fetch(imageData)).blob(); await createImageBitmap(blob); } catch (_e) { return false; } return true; } return false; }