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

@ikeboy003/cart

v0.4.0

Published

Headless cart primitive: local-first state + a configurable durable sync path. Framework-agnostic core, optional React binding. No POS/payment/store logic baked in.

Readme

@ikeboy003/cart

Headless cart primitive. Local-first cart state + a configurable durable sync path. Import the engine, inject config, design your own UI. The library knows nothing about any POS, payment provider, store, framework, or item kind — like postgrest-rs, behaviour comes from config, not baked-in business logic.

Install

npm i @ikeboy003/cart

Use

import { createCart, httpSync } from "@ikeboy003/cart";

const cart = createCart({
  namespace: "plane-things",                 // scopes storage keys + cart id
  storage: localStorage,                      // or memory / custom Storage
  sync: httpSync({ endpoint: "/api/cart" }),  // your durable write path
  debounceMs: 400,
});

cart.add({ id: "tee:L", quantity: 1, priceCents: 3199, title: "Formation Tee" });
cart.count;          // 1
cart.subtotalCents;  // 3199
await cart.flush();  // force the durable mirror current (call before checkout)

React (separate entry, optional):

import { CartProvider, useCart } from "@ikeboy003/cart/react";

<CartProvider namespace="plane-things" sync={httpSync({ endpoint: "/api/cart" })}>
  <App />
</CartProvider>;

const { items, count, subtotalCents, add, remove, updateQuantity, clear, flush } = useCart();

What it does (and only this)

local cart state · add · remove · updateQuantity · count / subtotalCents · debounced sync · flush · restore from storage + durable · the CartSyncAdapter interface.

It does not know about Square, Toast, Stripe, Cloudflare/D1, auth, fulfillment, or item kind. Those are the app's concern.

Line shape

The minimum for cart mechanics is { id, quantity, priceCents }; title/sku are optional and metadata passes through untouched. The engine is generic, so map your product into a typed line and keep type-safety end to end:

type MerchLine = CartItem & { metadata: { variationId: string; team: string } };
const cart = createCart<MerchLine>({ namespace: "plane-things", /* … */ });

When does sync happen

  1. Every mutationlocalStorage synchronously (the live cart, zero latency).
  2. Durable push → coalesced ~debounceMs after the last change, plus a forced flush on visibilitychange: hidden / pagehide (so the backend is current before the tab closes / checkout). keepalive lets that final PUT land during unload.
  3. restore() → pulls from the durable store once when the local cart is empty (returning / cross-device). Local wins when both exist.

The flow it slots into

frontend cart (this lib)
  -> durable cart row        (your sync adapter; usually Cloudflare D1)
  -> checkout / payment
  -> payment webhook
  -> graft pipeline looks up the durable cart
  -> creates merchant/POS records   (Square today, Toast tomorrow — swappable)

The durable row is the bridge. The app owns the /api/cart route (writes whatever store it uses) and the post-payment pipeline. This package owns only the left edge.

Sync adapter

httpSync posts to an app route:

PUT  {endpoint}            body: CartSnapshot        -> 2xx   (upsert)
GET  {endpoint}?id=&namespace=                       -> { items } | 404

Implement CartSyncAdapter yourself to target anything else (direct DB client, KV, IndexedDB, …) — push(snapshot) / pull(id, namespace).