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

hello-events

v5.1.2

Published

A JS events manager.

Readme

HelloEvents

A JS events manager.

Install

npm install --save hello-events

Usage

ES6:

import HelloEvents from 'hello-events'

CommonJS:

const { HelloEvents } = require('hello-events')

AMD:

<script src="./node_modules/hello-events/dist/hello-events.js"></script>
<script>
define(function(require, exports, module) {
  const { HelloEvents } = require('hello-events')
})
</script>

Normal Browsers:

<script src="./node_modules/hello-events/dist/hello-events.js"></script>
<script>
const { HelloEvents } = window['hello-events']
</script>

To use:

const events = new HelloEvents()
events.on('my_event', (e, ...args) => {
  //...
})
//...
events.emit('my_event', arg1, arg2)

API

on(event, callback, priority)

  • event: string, event name
  • callback: function, should be bound function if needed
  • priority: number, the bigger the earlier, default 10
events.on('some_event', (e, name, age) => {
  if (name === 'dota') {
    e.stop()
  }
}, 13)

events.emit('some_event', name, age)

Callback function parameters:

  • e: a object which have some information about current event
    • origin: event name which passed by emit,
    • target: event name which passed by on,
    • priority: event priority,
    • callback: event callback,
    • callback_index: event callback index in callbacks,
    • callbacks_length: callbacks length,
    • stop: function, to stop run other event callbacks,
    • passed_args: args from prev callback,
    • stack: code stack, you can use it for debug,
  • other parameters which passed by emit

event name rules

Use . to concat deep path.

events.on('root.child', fn) // the events which have name begin with 'root.child' will be fired

events.emit('root', data) // this will not fire fn
events.emit('root.child.subchild', data) // this will fire fn

events.on('*', fn) // will be fired when any emit occurs

once(event, callback, priority)

The same as on, callback will only run once, after it is executed, it will be offed.

off(event, callback)

If you do not pass callback, all callbacks of this event will be removed.

Notice: you should must off events' callbacks when you do not need it!!!

emit(event, ...args)

Trigger callback functions of this event by passing parameters.

dispatch(event, ...args)

The same as emit. It is used to callback async functions and return a promise:

events.on('evt', async function f1() {})
events.on('evt', async function f2() {})
events.on('evt', async function f3() {})

await events.dispatch('evt').then(() => { // f1, f2, f3 will run one by one
  // ...
})

For this code block, f2 will run after f1 resolved, f3 is the same will run after f2 resolved. If f1 rejected, f2 and f3 will not run any more.

Notice: callback function can be or not be async function.

broadcast(event, ...args)

The same as dispatch. It is used to callback async functions and return a promise:

events.on('evt', async function f1() {})
events.on('evt', async function f2() {})
events.on('evt', async function f3() {})

await events.broadcast('evt').then(() => { // f1, f2, f3 will run at the same time
  // ...
})

All the callback functions will be run at the same time. Only after all callbacks resolved, the callback in then will run.

Notice: callback function can be or not be async function.

destroy()

Destory the instance. You should must do this if you use namespace.

Passed Arguments

.broadcast will return a array which contains all results of callbacks.

.emit and .dispatch will return the value of last callback. However, you can get the result of each callback during the pipeline by e.passed_args.

evt.on('data', (e, data) => {
  console.log(e.passed_args)  // [0, 'a']      <-------------------------+
  return { a: 'ok' }          // ---------------------+                  |
})                            //                      |                  |
evt.on('data', (e, data) => { //                      |                  |
  console.log(e.passed_args)  // { a: 'ok' }    <-----+                  |
  return 2                    // -----------------------+                |
})                            //                        |                |
let res = await evt.dispatch('data', 0, 'a')  // -------+----------------+
console.log(res)              // 2    <-----------------+