Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

encodr

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

encodr

Encoding/Decoding to/from JSON/CBOR/MsgPack

  • 0.9.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
17K
increased by32.72%
Maintainers
1
Weekly downloads
 
Created
Source

Encodr

Encoding/Decoding to/from JSON/CBOR/MsgPack 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 object serialization formats JavaScript Object Notation (JSON, RFC4627), Concise Binary Object Representation (CBOR, RFC7049) and MsgPack. The actual encoding/decoding is performed by underyling libraries. This package is just a convenient abstraction layer to ensure the correct library is used and consistent data types are used.

Installation

$ npm install encodr

Usage

const Encodr  = require("encodr")

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

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


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

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

data = MsgPack.encode(data)
data = MsgPack.decode(data)

Application Programming Interface

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

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

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

The BLOB type depends on the serialization format and the execution environment:

FormatNode.jsBrowser
jsonStringString
cborBufferUint8Array
msgpackBufferUint8Array

License

Copyright (c) 2017 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.

Keywords

FAQs

Package last updated on 05 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc