JSPM

bitbit

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q38884F
  • License MIT

JavaScript Object to Bits Utility

Package Exports

  • bitbit

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (bitbit) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

bitbit

JavaScript Object to Bit Compression Utility and back

To use BitBit, you create a schema to convert objects to pack them down via a mapping to specific bits in a number and back.

Supports:

  • Numbers
  • Booleans
  • Using Lodash Keys for Getter/Setters (see Usage)

Does Not Support:

  • Packing anything other than numbers or booleans down yet

Usage

const BitBit = require('bitbit');

const bitBit = new BitBit({
  level: [0, 7],                  // 128 Levels Available to Pack
  class: [8, 9],                  // 0 - 3 (4 Classes)
  'inventory[0].value': [10, 41], // 32 Bit Integer Available
});

let player = {
  name: 'Joe the Great',
  level: 100,
  class: 1,               // Warrior
  inventory: [
    { name: 'Great Blade of Grass', value: 1 },
    { name: 'Great Shield of Wood', value: 999 },
  ],
};

let packed = bitBit.pack(player);
// 1380

let unpacked = bitBit.unpack(packed);
// { level: 100, class: 1, inventory: [ { value: 1 } ] }

Other Notes

A helpful tip is if you do use the lodash getter setter values in the schema - to use lodash.merge to merge settings back into the original object if you do lose any of the settings in the packing process.