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

@kmu/bjson_node

v1.0.0

Published

BJSON: binary JSON for node.js (encoder/decoder)

Downloads

6

Readme

bjson_node: binary JSON for node.js (encoder/decoder)

  • The reference BJSON implementation for JavaScript,
  • For C/C++ implementation please visit https://github.com/kemu-studio/bjson_c,
  • For protocol details please visit http://bjson.org/.

Usage

Encoding example

  // Import KBJSON module.
  const kbjson = require('kbjson')
  
  // Encode example JSON object into binary buffer.
  const buf = kbjson.encode({
    x: 1,
    y: 3.14,
    z: 'hello from BJSON'
  })
  
  // Show encoded data.
  // This line should prints out JSON document encoded as binary data:
  // <Buffer 24 25 10 01 78 1b 10 01 79 0f 1f 85 eb 51 b8 1e 09 40 10 01 7a 10 10 68 65 6c 6c 6f 20 66 72 6f 6d 20 42 4a 53 4f 4e>
  console.log(buf)

Decoding example

  // Import KBJSON module.
  const kbjson = require('kbjson')

  // Decode binary buffer generated in encoder example above.
  const encodedData = Buffer.from([
    0x24, 0x25, 0x10, 0x01, 0x78, 0x1b, 0x10, 0x01,
    0x79, 0x0f, 0x1f, 0x85, 0xeb, 0x51, 0xb8, 0x1e,
    0x09, 0x40, 0x10, 0x01, 0x7a, 0x10, 0x10, 0x68,
    0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x66, 0x72, 0x6f,
    0x6d, 0x20, 0x42, 0x4a, 0x53, 0x4f, 0x4e
  ])

  const plainData = kbjson.decode(encodedData)

  // Show decoded JSON document.
  // This line should prints out plain JSON data build from binary buffer:
  // { x: 1, y: 3.14, z: 'hello from BJSON' }
  console.log(plainData)

Limitation

Because JS stores all numbers as 64-bit float there is no way to encode pure 64-bit integer. Maximum integer is limited by amount of bits used to store mantisa part, that stays for 53bits for 64-bit floats (double).

Due to this limitation below types are not supported:

  • array64 (decode/decode)
  • map64 (encode/decode)
  • string64 (encode/decode)
  • binary64 (encode/decode)

After that:

  • Integers greater to 4294967295 (out of 32-bit limit) are encoded as 64-bit float.
  • There is no way to decode 64-bit integer.