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

@hypernym/emitter

v3.0.1

Published

A super simple and lightweight event emitter.

Downloads

206

Readme

Features

  • Ultra Lightweight & Powerful
  • Framework Independent
  • Written in TypeScript
  • Native SSR Support
  • No External Dependencies
  • API Friendly

CDN

ESM (minified)

<script type="module">
  import { createEmitter } from 'https://unpkg.com/@hypernym/emitter/dist/index.min.js'
  const emitter = createEmitter()
</script>

IIFE (minified)

<script src="https://unpkg.com/@hypernym/emitter/dist/index.iife.js"></script>
<script>
  const { createEmitter } = Emitter
  const emitter = createEmitter()
</script>

UMD (minified)

<script src="https://unpkg.com/@hypernym/emitter/dist/index.umd.js"></script>
<script>
  const { createEmitter } = Emitter
  const emitter = createEmitter()
</script>

Usage

JS

import { createEmitter } from '@hypernym/emitter'

const emitter = createEmitter()

emitter.on('event-id', (e) => console.log(e.x, e.y))

emitter.emit('event-id', { x: 0, y: 0 })

TS

import { createEmitter } from '@hypernym/emitter'

type Events = {
  'event-id': { x: number; y: number }
  // ...
}

const emitter = createEmitter<Events>()

emitter.on('event-id', (e) => console.log(e.x, e.y))

emitter.emit('event-id', { x: 0, y: 0 })
import { createEmitter, type Emitter } from '@hypernym/emitter'

type Events = {
  'event-id': { x: number; y: number }
  // ...
}

const emitter: Emitter<Events> = createEmitter<Events>()

API

.on()

  • Type: (id: Key, callback: EventCallback<Key, Events>, options?: EventOptions<Options>): () => void

Registers an event listener for a specific event type. Also, supports an optional object param for advanced options logic.

Returns a cleanup function that removes the listener when called.

// Adds scroll listener
const off = emitter.on('scroll', ({ x, y }) => {
  console.log(x, y)
})

// Removes the listener
off()

// Adds scroll listener that will be called only `once`
emitter.on(
  'scroll',
  ({ x, y }) => {
    console.log(x, y)
  },
  { once: true },
)

.off()

Type: (id?: Key, callback?: EventCallback<Key, Events>): void

Removes the registered event listeners.

// Removes all event listeners across all event types
emitter.off()

// Removes all click listeners
emitter.off('click')

// Custom scroll callback
const scrollCallback = ({ x, y }) => {
  console.log(x, y)
}

// Adds specific scroll listener
emitter.on('scroll', scrollCallback)

// Removes specific scroll callback
emitter.off('scroll', scrollCallback)

.get()

  • Type: (id: Key, optionsId: OptionsID): EventDetails<keyof Events, Events, Options> | undefined

Gets specific event details by options.id from the map.

Returns an object { id, callback, options } or undefined if not found.

// Adds scroll event listener with custom options
emitter.on(
  'scroll',
  ({ x, y }) => {
    console.log(x, y)
  },
  { id: 'custom-scroll', a: true, b: false }, // `id` prop can be any string, number or symbol
)

// Gets event details by options.id `custom-scroll`
const details = emitter.get('scroll', 'custom-scroll')

if (details?.options?.a) console.log('run custom logic...')

.emit()

  • Type: (id: Key, event: Events[Key] | ((details: EventDetails<Key, Events, Options>) => void)): void

Emits a specific event.

// Emits scroll event with position data
emitter.emit('scroll', { x: 0, y: 0 })

// Emits event without second parameter
emitter.emit('event-id')

// Emits event only `once`
emitter.emit('event-id', ({ id, callback, options }) => {
  if (options?.once) {
    callback('event-state') // Triggers callback only `once` with event state
    emitter.off(id, callback) // Removes callback from the map
  }
})

// Emits event with custom logic
emitter.emit('scroll', ({ callback, options }) => {
  // Triggers callback with default event state
  callback({ x: 0, y: 0 })

  // Triggers callback with `custom` event state
  if (options?.id === 'custom') callback({ x: 100, y: 100 })
})

.events

  • Type: Map<keyof Events, Map<EventCallback<keyof Events, Events>, EventDetails<keyof Events, Events>>>

Main events map.

Stores all registered events.

emitter.events

.has()

  • Type: (key: keyof Events): boolean

Checks if a specific event by id exists in the map.

emitter.events.has(id: string | symbol)

.get()

  • Type: (key: keyof Events): Map<EventCallback<keyof Events, Events>, EventDetails<keyof Events, Events>> | undefined

Gets a specific event by id from the map.

emitter.events.get(id: string | symbol)

.delete()

  • Type: (key: keyof Events): boolean

Deletes a specific event by id from the map.

emitter.events.delete(id: string | symbol)

.clear()

  • Type: (): void

Removes all events from the map.

emitter.events.clear()

.size

  • Type: number

Indicates the number of registered events in the map.

emitter.events.size

License

Developed in 🇭🇷 Croatia, © Hypernym Studio.

Released under the MIT license.