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

eventemitter-super

v1.0.9

Published

An event emitter/listener tool based on EventEmitter3.

Readme

eventemitter-super

QQ GitHub NPM

English | 简体中文

An event emitter/listener tool based on EventEmitter3.

Setup

Node

npm install --save eventemitter-super

Browser

<script src="./lib/eventemitter-super.umd.js"></script>

Usage

You can use it as a browser global or as a CommonJS/ESM module.

// Browser global
var eventBus = new EventTool.EventEmitterSuper()

// CommonJS
const EventEmitterSuper = require('eventemitter-super')
const bus1 = new EventEmitterSuper()

// ES module
import EventEmitterSuper from 'eventemitter-super'
const bus2 = new EventEmitterSuper()

Examples

// Aliases of common methods:
// bindOnce(once), bind(on), fire(emit), unbind(off), un(off), addOnceListeners(onceEvents)

Example 1 - Return a disposer function

import EventEmitterSuper from 'eventemitter-super'

const eventBus = new EventEmitterSuper()
const destroyEvent = eventBus.on('event1', () => {
  console.log('event1 fired')
})

destroyEvent() // destroy listener

Example 2 - HTML element event listener

const eventBus = new EventEmitterSuper()
const div = document.getElementById('test-div')
const destroyEvent = eventBus.addHtmlListener(div, 'click', () => {})
destroyEvent()

Example 3 - Debounce and throttle listeners

// Debounce
const eventBus = new EventEmitterSuper()
const destroyDebounce = eventBus.onDebounce('event1', function () {
  console.log('event1', arguments)
}, 1000, null)

const timer1 = setInterval(() => {
  eventBus.fire('event1', 1, 2, 3)
}, 100)

setTimeout(() => {
  clearInterval(timer1)
  destroyDebounce()
}, 5000)

// Throttle
const destroyThrottle = eventBus.onThrottle('event2', function () {
  console.log('event2', arguments)
}, 1000, null)

const timer2 = setInterval(() => {
  eventBus.fire('event2', 1, 2, 3)
}, 100)

setTimeout(() => {
  clearInterval(timer2)
  destroyThrottle()
}, 5000)

Example 4 - HTML event debounce and throttle

<body>
  <button id="btn">click me</button>
  <button id="btn2">stop listen</button>
  <script src="./lib/eventemitter-super.umd.js"></script>
  <script>
    const eventBus = new EventTool.EventEmitterSuper()
    const btn = document.getElementById('btn')
    const btn2 = document.getElementById('btn2')

    const destroyBtn = eventBus.onDebounceHtmlEvent(btn, 'click', () => {
      console.log('click btn')
    }, 1000, null)

    eventBus.onHtmlEvent(btn2, 'click', () => {
      destroyBtn()
    }, null)
  </script>
</body>

Example 5 - Wait for multiple events once

const eventBus = new EventEmitterSuper()

eventBus.onceEvents(['event1', 'event2'], () => {
  console.log('event1 and event2')
})

setTimeout(() => eventBus.emit('event2'), 1000)
setTimeout(() => eventBus.emit('event1'), 2000)

Example 6 - Trigger callback after N executions

const eventBus = new EventEmitterSuper()

eventBus.onceByExecCount('test', () => {
  console.log('event emitted')
}, 3)

eventBus.emit('test')
eventBus.emit('test')
eventBus.emit('test')

Example 7 - Max wait time fallback

const eventBus = new EventEmitterSuper()

eventBus.onceWithMaxWaitTime('test', () => {
  console.log('event emitted')
}, 3000)

eventBus.onceEventsWithMaxWaitTime(['test1', 'test2'], () => {
  console.log('event emitted')
}, 3000)

eventBus.onceEventsWithMaxWaitTime(['test1', 'test1'], () => {
  console.log('event emitted')
}, 3000)

Example 8 - Promise wrappers

// Promise wrapper methods
// oncePromise
// onceEventsPromise
// onceByExecCountPromise
// onceWithMaxWaitTimePromise
// onceEventsWithMaxWaitTimePromise

async function test1() {
  const res = await eventBus.oncePromise('test')
  console.log(res)
}

test1()
setTimeout(() => {
  eventBus.emit('test', 'eventobj1', 'eventobj2')
}, 3000)

async function test2() {
  const res = await eventBus.onceWithMaxWaitTimePromise('test1', 3000)
  console.log(res)
}

test2()
setTimeout(() => {
  eventBus.emit('test1', 'eventobj1', 'eventobj1')
}, 1000)

Example 9 - Wait for all listeners with emitPromise

import { EventEmitterSuper } from 'eventemitter-super'

const eventBus = new EventEmitterSuper()

eventBus.on('task', async (id) => {
  await new Promise((resolve) => setTimeout(resolve, 800))
  console.log('async listener done:', id)
})

eventBus.on('task', (id) => {
  console.log('sync listener done:', id)
})

async function run() {
  console.log('before emitPromise')
  await eventBus.emitPromise('task', 1001)
  console.log('after emitPromise')
}

run()

Example 10 - Catch errors from emitPromise

import { EventEmitterSuper } from 'eventemitter-super'

const eventBus = new EventEmitterSuper()

eventBus.on('task', async () => {
  await new Promise((resolve) => setTimeout(resolve, 200))
  throw new Error('listener failed')
})

eventBus.on('task', () => {
  console.log('another listener finished')
})

async function run() {
  try {
    await eventBus.emitPromise('task')
    console.log('all listeners completed')
  } catch (err) {
    console.error('emitPromise failed:', err.message)
  }
}

run()