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

@xazure/event-manager

v0.1.0

Published

An async-first event manager. Used by Xazure framework.

Readme

Xazure Event Manager

An async-first event manager. Used by Xazure CMS.

Uses an async reducer pattern to parse arguments with all events.

Basic Usage

import EventManager from 'xazure-event-manager';

const eventManager = EventManager();

// Add event
eventManager.add('add', async previous => {
  const args = await previous;
  const { a, b, sum = 0 } = args;
  return Object.assign(args, { sum: sum + a + b });
});

// in an async function
// Apply event
const { a, b, sum } = await eventManager.apply('add', { a: 1, b: 2 });

Concepts

Xazure Event Manager is async-first. All of the event callbacks should accept a Promise which resolves an object with the parameters. This allows any event to be asynchronous without any additional effort.

eventManager.add('add', async previous => {
  const args = await previous;
}); 

The event manager will run through each event in priority order:

eventManager.add('rollCall', [
  Object.assign(
    async previous => {
      const args = await previous;
      return Object.assign(args, { list: [].concat(args.list, 'a') });
    }, { priority: 1 }
  ),
  Object.assign(
    async previous => {
      const args = await previous;
      return Object.assign(args, { list: [].concat(args.list, 'b') });
    }, { priority: 2 }
  ),
  Object.assign(
    async previous => {
      const args = await previous;
      return Object.assign(args, { list: [].concat(args.list, 'c') });
    }, { priority: 3 }
  )
]);

const { list } = eventManager.apply('rollCall');
console.log(list); // ['a', 'b', 'c']

Each event should return all of the arguments, making any transforms as necessary.

Any event can return a Promise or the arguments directly.

API

add(eventName, callback, priority)
  • eventName - string - The event name to register.
  • callback - function(Promise<{}>):(Promise<{}>|{}) - The callback function to call, or an array of them.
  • priority - number - Optional. Specifies the priority. Default: 100

callback should accept a Promise as it's only parameter, which will resolve to an object of arguments. It should return the arguments object, applying any required transforms, or a Promise that results in one.

callback can also have a static priority value. If provided, it supersedes the priority argument given to the function. This is useful when passing an array where you want different priorities.

If neither callback.priority or priority are given, it'll be defaulted to 100.

addMap(map)

Registers a map of events, with each key being the event name, and the values the callback(s).

See add() for rules on the callbacks.

apply(eventName, args = {}):Promise<{}>

Applies the arguments to all registered events for the given name, in priority order (ascending).

The args are given to the first callback (wrapped in a Promise), then the result of that is given to the next and so-on (a reducer pattern).