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

bserial

v0.1.2

Published

A high-performance binary serializer framework for Node.js.

Downloads

297

Readme

bserial

A high-performance binary serializer framework. Supports both ESM and CJS modules.

Installation

npm i bserial

Features

Supported Data Types

| Type | Alias / Notes | | ------ | ----------------------------------------- | | uint8 | byte | | int8 | | | uint16 | ushort | | int16 | short | | uint32 | uint | | int32 | int | | uint64 | ulong | | int64 | long | | float | float32 | | double | float64 | | bool | boolean | | string | str | | date | date_ms, date_time_ms, int64_date_time_ms | | date_s | date_time_s, int64_date_time_s |

Supported Data Annotations

| Annotation | Description | | ---------------------------- | ------------------------------------------------------------- | | @if(expr:string) | Generates an optional node, present only when expr is true. | | @len(fixedLength:number) | Sets string to use a fixed byte length. | | @encoding(encoding:string) | Sets the string encoding (e.g., 'utf-8'). |

Usages

Basic Usage

import { compile, codec } from "bserial";
// const { compile, codec } = require("bserial"); // or commonjs module

const scheme = {
    isOk: 'byte',
    info: {
        id: 'int',
        name: 'string',
        isVIP: 'boolean',
        scope: 'float',
        createdAt: 'date',
    },
    behaviors: ['short', {
        name: 'string',
    }], // [length type, element scheme]
};

const srcObj = {
    isOk: 1,
    info: {
        id: 100,
        name: 'alien',
        isVIP: true,
        scope: 98.5,
        createdAt: new Date(),
    },
    behaviors: [{name: 'coding'}, {name: 'writing'}],
};

// compile
const ast = compile(scheme);

// encode
const buf = codec.encode(ast, srcObj);
// console.log(buf);
/*
log:
<Buffer 01 00 00 00 64 00 05 61 6c 69 65 6e 01 42 c5 00 00 00 00 01 9c b3 fd de 51 00 02 00 06 63 6f 64 69 6e 67 00 07 77 72 69 74 69 6e 67>
*/

// decode
const obj = codec.decode(ast, buf);
console.log(obj);
/*
log:
{
  isOk: 1,
  info: {
    id: 100,
    name: 'alien',
    isVIP: true,
    scope: 98.5,
    createdAt: 2026-03-03T14:01:48.621Z
  },
  behaviors: [ { name: 'coding' }, { name: 'writing' } ]
}
*/

Usage Via Annotation

| annotation place | usage | | ---------------- | -------------------------------------------------------- | | filed | fieldName: dataType[@annotation...] | | object | __annotations__: [@annotation...] | | list | fieldName: [lengthDataType[@annotation...], elementType] |

import { compile, codec } from "bserial";
// const { compile, codec } = require("bserial"); // or commonjs module

const scheme = {
    isOk: 'byte',
    info: {
        __annotations__: '@if(isOk == 1 || isOk > 3)',
        isVIP: 'boolean',
        name: 'string@len(16)@encoding("utf-8")',
    },
    deadline: 'date@if(info.isVIP)', // or @if(this.info.isVIP)
    data: ['int@if(isOk != 1 )', 'int']
};

const srcObj = {
    isOk: 4,
    info: {
        isVIP: false,
        name: 'fixed string buffer size'
    },
    deadline: new Date(),
    data: [1, 2, 3, 4],
};

// compile
const ast = compile(scheme);

// set endian "BE" or "LE"
codec.setEndian('BE'); // defautl BE if not set.

// encode
const buf = codec.encode(ast, srcObj);
console.log(buf);
/*
log:
<Buffer 04 00 66 69 78 65 64 20 73 74 72 69 6e 67 20 62 75 66 00 00 00 04 00 00 00 01 00 00 00 02 00 00 00 03 00 00 00 04>
*/

// decode
const obj = codec.decode(ast, buf);
console.log(obj);
/*
log:
{
  isOk: 4,
  info: { isVIP: false, name: 'fixed string buf' },
  data: [ 1, 2, 3, 4 ]
}
*/

License

MIT