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

2.3.0 • Public • Published

Nibs for JavaScript

This is a generic nibs serializtion implementaion for any modern JavaScript runtime.

Unit Tests

npm version

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.

Readme

Keywords

none

Package Sidebar

Install

npm i nibs

Weekly Downloads

25,510

Version

2.3.0

License

none

Unpacked Size

61.1 kB

Total Files

16

Last publish

Collaborators

  • creationix