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

upgrade-modal-version

v1.0.3

Published

**Upgrade Modal Version** is a package that displays a modal whenever the version in your application's package.json changes compared to the version stored in local storage. This package is specifically designed for PWA applications to help refresh cached

Readme

Upgrade Modal Version

Introduction

Upgrade Modal Version is a package that displays a modal whenever the version in your application's package.json changes compared to the version stored in local storage. This package is specifically designed for PWA applications to help refresh cached content after updates.

Features

  1. Compares the version in package.json with the version stored in local storage.

  2. Displays a modal if the versions differ.

  3. Requires the user to explicitly provide their package.json file for better control.

  4. Supports highly customizable UI and behavior.

  5. Provides hooks for pre-upgrade logic and error handling.

  6. Seamless integration with PWA projects.

display

Installation

Install the SDK via npm:

npm install upgrade-modal-version

or yarn

yarn add upgrade-modal-version

Usage

Step 1: Add a cache-clearing function to your service worker

In your service worker file, include the following code to handle cache clearing when the modal triggers the update:

self.addEventListener('message', (event) => {
  if (event.data && event.data.type === 'CLEAR_CACHE') {
    caches.keys().then((cacheNames) => {
      cacheNames.forEach((cacheName) => {
        caches.delete(cacheName);
      });
    });
  }
});

Step 2: Add the Modal to Your Application

Import and provide your package.json to the UpgradeModal component:

import UpgradeVersionModal from "upgrade-modal-version";
import 'upgrade-modal-version/dist/style.css'
import yourPackageJS from '../package.json';


function App() {
  return (
    <div>
      <UpgradeVersionModal packageJson={yourPackageJS} />
    </div>
  );
}

Customization

You can customize the modal using the following type:

type UpgradeVersionModalProps = {
  packageJson: PackageJson;
  type?: "modal" | "popup";
  render?: {
    header?: JSX.Element;
    version?: (target: string, current?: string) => JSX.Element;
    button?: (loading: boolean, upgrade: () => Promise<void>) => JSX.Element;
    rocket?: {
      projectionModifier?: string;
      color?: string;
    };
  };
  containerClassName?: string;
  modalClassName?: string;
  onBeforeUpgrade?: () => void;
};

Example

import UpgradeVersionModal from "upgrade-modal-version";
import 'upgrade-modal-version/dist/style.css'
import yourPackageJS from '../package.json';

function App() {
  return (
    <div>
      <UpgradeVersionModal
        packageJson={yourPackageJS}
        type="popup"
        render={{
          header: <h1>Upgrade Available</h1>,
          version: (target, current) => (
            <p>
              New version: {target}, Current version: {current}
            </p>
          ),
          button: (loading, upgrade) =>
            loading ? (
              <button disabled>Updating...</button>
            ) : (
              <button onClick={upgrade}>Update</button>
            ),
          rocket: { projectionModifier: "1.5rem", color: "red" },
        }}
        containerClassName="custom-container"
        modalClassName="custom-modal"
        onBeforeUpgrade={() => console.log("Preparing for upgrade...")}
      />
    </div>
  )
}

License

ISC Licensed. Copyright (c) Esollabs 2024.