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

binspector

v2.0.0

Published

A _truly_ declarative library for binary file and protocol definition written in typescript. Read binary files based on class definition and decorators directly from your webapp.

Readme

🕵️ binspector, your binary file assistant

A truly declarative TypeScript library to help you create binary file and protocol definitions.

  • 🗣️ Declarative – Define binary structures using decorators.
  • 🔄 Read & Write Support – Seamlessly parse & serialize binary data.
  • ⬆️ Extensible - Write custom decorators.
  • 🖋️ Typed – Leverage TypeScript’s type system for validation.
  • 🌐 Works in the Browser – Use Binspector for frontend or backend binary processing.
  • 📦 Zero Dependencies – No external dependencies.

📌 What does it looks like ?

See examples for real files formats.

class ProtocolHeader {
  // Ensure the header starts with specific magic number
  @Match(".bin")
  @Count(4)
  @Ascii
  extension: string

  @Uint32
  len: number

  @Uint32
  string_map_offset: number

  @Uint32
  string_map_size: number
}

enum RecordTypes {
  RecordStart = 0x01,
  RecordMsg = 0x02,
  RecordEnd = 0x03,
}

class RecordMessage {
  @Uint32
  size: number

  @Size('size')
  @Utf8
  message: string
}

class Record {
  @Uint32
  id: number

  // Supports TypesSript enums
  @Enum(RecordTypes)
  @Uint8
  type: RecordTypes

  // Dynamically select a subtype based on `type`
  @Choice('type', {
    [RecordTypes.RecordMsg]: RecordMessage,
    [RecordTypes.RecordStart]: undefined,
    [RecordTypes.RecordEnd]: undefined,
  })
  data: RecordMessage;
}

class Protocol {
  // Nested structure with a reference to another class
  @Relation(ProtocolHeader)
  header: ProtocolHeader

  // Use values from previously read properties
  @Count('header.len')
  @Relation(Record)
  records: Record

  // Jump to an arbitrary offset and read data until size is reached
  // to create an array of strings
  @Offset('header.string_map_offset')  
  @Size('header.string_map_size')  
  @NullTerminatedString()
  strings: string[]
}

🚀 Features

  • Declarative Class-Based Approach – Define binary structures as TypeScript classes.
  • Leverages TypeScript's Type System – No need to write separate type definitions.
  • Fully Extensible – Unlike DSL-based libraries, Binspector is easily extensible to create custom decorators.
  • Supports Complex Binary Operations:
    • Endianness
    • Magic numbers and enums validation
    • Conditional parsing
    • Bitfields
    • Nested Structure & recursive references
    • Dynamic offset, variable length properties
    • String encodings (UTF-8, UTF-16, UTF-32, ASCII)
    • Shared context

📦 Installation

Install Binspector from npm:

> npm install binspector

📁 Usage

Here’s a simple example of reading and writing a binary coordinate system.

import { Relation, Uint8, Count } from 'binspector'

class Coord {
  @Uint8
  x: number

  @Uint8
  y: number
}

class Protocol {
  @Uint8
  len: number

  @Count('len')
  @Relation(Coord)
  coords: Coord[]
}

🔍 Reading an ArrayBuffer into Objects

import { binread } from 'binspector'

const buf = new Uint8Array([0x02, 0x01, 0x02, 0x03, 0x04])

binread(buf, Protocol)
// => { len: 2, coords: [{ x: 1, y: 2 }, { x: 3, y: 4 }] }

✍️ Writing Objects to ArrayBuffer

import { binwrite, BinaryWriter } from 'binspector'

const obj = { len: 2, coords: [{ x: 1, y: 2 }, { x: 3, y: 4 }] }

binwrite(obj, Protocol)
// => [0x02, 0x01, 0x02, 0x03, 0x04]

📖 Learn more