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

when-events

v1.0.3

Published

A module for managing asynchronous and synchronous conditions with corresponding callback functions.

Readme

when-events

The when-events module is designed to manage a collection of asynchronous and synchronous conditions and their corresponding callback functions.

Installation

To install the module, use npm:

npm install when-events

Usage

Importing the Module

import When from 'when-events';

Adding a Condition and Callback Function

When.call(
    async () => {
        // Your condition
        return true;
    },
    () => {
        // Your callback
        console.log('Condition met!');
    }
);

Adding a Condition with a Custom ID

You can add a condition and specify a custom ID for better control and management:

When.call(
    async () => {
        // Your condition
        return true;
    },
    () => {
        // Your callback
        console.log('Condition met!');
    },
    'customID' // Custom ID
);

Updating Conditions

The update method checks all conditions and calls the corresponding callback functions.

await When.update();

Getting All Conditions

The all method returns all conditions and their states.

const allCalls = When.all();
console.log(allCalls);

Getting a Specific Condition

The get method returns a specific condition by its ID.

const specificCall = When.get('0');
console.log(specificCall);

Getting a Condition by Custom ID

You can get a specific condition using its custom ID:

const specificCall = When.get('customID');
console.log(specificCall);

Removing a Condition

The remove method removes a condition by its ID.

When.remove('0');

Removing a Condition by Custom ID

You can remove a condition by its custom ID:

When.remove('customID');

Automatic Updating

To automatically update conditions, you can use setInterval:

setInterval(() => {
    When.update();
}, 1000);

Example

import When from 'when-events';

// Adding a condition and callback function
When.call(
    async () => {
        // Condition
        return true;
    },
    () => {
        // Callback
        console.log('Condition met!');
    }
);

// Adding a condition with a custom ID and callback function
When.call(
    async () => {
        // Condition
        return true;
    },
    () => {
        // Callback
        console.log('Condition met!');
    },
    'myCondition' // Custom ID
);

// Automatically updating conditions every 1000 milliseconds (1 second)
setInterval(() => {
    When.update();
}, 1000);

// Getting and logging the condition with the custom ID
const specificCall = When.get('myCondition');
console.log(specificCall);

// Removing the condition with the custom ID
When.remove('myCondition');

License

The when-events module is distributed under the MIT license.