jsonsca

0.1.1 • Public • Published

JSON SCA

A serialization tool supporting HTML5 Structured Clone Algorithm types.

You can read more about the SCA types from MDN: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm

The algorithm is part of HTML5 specifications that define things like what types may be stored in IndexedDB and how data is transferred between Web Workers and iFrames via the postMessage() API. This covers a much wider range of types than JSON, which postMessage() originally used, but is not actually a serialization format. SCA only defines how the data is copied across boundaries, not any way to actually represent this.

Supported Types

This is a work in progress, but was fully functioning as part of a previous project. As a stand-alone library support for some types is still forthcoming. Currently known to work and be tested includes:

  • string
  • number
  • boolean
  • null
  • undefined
  • objects (including multiple references and cyclic references)
  • arrays (including some reference features)

Upcoming:

  • RegExp objects
  • ImageData
  • File and FileList and Blob

API

jsonsca.stringify(obj)

Serialization a compatible object into a string. Returns a promise, because some types can only be serialized by processing them through asynchronous means.

jsonsca.parse(string)

Deserialize data previously serialized. Preserves multiple references to shared objects and cyclic references.

Readme

Keywords

Package Sidebar

Install

npm i jsonsca

Weekly Downloads

0

Version

0.1.1

License

MIT

Last publish

Collaborators

  • ironfroggy