File I/O in PEX.
npm install pex-io
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);
}
- ImageOptions :
object
- Resource :
object
- LoadedResource :
string
|object
|HTMLImageElement
|Blob
|ArrayBuffer
- pex-io
- .loadText(url, options) ⇒
Promise.<string>
- .loadJson(url, options) ⇒
Promise.<JSON>
- .loadArrayBuffer(url, options) ⇒
Promise.<ArrayBuffer>
- .loadBlob(url, options) ⇒
Promise.<Blob>
- .loadImage(urlOrOpts, options) ⇒
Promise.<HTMLImageElement>
- .load(resources) ⇒
Promise.<Object.<string, LoadedResource>>
- .loadText(url, options) ⇒
Load an item and parse the Response as text.
Kind: static method of pex-io
Param | Type |
---|---|
url | RequestInfo |
options | RequestInit |
Load an item and parse the Response as json.
Kind: static method of pex-io
Param | Type |
---|---|
url | RequestInfo |
options | RequestInit |
Load an item and parse the Response as arrayBuffer.
Kind: static method of pex-io
Param | Type |
---|---|
url | RequestInfo |
options | RequestInit |
Load an item and parse the Response as blob.
Kind: static method of pex-io
Param | Type |
---|---|
url | RequestInfo |
options | RequestInit |
Load an item, parse the Response as blob and create a HTML Image.
Kind: static method of pex-io
Param | Type |
---|---|
urlOrOpts | string | ImageOptions |
options | RequestInit |
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" } },
};
const res = await io.load(resources);
res.hello; // => string
res.data; // => Object
res.img; // => HTMLImageElement
res.blob; // => Blob
res.hdrImg; // => ArrayBuffer
Kind: global typedef Properties
Name | Type | Description |
---|---|---|
url | string |
|
...rest | * |
HTMLImageElement#properties |
Kind: global typedef Properties
Name | Type | Description |
---|---|---|
[text] | string |
|
[json] | string |
|
[image] | string |
|
[binary] | string |
|
[options] | RequestInit |
Request#parameters |
Kind: global typedef
MIT. See license file.