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

@teskevirtualsystem/struct.js

v1.0.0

Published

Python struct module port to JavaScript — pack/unpack binary data using format strings

Downloads

293

Readme

      _                   _      _     
  ___| |_ _ __ _   _  ___| |_   (_)___ 
 / __| __| '__| | | |/ __| __|  | / __|
 \__ \ |_| |  | |_| | (__| |_ _ | \__ \
 |___/\__|_|   \__,_|\___|\__(_)/ |___/
                              |__/     

Python struct module port to JavaScript — pack and unpack binary data using format strings.

Works in Node.js and browsers (no dependencies, uses Web APIs: ArrayBuffer, DataView, BigInt).

Install

npm install @teskevirtualsystem/struct.js

Usage

import { pack, unpack, calcSize } from "@teskevirtualsystem/struct.js";

// Pack an unsigned int (1234) — returns ArrayBuffer
const buf = pack("I", 1234);

// Unpack it back
unpack("I", buf); // [1234]

// Pack multiple fields
const buf2 = pack("Ifc", 9184, 10.5, "a");
unpack("Ifc", buf2); // [9184, 10.5, "a"]

// Big-endian
const buf3 = pack(">I", 1234);
unpack(">I", buf3); // [1234]

// Repeat counts
const buf4 = pack("3I", 10, 20, 30);
unpack("3I", buf4); // [10, 20, 30]

// Fixed-width strings
const buf5 = pack("10s", "hello");
unpack("10s", buf5); // ["hello\0\0\0\0\0"]

// Pascal strings (length-prefixed)
const buf6 = pack("10p", "hello");
unpack("10p", buf6); // ["hello"]

// Calculate size without packing
calcSize("IHHf"); // 14

API

unpack(fmt, input)Array

Unpacks binary data according to the format string.

Input types: string (legacy), ArrayBuffer, or DataView.

pack(fmt, ...values)ArrayBuffer

Packs values into an ArrayBuffer according to the format string.

calcSize(fmt)number

Returns the byte size of the packed data for a given format.

StructError

Error class thrown on invalid formats, buffer size mismatches, value count mismatches, or out-of-range values.

Format String

First character (optional) sets endianness:

| Prefix | Endianness | |--------|-----------| | @, =, < | Little-endian | | >, ! | Big-endian |

Remaining characters define fields. A numeric prefix repeats the field:

| Format | C Type | Size | Description | |--------|---------|------|-------------| | x | pad byte | 1 | Skips bytes (no value consumed) | | c | char | 1 | Single character string | | b | signed char | 1 | Integer | | B | unsigned char | 1 | Integer | | ? | _Bool | 1 | Boolean | | h | short | 2 | Integer | | H | unsigned short | 2 | Integer | | i | int | 4 | Integer | | I | unsigned int | 4 | Integer | | l | long | 4 | Integer | | L | unsigned long | 4 | Integer | | q | long long | 8 | BigInt | | Q | unsigned long long | 8 | BigInt | | f | float | 4 | Float | | d | double | 8 | Double | | s | char[] | N | Fixed-width string (N bytes, padded with \0) | | p | char[] | N | Pascal string (1 length byte + N-1 data bytes) | | P | void * | 4 | Integer (pointer, 32-bit) |

Dev

npm run build      # Copy src/ to dist/
npm test           # Run tests (vitest)
npm run test:watch # Watch mode
npm run lint       # ESLint
npm run typecheck  # TypeScript declaration check

License

MIT