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

@digilabscz/sync-hub-js

v1.0.8

Published

Lightweight master-slave tab synchronization hub for browsers

Readme

📡 SyncHub - Master/Slave Tab Synchronization for Browsers

SyncHub is a lightweight JavaScript library that enables master-slave synchronization between browser tabs using BroadcastChannel and localStorage. It prevents excessive server requests and ensures data consistency across tabs.

  • ✅ Master tab handles data fetching
  • ✅ Slave tabs stay passive and react to updates
  • ✅ Automatic master re-election if the active tab changes
  • ✅ Supports periodic data fetching or manual updates
  • ✅ Designed for e-commerce carts, notifications, and any shared browser state

🚀 Installation

NPM

npm i @digilabscz/sync-hub-js

Then:

import SyncHub from '@digilabscz/sync-hub-js';
SyncHub.init();

or (CommonJS)

const SyncHub = require('@digilabscz/sync-hub-js');
SyncHub.init();

CDN

<script src="https://unpkg.com/@digilabscz/sync-hub-js@latest/dist/sync-hub.min.js"></script>

or

<script src="https://cdn.jsdelivr.net/npm/@digilabscz/sync-hub-js@latest/dist/sync-hub.min.js"></script>

The library will automatically call init() method and register as window.SyncHub.


Examples

🔄 Example 1 - Static Data Synchronization

<div id="notifications-badge" style="padding:10px; background:orange;"></div>

<script>
    // Initialize task for static data
    let task = window.SyncHub.registerTask('notifications-badge')
        .onUpdate((newState, prevState) => {
            renderNotificationBadge(newState, prevState);
        });

    // Manually update the task (can be triggered by button or event)
    task.update(5);

    function renderNotificationBadge(newState, prevState) {
        const node = document.querySelector('#notifications-badge');

        if (window.SyncHub.isMaster()) {
            node.classList.add('master');
        } else {
            node.classList.remove('master');
        }

        node.innerHTML = `<strong>${newState}</strong><sup>/${prevState !== undefined ? prevState : 0}</sup>`;
    }

    // Render initial state (if any)
    renderNotificationBadge(task.getState());
</script>

🌐 Example 2 - Auto Fetch from API (Notifications Badge)

<div id="notifications-badge" style="padding:10px; background:orange;"></div>

<script>
    // Create a task that fetches data every 5 seconds (only master tab runs fetch)
    let task = window.SyncHub.registerTask('notifications-badge')
        .onInterval(async (task) => {
            const response = await fetch('https://api.example.com/notifications-count', { cache: "no-store" });
            const count = await response.text();
            return parseInt(count);
        }, 5000, true) // true = run immediately
        .onUpdate((newState, prevState) => {
            renderNotificationBadge(newState, prevState);
        });

    function renderNotificationBadge(newState, prevState) {
        const node = document.querySelector('#notifications-badge');

        if (window.SyncHub.isMaster()) {
            node.classList.add('master');
        } else {
            node.classList.remove('master');
        }

        if (newState > 0) {
            node.classList.add('active');
        } else {
            node.classList.remove('active');
        }

        node.innerHTML = `<strong>${newState}</strong><sup>/${prevState !== undefined ? prevState : 0}</sup>`;
    }

    // Render initial state (if any)
    renderNotificationBadge(task.getState());
</script>

⚙️ API Summary

| Method | Description | |---------------------------------------------------------------|--------------------------------------------------------| | SyncHub.registerTask(taskName) | Register a new named task | | task.onInterval(callback, intervalMs, runImmediately = false) | Define a periodic action the master tab should execute | | task.onUpdate(callback) | React to data updates in all tabs | | task.update(newData) | Manually trigger a new update | | task.getState() | Get the last known state of the task | | SyncHub.isMaster() | Check if the current tab is master |