3.0.1 • Published 9 months ago

pex-io v3.0.1

Weekly downloads
26
License
MIT
Repository
github
Last release
9 months ago

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

Typedefs

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

Load an item and parse the Response as text.

Kind: global function

ParamType
urlRequestInfo
optionsRequestInit

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

Load an item and parse the Response as json.

Kind: global function

ParamType
urlRequestInfo
optionsRequestInit

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

Load an item and parse the Response as arrayBuffer.

Kind: global function

ParamType
urlRequestInfo
optionsRequestInit

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

Load an item and parse the Response as blob.

Kind: global function

ParamType
urlRequestInfo
optionsRequestInit

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

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

Kind: global function

ParamType
urlOrOptsstring | ImageOptions
optionsRequestInit

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

Loads resources from a named map.

Kind: global function

ParamType
resourcesObject.<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

NameTypeDescription
urlstring
...rest*HTMLImageElement#properties

Resource : object

Kind: global typedef Properties

NameTypeDescription
textstring
jsonstring
imagestring
binarystring
optionsRequestInitRequest#parameters

LoadedResource : string | object | HTMLImageElement | Blob | ArrayBuffer

Kind: global typedef

License

MIT. See license file.

3.0.1

9 months ago

3.0.0

12 months ago

3.0.0-alpha.0

2 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.5.3

7 years ago

1.5.2

7 years ago

1.5.1

7 years ago

1.5.0

7 years ago

1.4.1

7 years ago

1.4.0

7 years ago

1.3.2

7 years ago

1.3.1

8 years ago

1.3.0

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago

1.0.0-beta.1

8 years ago