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

starling-crdt

v0.1.0

Published

A from-scratch Fugue/RGA CRDT for collaborative plain text: no runtime dependencies, a compact binary wire format, tombstone-based deletion, and id-based anchors for cursors that survive concurrent edits.

Readme

starling-crdt

A from-scratch Fugue/RGA CRDT for collaborative plain text. No runtime dependencies. A compact binary wire format (LEB128 varints, run-length-encoded deletion runs — 60,000 deletions in 14 bytes). Tombstone-based deletion. Id-based anchors for cursors and undo that survive concurrent remote edits, not raw offsets.

This package is the CRDT core of Starling, a full collaborative editor (ProseMirror binding, a relay server, offline- first persistence, presence). Most people building an editor want that whole stack, not this package alone — see the main repository's docs/ for the full architecture. This package is what you'd reach for if you want the CRDT algorithm itself, decoupled from everything else.

Install

npm install starling-crdt

Usage

import { Doc } from "starling-crdt";

const a = new Doc("replica-a");
const b = new Doc("replica-b");

// Local edits return an op — send it to other replicas however you like
// (a WebSocket, an HTTP relay, a file). This package has no networking
// opinions of its own.
const op1 = a.insertLocal(0, "h");
const op2 = a.insertLocal(1, "i");
b.receive(op1);
b.receive(op2);

a.text; // "hi"
b.text; // "hi" — converges regardless of delivery order or duplicates

// A cursor as an id + side, not a number — stays attached to the same
// character even after concurrent edits shift what index it's at.
const anchor = a.anchorAt(1);
a.insertLocal(0, "!");
a.resolveAnchor(anchor); // 2, not 1 — followed the character it anchored to

Encoding, for wire transport or disk persistence

import { encodeOps, decodeOps } from "starling-crdt";

const bytes = encodeOps([op1, op2]); // Uint8Array
const ops = decodeOps(bytes);

Sync: only send what a peer is missing

// `theirVector`: what the other replica already told you it has.
const missing = a.missingFrom(theirVector);
const bytes = encodeOps(missing);

What's in the box

  • Doc — the Fugue-based implementation. This is the one to use.
  • RgaDoc — an RGA implementation with an order-statistic treap for O(log n) operations. Kept as a working alternative; Doc fixes a correctness gap RGA has under concurrent backward typing (interleaving), which is why it's the default.
  • NaiveDoc, ArrayDoc — reference implementations that are either incorrect under concurrency (NaiveDoc) or correct but algorithmically unusable at scale (ArrayDoc, O(n) per operation). Not for production use — kept for the same reason a museum keeps a "before" exhibit next to the real one: bench/ in the main repository benchmarks all four side by side, honestly, including the ones that lose.

Honest performance note

Doc currently has an O(n²) worst case for a single replica typing a long document forward without pausing (see the main repository's bench/README.md and docs/DECISIONS.md #0026 for the full, unflattering measurement — 168 seconds to cold-open a 100,000-character forward-typed document, against a 1-second target). RgaDoc doesn't have this problem and is faster in that specific scenario. If your workload is large single-session forward typing and cold-open latency matters, benchmark both against your actual workload before picking one.

License

MIT