mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-14 07:39:29 -07:00
Adds input validation and safe property access to utility functions to handle edge cases and invalid arguments gracefully
23 lines
626 B
JavaScript
23 lines
626 B
JavaScript
import { blob } from './fetch.mjs';
|
|
|
|
// preload an image
|
|
// the goal is to get it in the browser's cache so it is available more quickly when the browser needs it
|
|
// a list of cached icons is used to avoid hitting the cache multiple times
|
|
const cachedImages = [];
|
|
const preloadImg = (src) => {
|
|
if (!src || typeof src !== 'string') {
|
|
console.warn(`preloadImg expects a URL string, received: '${src}' (${typeof src})`);
|
|
return false;
|
|
}
|
|
|
|
if (cachedImages.includes(src)) return false;
|
|
blob(src);
|
|
cachedImages.push(src);
|
|
return true;
|
|
};
|
|
|
|
export {
|
|
// eslint-disable-next-line import/prefer-default-export
|
|
preloadImg,
|
|
};
|