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

@digta/codec

v0.1.0

Published

Zero-dependency message framing (length-prefix + delimiter) and typed binary struct read/write. Pairs with @digta/network.

Readme

@digta/codec

Zero-dependency message framing and typed binary struct read/write for Node. The missing half of raw TCP: turn a byte stream into whole messages, and read/write fixed-layout binary (Modbus registers, custom device protocols).

npm install @digta/codec

Framing — byte stream → whole messages

TCP has no message boundaries: one send can arrive as three chunks, or three sends as one. A framer buffers partial data and hands you only complete frames.

Length-prefixed

import { lengthPrefix } from "@digta/codec";
// or: const { lengthPrefix } = require("@digta/codec");

const framer = lengthPrefix({ bytes: 2 });   // 2-byte big-endian length header

// pairs directly with @digta/network:
conn.on("message", framer.feed);
framer.on("frame", (msg) => handle(msg));     // msg = payload without the prefix

conn.send(framer.encode("hello"));            // prepends the length header

Options: bytes (1 | 2 | 4, default 2), endian ('be' | 'le', default 'be'), includePrefix (does the length count its own header? default false), maxFrame (reject oversized frames, default 10 MB).

Delimiter

import { delimiter } from "@digta/codec";

const lines = delimiter("\n");                // or "\r\n", or a Buffer
conn.on("message", lines.feed);
lines.on("frame", (line) => console.log(line.toString()));
conn.send(lines.encode("PING"));              // appends the delimiter

Functional style (no events)

push() is the core — feed a chunk, get back complete frames, the remainder stays buffered:

for (const frame of framer.push(chunk)) handle(frame);

struct — typed binary read/write

Describe a fixed layout once, then decode/encode Buffers against it. Field order = byte order.

import { struct } from "@digta/codec";

const packet = {
  id:      "uint16be",
  temp:    "int16be",                 // e.g. tenths of a degree, can be negative
  running: "bool",
  name:    { type: "string", length: 8 },
  regs:    { type: "array", of: "uint16be", length: 4 },
};

const obj = struct.read(buffer, packet);     // → { id, temp, running, name, regs }
const buf = struct.write(obj, packet);       // → Buffer
struct.size(packet);                         // → byte length

Types

uint8 int8 · uint16 int16 uint32 int32 · float32/float float64/double · bool

Add be/le for endianness (uint16le, float32be, …). Bare names are big-endian — the network / Modbus default. Plus:

  • { type: "string", length, encoding? } — fixed-width text (trailing NULs trimmed on read)
  • { type: "bytes", length } — raw Buffer slice
  • { type: "array", of, length } — repeated scalar (e.g. a block of Modbus registers)

Why it pairs with @digta/network

@digta/network deliberately leaves TCP framing to you (it's protocol-specific). This is that layer:

import { createConnection } from "@digta/network";
import { lengthPrefix, struct } from "@digta/codec";

const conn = createConnection({ url: "tcp://192.168.1.10:9000" });
const framer = lengthPrefix({ bytes: 2 });

conn.on("message", framer.feed);
framer.on("frame", (buf) => {
  const reading = struct.read(buf, { sensor: "uint16be", value: "float32be" });
  logger.info(reading);
});
conn.connect();

License

MIT