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

@craftycodie/cstruct

v2.0.2

Published

Schema-first binary struct layouts for TypeScript (packed read/write with c.struct and @c.class)

Readme

@craftycodie/cstruct

npm docs

Declarative binary readers and writers for TypeScript, inspired by binrw and zod.

Features

  • Schema-first layouts with c.struct({ field: c.u32() }), or @c.class() / @c.field() decorators (standard or experimentalDecorators)
  • c.read, c.write, c.sizeof and c.offsetof over Uint8Array (including Node Buffer), ArrayBuffer or DataView
  • Packed by default, or C alignment with { align: true } / { pack: n }
  • Byte order per call, per struct or per field
  • Padding, nested structs, arrays, unions, c.match tagged unions, enums, bitfields and multi-bit c.bits
  • zod-style modifiers: .array(n), .default(v), .transform(decode, encode), .assert(check), .be(), …
  • Inferred types: c.infer / c.output for reads, c.input for writes
  • Errors that name the field: write failed at header.points[2].x: 300 is out of range for u8
  • Fast: struct readers and writers are code-generated on first use

Usage

import { c } from "@craftycodie/cstruct";

const Dog = c.struct({
  bone_pile_count: c.u8(),
  favorite_bone: c.u16().padBefore(1),
  name: c.string(16),
});

const bytes = Dog.write({
  bone_pile_count: 2,
  favorite_bone: 0x12,
  name: "Rudy",
});

const parsed = Dog.read(bytes);
console.log(parsed.favorite_bone); // 18
console.log(parsed.name); // "Rudy"

type Dog = c.infer<typeof Dog>; // { bone_pile_count: number; favorite_bone: number; name: string }

Class decorators work too:

@c.class()
class Dog {
  @c.field(c.u8())
  bone_pile_count = 0;

  @c.field(c.string(16))
  name = "";
}

const dog = c.read(Dog, bytes); // a Dog instance
const out = c.write(dog);

@c.field checks the property type against the field: @c.field(c.u64()) id!: number is a compile error, because u64 decodes to bigint.

For guides, the API reference and more examples, see the documentation.

Install

npm install @craftycodie/cstruct

Decorators work with TypeScript's standard decorators or with experimentalDecorators: true; no other setup is needed. Schema-only usage needs neither.

License

MIT