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

tabcoord

v1.3.0

Published

Multi-tab coordination layer — shared state, leader election, distributed locks, event bus

Readme

tabcoord

Cross-tab state sync, leader election, distributed locks, and event bus — zero dependencies.

npm version

Install

npm install tabcoord
# or just install tabcoord-react — it includes everything
npm install tabcoord-react

Quick Start

import { createSharedStore } from 'tabcoord';

const store = createSharedStore({
  name: 'counter',
  initial: { count: 0 },
});

store.get();                                    // { count: 0 }
store.set({ count: 1 });                        // syncs to all tabs
store.set(s => ({ count: s.count + 1 }));       // updater function
const unsub = store.subscribe((s) => console.log(s));
store.destroy();

API

createSharedStore(options)

const store = createSharedStore({
  name: 'my-store',          // unique name
  initial: { count: 0 },     // starting value or () => value
  persist: { version: 1 },   // optional: localStorage persistence
  onError: (err) => {},      // optional: error callback
});

SharedStoreHandle

| Method | Returns | Description | |--------|---------|-------------| | store.get() | T \| undefined | Get current state | | store.set(value) | void | Set state (syncs to all tabs) | | store.set(fn) | void | Update with function | | store.subscribe(fn) | () => void | Listen for changes | | store.destroy() | void | Clean up | | store.status | 'bootstrap' \| 'synced' | Store status |

leaderElection(name, options?)

const election = leaderElection('my-app', {
  heartbeatInterval: 2000,  // default: 2000ms
  timeout: 5000,            // default: 5000ms
});

election.onElected(() => { /* leader */ });
election.onDemoted(() => { /* follower */ });
election.isLeader;           // boolean

Uses Web Locks API when available, falls back to heartbeat-based election.

lockManager(name, options?)

const lock = lockManager('data-write', { ttl: 30000 });

await lock.acquire(async () => { await writeData(); });
await lock.acquire(fn, { timeout: 5000 });
const acquired = await lock.tryAcquire(fn);

eventBus(name, options?)

const bus = eventBus('events', { maxReplay: 50 });

bus.emit('user:login', { userId: 123 });          // local + cross-tab
bus.on('user:*', (e) => console.log(e.type));      // wildcard
bus.on('*', (e) => {});                             // all events
bus.on('user:*', handler, { replay: true });        // replay past events

diff / apply (subpath export)

import { diff, apply } from 'tabcoord/diff';

const patch = diff({ a: 1, b: 2 }, { a: 1, b: 3 });
const next = apply({ a: 1, b: 2 }, patch);

Error Classes

import {
  TabcoordError, StoreDestroyedError, LockTimeoutError,
  LockManagerDestroyedError, BootstrapTimeoutError,
} from 'tabcoord';

Exports

// ESM
import { createSharedStore } from 'tabcoord';

// CJS
const { createSharedStore } = require('tabcoord');

// Subpath
import { diff, apply } from 'tabcoord/diff';

How It Works

  1. BroadcastChannel with localStorage fallback
  2. Logical clock (counter + tab ID) for conflict resolution
  3. Bootstrap handshake — new tabs request state from existing tabs
  4. Deterministic leader election — lowest tab ID wins ties

Browser Support

| Browser | Minimum Version | |---------|----------------| | Chrome | 54+ | | Firefox | 38+ | | Safari | 16+ | | Edge | 79+ | | Node.js | 18+ (SSR only) |

Bundle Size

| Package | Gzipped | Dependencies | |---------|---------|--------------| | tabcoord | ~6 KB | 0 | | tabcoord-react | ~1 KB | tabcoord, react |

License

MIT