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

barsic

v0.2.0

Published

A fluffy parser and builder for binary data

Readme

barsic

A lightweight library for working with binary data in a type-safe and declarative way. Instead of writing manual parsing code, Barsic lets you define binary formats as simple objects and handles all the encoding and decoding for you.

Features

  • 🚀 Simple & Declarative API - Define binary formats using a straightforward object syntax
  • 🔄 Two-way Conversion - Both encode and decode operations
  • 🔬 Zero Dependencies - Lightweight and self-contained
  • 📦 Rich Type System - Supports integers, strings, arrays, nested objects, discriminated unions, and more
  • 🎯 Type-safe - Full TypeScript support with proper type inference
  • 🌐 Universal - Works in Node.js, browsers, Bun, Deno, and any JavaScript runtime

Install

npm i barsic

Usage

import { b } from 'barsic';

// Define a simple user profile format
const UserProfile = b.object({
  version: b.uint8(), // Format version
  nameLength: b.uint8(), // Length of the name string
  name: b.string(), // User's name
  age: b.uint8(), // User's age
  scores: b.array(b.uint16(), 3), // Array of 3 game scores
});

// Create binary data
const profileData = UserProfile.encode({
  version: 1,
  nameLength: 4,
  name: 'John',
  age: 25,
  scores: [100, 250, 175],
});

console.log(profileData);
// Output: Uint8Array([
//   0x01,             // version = 1
//   0x04,             // nameLength = 4
//   0x4A, 0x6F, 0x68, // "John"
//   0x6E,
//   0x19,             // age = 25
//   0x00, 0x64,       // scores[0] = 100
//   0x00, 0xFA,       // scores[1] = 250
//   0x00, 0xAF        // scores[2] = 175
// ])

// Decode binary data back into an object
const decoded = UserProfile.decode(profileData);
console.log(decoded);
// Output:
// {
//   version: 1,
//   nameLength: 4,
//   name: "John",
//   age: 25,
//   scores: [100, 250, 175]
// }
import { b } from 'barsic';

// Define a scheme for a simple packet format
const Packet = b.object({
  header: b.object({
    magic: b.literal(new Uint8Array([0xca, 0xfe])), // Magic bytes
    type: b.uint16(),
    length: b.uint32(),
  }),
  payload: b.discriminatedUnion(
    (ctx) => ctx.header.type, // Select variant based on type field
    {
      1: b.object({
        // Type 1: Text message
        message: b.string(),
      }),
      2: b.object({
        // Type 2: Array of numbers
        count: b.uint16(),
        values: b.array(b.uint32(), (ctx) => ctx.count),
      }),
    }
  ),
});

// Example 1: Parse text message packet
const textPacket = new Uint8Array([
  0xca,
  0xfe, // Magic bytes
  0x00,
  0x01, // Type = 1 (text)
  0x00,
  0x00,
  0x00,
  0x0b, // Length = 11
  0x48,
  0x65,
  0x6c,
  0x6c, // "Hello World"
  0x6f,
  0x20,
  0x57,
  0x6f,
  0x72,
  0x6c,
  0x64,
]);

const decoded1 = Packet.decode(textPacket);
console.log(decoded1);
// Output:
// {
//   header: {
//     magic: Uint8Array([0xCA, 0xFE]),
//     type: 1,
//     length: 11
//   },
//   payload: {
//     message: "Hello World"
//   }
// }

// Example 2: Build array packet
const arrayPacket = Packet.encode({
  header: {
    magic: new Uint8Array([0xca, 0xfe]),
    type: 2,
    length: 14,
  },
  payload: {
    count: 3,
    values: [1, 2, 3],
  },
});

console.log(arrayPacket);
// Output: Uint8Array([
//   0xCA, 0xFE,           // Magic
//   0x00, 0x02,           // Type = 2 (array)
//   0x00, 0x00, 0x00, 0x0E, // Length = 14
//   0x00, 0x03,           // Count = 3
//   0x00, 0x00, 0x00, 0x01, // value[0] = 1
//   0x00, 0x00, 0x00, 0x02, // value[1] = 2
//   0x00, 0x00, 0x00, 0x03  // value[2] = 3
// ])

Available Types

Barsic provides the following built-in types:

  • Numbers

    • int8() - 8-bit signed integer
    • uint8() - 8-bit unsigned integer
    • int16() - 16-bit signed integer
    • uint16() - 16-bit unsigned integer
    • int32() - 32-bit signed integer
    • uint32() - 32-bit unsigned integer
    • int64() - 64-bit signed integer
    • uint64() - 64-bit unsigned integer
    • float16() - 16-bit floating point number
    • float32() - 32-bit floating point number
    • float64() - 64-bit floating point number
  • Strings

    • string() - UTF-8 encoded string
    • base64() - Base64 encoded string
    • hex() - Hex encoded string
  • Compound Types

    • object({...}) - Object with named fields
    • array(type, length) - Fixed or variable length array
    • discriminatedUnion(discriminator, cases) - Tagged union type
    • literal(value) - Exact value matcher
    • bytes(length) - Fixed-length byte array
    • prefixed(length, subSchema) - Prefixed data
    • sized(subSchema, length) - Fixed-length data
    • greedyRange(subSchema) - Greedy range of items

License

MIT