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

tinybuf

v1.8.6

Published

Fast, compressed binary serializers in Node.js and HTML5

Downloads

232

Readme

🔌 tinybuf  NPM version Minzipped Downloads Tests License

⚡Fast, compressed binary serializers in Node.js and HTML5

| | | | --------------------------------- | ---------------------------------------- | | 🔮 Simple, declarative API | 🔥 Blazing fast serialization | | 🗜️ Powerful compression | 💾 ^50% smaller than FlatBuffers | | 🍃 Zero dependencies | 🙉 Strong, inferred types | | 🌐 Node / browser | 🛡️ Built-in validation/transforms | | 🤏 ~4.4kb minzipped | ✅ Property mangling (Terser) |

💿 Install

npm install tinybuf

🕹 Example

import { defineFormat, Type } from 'tinybuf';

export const GameWorldData = defineFormat({
  frameNo: Type.UInt,
  timeRemaining: Type.Float16,
  players: [
    {
      id: Type.UInt,
      position: {
        x: Type.Float32,
        y: Type.Float32
      },
      joystick: {
        x: Type.Scalar8,
        y: Type.Scalar8
      },
      actions: Type.Bools // [ jump, attack ]
    }
  ]
});

Encode

Formats can be encoded directly:

let bytes = GameWorldData.encode({
  frameNo: 50,
  timeRemaining: 59.334,
  players: [
    {
      id: 1,
      position: { x: 123.5, y: 456.75 },
      joystick: { x: 0.75, y: -0.662 },
      actions: [ /* jump: */ true,
               /* attack: */ false ]
    }
  ]
});

bytes.byteLength
// 16

Or directly from objects:

let bytes = GameWorldData.encode( obj );

bytes.byteLength
// 16

Decode

Formats can be read in a number of ways:

  1. Simple – decode to object
  2. In-place – decode into an existing object
  3. Parser – register / decode many formats

Simple

Decode as a strongly-typed object.

let obj = GameWorldData.decode( bytes );
// { frameNo: number; timeRemaining: number; … }

In-place

Use for memory effiency - extract fields directly into an existing object instance. This prevents allocating new memory.

let obj: Decoded<typeof GameWorldData> = {} as any;

GameWorldData.decode( bytes, obj );

Parser – Decoding registered formats

  • Register formats with .on(format, handler, options?)
  • Trigger format handlers with .processBuffer(bytes)
import { bufferParser } from 'tinybuf';

// register
const parser = bufferParser()
  .on(MyChatMessage, msg => myHud.showChat(msg))
  .on(GameWorldData, data => myWorld.update(data), {
    decodeInPlace: true, // `data` gets recycled
  });

// parse
parser.processBuffer( bytes );

📘 Documentation

| | | | --- | :--- | | 🏁 Quick start: | Quick start guide,Types | | 📑 Advanced: | Async safety mode,Format header collisions,Compression tips,Validation/transforms |

Credits

tinybuf is based on Guilherme Souza's js-binary