@fogrexon/glyph-arena-assets
URL asset loading with in-memory cache. See also package README.
Exports
Generated from the package's source when the docs are built — do not edit this table by hand.
| Name | Kind |
|---|---|
Assets | type |
CreateAssetsOptions | type |
LoadOptions | type |
createAssets | function |
createAssets(options?)
const assets = createAssets({
fetch?, // optional
createImageBitmap?, // optional
});
await assets.loadText(url, { signal? });
await assets.loadJson(url, { signal? });
await assets.loadBytes(url, { signal? });
await assets.loadImage(url, { signal? });
assets.evict(url);
assets.dispose();
Options
fetch?— fetch implementation. Defaults toglobalThis.fetch.createImageBitmap?— image decoder. Defaults toglobalThis.createImageBitmapwhen available.
Methods
loadText(url, options?)— fetch and return response text.loadJson(url, options?)— fetch and return parsed JSON asunknown.loadBytes(url, options?)— fetch and returnArrayBuffer.loadImage(url, options?)— fetch blob and decode toImageBitmap.evict(url)— drop cached results for all kinds onurl. Unknown URLs are no-ops.dispose()— clear cache. After dispose,load*reject with"Assets disposed";evictis a no-op.
LoadOptions
| Field | Description |
|---|---|
signal? | optional AbortSignal passed to fetch |
Caching
- Successful loads are cached per URL and kind until
evictordispose. - In-flight loads for the same URL and kind are deduped.
- Failures are not cached; the next load retries.
- Cached loads return the same reference for the same URL and kind.
HTTP errors
Non-OK responses reject with Error("HTTP <status> for <url>").
loadImage requirements
Rejects with "createImageBitmap is not available" when no decoder is provided and globalThis.createImageBitmap is missing.
Evict during in-flight load
Does not abort the in-flight request. On success, the result is not re-cached; the next load fetches again.