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 🙏

© 2024 – Pkg Stats / Ryan Hefner

page-lifecycle

v0.1.2

Published

A JavaScript library to observe Page Lifecycle API states: https://github.com/WICG/page-lifecycle

Downloads

157,668

Readme

PageLifecycle.js

Overview

PageLifecycle.js is a tiny JavaScript library (<1K gzipped) that allows developers to easily observe Page Lifecycle API state changes and implement Page Lifecycle best practices consistently across all browsers.

▶️ View demo: page-lifecycle.glitch.me 👀

Installation

You can install this library from npm by running:

npm install --save-dev page-lifecycle

Usage

Releases of this library include three minified, production-ready versions:

1. ES5: dist/lifecycle.es5.js (UMD) ⭐

Use this version for maximum compatibility with legacy browsers (that can't run ES2015+ code).

As a UMD bundle, it can be required in CommonJS or AMD environments, or it can be loaded with a script tag as the browser global lifecycle.

<script defer src="/path/to/lifecycle.es5.js"></script>
<script defer>
lifecycle.addEventListener('statechange', function(event) {
  console.log(event.oldState, event.newState);
});
</script>

2. ES2015: dist/lifecycle.mjs (ESM) 🔥

Use this version if you only support ES module-capable browsers or if you're using <script type="module"> and the nomodule fallback to conditionally target modern browsers.

<script type="module">
import lifecycle from '/path/to/page-lifecycle.mjs';

lifecycle.addEventListener('statechange', function(event) {
  console.log(event.oldState, event.newState);
});
</script>

3. ES2015 (native): dist/lifecycle.native.mjs (ESM w/o EventTarget and Event shims) ⚠️

Use this version if you're only targeting browsers that support extending EventTarget and Event constructors.

Note: this version is the smallest but will only work in some browsers. The implementation instructions are the same as the ES2015 version above.

API

The PageLifecycle.js library exports a lifecycle object, which is a singleton instance of the Lifecycle class. The Lifecycle class has the following properties, methods, and events:

Properties

Methods

Events

Browser Support

PageLifecycle.js has been tested and known to work in the above browsers.