pex-io
v3.1.0
Published
File I/O in PEX.
Readme
pex-io
File I/O in PEX.
Installation
npm install pex-ioUsage
import * as io from "pex-io";
try {
const text = await io.loadText("assets/hello.txt");
// => DOMString
const json = await io.loadJson("assets/color.json");
// => Object
const image = await io.loadImage("assets/pex.png");
// => HTMLImageElement
const blob = await io.loadBlob("assets/data");
// => Blob
const arrayBuffer = await io.loadArrayBuffer("assets/data.bin");
// => ArrayBuffer
} catch (error) {
console.log(error);
}API
Modules
Typedefs
pex-io
- pex-io
- .loadText(url, [fetchOptions]) ⇒ Promise.<string>
- .loadJson(url, [fetchOptions]) ⇒ Promise.<JSON>
- .loadArrayBuffer(url, [fetchOptions]) ⇒ Promise.<ArrayBuffer>
- .loadBytes(url, [fetchOptions]) ⇒ Promise.<Uint8Array>
- .loadBlob(url, [fetchOptions]) ⇒ Promise.<Blob>
- .loadImage(urlOrImageProperties, [fetchOptions]) ⇒ Promise.<HTMLImageElement>
- .load(resources) ⇒ Promise.<Object.<string, LoadedResource>>
pex-io.loadText(url, [fetchOptions]) ⇒ Promise.<string>
Load an item and parse the Response as text.
Kind: static method of pex-io
| Param | Type | | -------------- | ------------------------ | | url | RequestInfo | | [fetchOptions] | RequestInit |
pex-io.loadJson(url, [fetchOptions]) ⇒ Promise.<JSON>
Load an item and parse the Response as json.
Kind: static method of pex-io
| Param | Type | | -------------- | ------------------------ | | url | RequestInfo | | [fetchOptions] | RequestInit |
pex-io.loadArrayBuffer(url, [fetchOptions]) ⇒ Promise.<ArrayBuffer>
Load an item and parse the Response as arrayBuffer.
Kind: static method of pex-io
| Param | Type | | -------------- | ------------------------ | | url | RequestInfo | | [fetchOptions] | RequestInit |
pex-io.loadBytes(url, [fetchOptions]) ⇒ Promise.<Uint8Array>
Load an item and parse the Response as bytes.
Kind: static method of pex-io
| Param | Type | | -------------- | ------------------------ | | url | RequestInfo | | [fetchOptions] | RequestInit |
pex-io.loadBlob(url, [fetchOptions]) ⇒ Promise.<Blob>
Load an item and parse the Response as blob.
Kind: static method of pex-io
| Param | Type | | -------------- | ------------------------ | | url | RequestInfo | | [fetchOptions] | RequestInit |
pex-io.loadImage(urlOrImageProperties, [fetchOptions]) ⇒ Promise.<HTMLImageElement>
Create and load a HTML Image. If fetchOptions are specified, load and parse the Response as blob to set the "src" property.
Kind: static method of pex-io
| Param | Type | | -------------------- | ----------------------------------------------------------------- | | urlOrImageProperties | string | ImageOptions | | [fetchOptions] | RequestInit |
pex-io.load(resources) ⇒ Promise.<Object.<string, LoadedResource>>
Loads resources from a named map.
Kind: static method of pex-io
| Param | Type | | --------- | -------------------------------------------- | | resources | Object.<string, Resource> |
Example
const resources = {
hello: { text: "assets/hello.txt" },
data: { json: "assets/data.json" },
img: { image: "assets/tex.jpg" },
blob: { blob: "assets/blob" },
hdrImg: { arrayBuffer: "assets/tex.hdr", options: { mode: "no-cors" } },
bytes: { bytes: "assets/tex.hdr" },
};
const res = await io.load(resources);
res.hello; // => string
res.data; // => Object
res.img; // => HTMLImageElement
res.blob; // => Blob
res.hdrImg; // => ArrayBuffer
res.bytes; // => Uint8ArrayImageOptions : object
Kind: global typedef Properties
| Name | Type | Description | | ------- | ------------------- | ----------------------------------------------------------------------------------------------------------- | | url | string | | | ...rest | * | HTMLImageElement#properties |
Resource : object
Kind: global typedef Properties
| Name | Type | Description | | --------- | ------------------------ | ------------------------------------------------------------------------------------------------- | | [text] | string | | | [json] | string | | | [image] | string | | | [binary] | string | | | [options] | RequestInit | Request#parameters |
LoadedResource : string | object | HTMLImageElement | Blob | ArrayBuffer
Kind: global typedef
License
MIT. See license file.
