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 🙏

© 2026 – Pkg Stats / Ryan Hefner

tiny-binary-format

v0.0.2

Published

Get memory efficient using binary formats instead of objects.

Downloads

18

Readme

Travis Status

tiny-binary-format

Memory efficient JS using binary formats instead of objects.

var BinaryFormat = require('tiny-binary-format');

var Tile = new BinaryFormat([
  { length: 8, name: 'type' },
  { length: 8, name: 'height' },
  { length: 1, name: 'vegetation' }
]);

Tile.pack(4, 48, 1);
// 000000100001100001 (2145)

Tile.unpack(2145);
// { type: 4, height: 48, vegetation: 1 }

Tile.unpackArray(2145);
// [4, 48, 1]

This library is designed to be used as a very thin wrapper around dealing with binary data yourself.

Define a format by creating an instance of BinaryFormat and passing in your field specifications. Then call the resulting object, passing instance data as arguments in order to create a binary representation.

When you need to read the values back, pass the number to either .unpack which returns the values in an object, or .unpackArray which returns them in an array.

Install

npm install tiny-binary-format

Gotchas

The module was designed for storing lightweight tile representations for games, however it could be used for a lot of other things too. Just remember that once the data has been serialized, it will always be read back out as numbers.

This module should be used for removing the neccessity of working with bitwise operators when dealing with binary formats. It's not a framework and it won't hold your hand.

This module does no error handling whatsoever. If you care enough about performance to be using a binary format in the first place, then you'll appreciate the transparency of the pack and unpack methods.

However, this does mean that if you pass in a 9 bit number into an 8 bit field, you'll lose precision silently. Use it carefully.

As pointed out by @dioxmat, you're still bound by the restrictions of MAX_SAFE_INTEGER. If you're dealing with integers greater than 2 ^ 53, then expect things to break.

FAQ

What if I need to store strings or objects too?

If you arrived here looking for a Javascript library for parsing binary format files that include lots of data types, you've come to the wrong place. Go and check out binary-format

What would be a good use case for this library?

This code was born from a game engine, read more about where it might be useful in the accompanying blog blost.