nibs
v2.3.0
Published
This is a generic nibs serializtion implementaion for any modern JavaScript runtime.
Downloads
258,974
Readme
Nibs for JavaScript
This is a generic nibs serializtion implementaion for any modern JavaScript runtime.
Install
npm i nibs
Usage
Nibs is packaged as an ES module. You can import the exports individually:
import {
encode, // JS Value -> Nibs Uint8Array
decode, // Nibs Uint8Array -> Lazy JS Value
} from 'nibs'
Or you can grab the entire namespace:
import * as Nibs from 'nibs'
Encoding turns any supported JS value into a memory buffer.
const encoded = Nibs.encode({ hello: "world" })
Decoding turns any memory buffer into a nibs object.
const decoded = decode(encoded)
// All nibs maps decode to JavaScript objects.
// It doesn't matter of you used a map or an object when encoding.
// This does mean non-string keys get stringified.
const hello = decoded.hello
Lazy Reading
The JS implementation of nibs takes advantage getter functions to make objects and arrays appear like normal, but only decode when properties are actually read. It will cache the result as you traverse an object and replace the getter with the decoded value.