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

event-manager-js

v1.0.6

Published

An Event Management system for typescript or plain javascript

Readme

Typescript Event Manager

Install

Run in terminal npm install event-manager-js

Usage with TypeScript

Step 1 - Create an event:

Start by creating a domain event class that extends the abstract class DomainEvent. You can do some operations in the event constructor before saving the data as attributes.

Implement payload() getter to return an object that exports all the class attributes. You have to add the "occurredOn" attribute to the returned object. "this.timestamp" is the current timestamp generated when you call the "super()" method in the class constructor.

Example:

import * as eventStore from 'event-manager-js'


export class UserCreated extends eventStore.DomainEvent
{
    private userId : String

    // Just pass whatever data you need in the constructor
    constructor(userId : String)
    {
        // Must call super() first thing in the constructor
        super()
        this.userId = userId
    }

    // Must be implemented from abstract DomainEvent
    get payload()
    {
        return {
            userId:     this.userId,
            occurredOn: this.timestamp // "occuredOn" must be added to the payload object
        }
    }
}

Step 2 - Create a listener:

Create a listener that does whatever action you need when the event is dispatched. Logic should be encapsulated in this class execute() method.

Example:

import * as eventStore from 'event-manager-js'


export class SendEmailListener implements eventStore.ListenerInterface
{
    constructor()
    {
        // Do constructor stuff in here
    }

    execute()
    {
        // Do the logic of the listener in here
    }
}

Step 3 - Register events and listeners in the EventStore:

If you are in a Node project, you could create a new file that holds the registered events and listeners in the event store. Just export the EventStore after registering and import it where you need it.

Example events.ts :

import * as store from 'event-manager-js'
import { SendEmailListener } from './path-to-listeners-folder/SendEmailListener'


let store = new store.EventStore()

let sendEmail = new SendEmailListener() // This class implements ListenerInterface

// Register listener to an Event in the EventStore
store.on('UserCreated', sendEmail)

export default store

Step 4 - Trigger the events:

Trigger the event from some other place in your code.

Example:

import { store } from './path-to-events-file/events.ts'
import { UserCreated } from './path-to-events-folder/UserCreated'

let userEmail = '[email protected]'
let userName = 'Bob Smith'

store.dispatch(new UserCreated(userEmail, userName))