npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

encodr

v1.3.5

Published

Encoding/Decoding to/from JSON/CBOR/MsgPack

Downloads

67,331

Readme

Encodr

Encoding/Decoding to/from CBOR/MsgPack/JSON for Node.js and Browser.

About

This is a small JavaScript abstraction layer for Node.js and the Browser to encode/decode JavaScript values to/from the (binary) object serialization formats Concise Binary Object Representation (CBOR, RFC7049), MessagePack (MsgPack) and JavaScript Object Notation (JSON, RFC4627). The actual encoding/decoding is performed by underyling libraries. This package is just a convenient abstraction layer to ensure the correct library and consistent data types are used.

Installation

$ npm install encodr

Usage

import Encodr from "encodr"

const CBOR    = new Encodr("cbor")
const MSGPACK = new Encodr("msgpack")
const JSON    = new Encodr("json")

let data = {
    foo: "bar",
    baz: 42,
    baz: [ 1.0, "quux", true ],
    quux: {}
}

data = CBOR.encode(data)
data = CBOR.decode(data)

data = MSGPACK.encode(data)
data = MSGPACK.decode(data)

data = JSON.encode(data)
data = JSON.decode(data)

Application Programming Interface

  • type BLOB = Buffer | Uint8Array The BLOB data type depends on the execution environment: In Node.js it is Buffer, in the Browsers it is Uint8Array.

  • new Encodr(format: string = "cbor"): Encodr Create a new Encodr instance for a particular encoding format. The supported formats are cbor, msgpack, json and jsons. The default is cbor.

  • Encodr::encode(data: any): BLOB Encode a JavaScript value to the serialization format.

  • Encodr::decode(data: BLOB): any Decode a JavaScript value from the serialization format.

Encoding Formats

The following regular serialization formats are supported:

  • cbor: Concise Binary Object Representation (CBOR, RFC7049): This is a very compact, efficient and IETF-standardized serialization format.

  • msgpack: MessagePack (MsgPack): This is a very compact, efficient and battle-tested serialization format.

For convenience and application development reasons, there is also an additional special serialization format:

  • json: UTF-16 string-encoded JavaScript Object Notation (JSON, RFC4627): This is a less compact, less efficient but IETF-standardized and human-readable serialization format.

    This serialization format is JSON encoded into a regular UTF-16 character string (instead of the UTF-8 byte array as it is the case for cbor and msgpack) and hence the API BLOB type here becomes String as an unregular case.

    This serialization format exists for development purposes only, where one wants to easily switch the encoding to a human-readable string representation. For instance, when transferring the data over WebSockets via WebSocket-Framed, the resulting WebSocket frame will be human-readable in the Browser's debugger.

License

Copyright (c) 2017-2023 Dr. Ralf S. Engelschall (http://engelschall.com/)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.