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 🙏

© 2025 – Pkg Stats / Ryan Hefner

tab-syncer

v1.0.7

Published

A lightweight (4KB) library for browser tab state synchronization and communication. Supports auto-persistence and real-time data sync between tabs.

Readme

TabSyncer

🚀 The simplest way to sync data between browser tabs! A tiny yet powerful library that makes tab communication a breeze.

中文

English

Why TabSyncer?

  • 🪶 Incredibly Light - Tiny 4KB footprint with zero dependencies. Your bundle size will thank you!
  • 🔄 Seamless Sync - Keep your tabs in perfect harmony. Update data in one tab, see it everywhere!
  • 📨 Easy Communication - Let your tabs talk to each other like best friends
  • 💾 Smart Management - Handle your data with ease. Auto-persists state across page refreshes!
  • 🔐 Auto Persistence - Your data survives refreshes and tab closures. Never lose state again!

Get Started in Seconds

npm install tab-syncer
# or
yarn add tab-syncer

Show Me the Code!

import { TabSyncer } from 'tab-syncer';

// Initialize TabSync with a unique namespace and initial state
const tabSyncer = new TabSyncer(
  'myApp',           // namespace
  'broadcast',       // sync method
  {                  // initial state
    count: 0,
    message: ''
  }
);

// Update state
tabSyncer.setState(prevState => ({
  ...prevState,
  count: prevState.count + 1
}));

// Get current state
const state = tabSync.getState();

// Listen to state changes
tabSyncer.onStateChange((state) => {
  console.log('State updated:', state);
});

// Send notifications across tabs
tabSyncer.notify('customEvent', { data: 'Hello from another tab!' });

// Subscribe to notifications
tabSyncer.subscribe('customEvent', (data) => {
  console.log('Received:', data);
});

API Reference

Constructor

new TabSyncer(namespace, method, initialState)

Creates a new TabSyncer instance.

new TabSyncer(
  namespace: string,  // Unique identifier for your app instance
  method: string,     // Sync method, currently supports 'broadcast'
  initialState: T     // Initial state object of any type
)

Methods

setState(newState)

Updates the state across all tabs.

Type:

setState(newState: T | ((prevState: T) => T)): void

Example:

// Direct value
tabSyncer.setState({ count: 1, message: 'Hello' });

// Updater function
tabSyncer.setState(prevState => ({
  ...prevState,
  count: prevState.count + 1
}));

getState()

Returns the current state.

Type:

getState(): T

Example:

const currentState = tabSyncer.getState();
console.log(currentState); // { count: 1, message: 'Hello' }

onStateChange(callback)

Subscribe to state changes across all tabs.

Type:

onStateChange(callback: (state: T) => void): () => void

Example:

const unsubscribe = tabSyncer.onStateChange((state) => {
  console.log('New state:', state);
});

// Cleanup when needed
unsubscribe();

notify(event, data)

Send a custom event to all other tabs.

Type:

notify(event: string, data: any): void

Example:

tabSyncer.notify('userLoggedIn', { 
  userId: 123,
  timestamp: Date.now()
});

subscribe(event, callback)

Listen for custom events from other tabs.

Type:

subscribe(event: string, callback: (data: any) => void): () => void

Example:

const unsubscribe = tabSyncer.subscribe('userLoggedIn', (data) => {
  console.log('User logged in from another tab:', data);
});

// Cleanup when needed
unsubscribe();

License

MIT