pex-io
TypeScript icon, indicating that this package has built-in type declarations

3.0.1 • Public • Published

pex-io

npm version stability-stable npm minzipped size dependencies types Conventional Commits styled with prettier linted with eslint license

File I/O in PEX.

Installation

npm install pex-io

Usage

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

Functions

loadText(url, options)Promise.<string>

Load an item and parse the Response as text.

loadJson(url, options)Promise.<JSON>

Load an item and parse the Response as json.

loadArrayBuffer(url, options)Promise.<ArrayBuffer>

Load an item and parse the Response as arrayBuffer.

loadBlob(url, options)Promise.<Blob>

Load an item and parse the Response as blob.

loadImage(urlOrOpts, options)Promise.<HTMLImageElement>

Load an item, parse the Response as blob and create a HTML Image.

load(resources)Promise.<Object.<string, LoadedResource>>

Loads resources from a named map.

Typedefs

ImageOptions : object
Resource : object
LoadedResource : string | object | HTMLImageElement | Blob | ArrayBuffer

loadText(url, options) ⇒ Promise.<string>

Load an item and parse the Response as text.

Kind: global function

Param Type
url RequestInfo
options RequestInit

loadJson(url, options) ⇒ Promise.<JSON>

Load an item and parse the Response as json.

Kind: global function

Param Type
url RequestInfo
options RequestInit

loadArrayBuffer(url, options) ⇒ Promise.<ArrayBuffer>

Load an item and parse the Response as arrayBuffer.

Kind: global function

Param Type
url RequestInfo
options RequestInit

loadBlob(url, options) ⇒ Promise.<Blob>

Load an item and parse the Response as blob.

Kind: global function

Param Type
url RequestInfo
options RequestInit

loadImage(urlOrOpts, options) ⇒ Promise.<HTMLImageElement>

Load an item, parse the Response as blob and create a HTML Image.

Kind: global function

Param Type
urlOrOpts string | ImageOptions
options RequestInit

load(resources) ⇒ Promise.<Object.<string, LoadedResource>>

Loads resources from a named map.

Kind: global function

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

ImageOptions : 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.

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i pex-io

      Weekly Downloads

      9

      Version

      3.0.1

      License

      MIT

      Unpacked Size

      16.5 kB

      Total Files

      6

      Last publish

      Collaborators

      • vorg
      • dmnsgn