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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jotter/emitter

v1.1.2

Published

Simple and modern emitter library.

Downloads

35

Readme

EventEmitter

version download license

Simple and modern event emitter library.

一个功能丰富的事件订阅/发布库,方便您在应用程序中实现事件的订阅、发布和取消订阅。

Install

npm

npm install @jotter/emitter

browser

https://cdn.jsdelivr.net/npm/@jotter/emitter/dist/index.global.js

Usage

import EventEmitter from '@jotter/emitter'

const emitter = new EventEmitter()

function handleMessage(arg1, arg2) {
  // ...
  console.log('message 1: ', arg1, arg2)
}

emitter.on('message', handleMessage)

emitter.once('message', function(data) {
  console.log('message 2:', data)
})

emitter.emit('message', 'hello', 'world')
// message 1:  hello world
// message 2:  hello

emitter.off('message', handleMessage)

API

Instance Methods

on

on(type: string | symbol, listener: Function, context?: any): this;

Subscribe to an event

  • type - the name of the event to subscribe to
  • listener - the function to call when event is emitted
  • context - (OPTIONAL) - the context to bind the event callback to

once

once(type: string | symbol, listener: Function, context?: any): this;

Subscribe to an event only once.

  • type - the name of the event to subscribe to
  • listener - the function to call when event is emitted
  • context - (OPTIONAL) - the context to bind the event callback to

emit

emit(type: string | symbol, ...args: any[]): this;

Trigger a named event

  • type - the event name to emit
  • args - any number of arguments to pass to the event subscribers

off

off(type: string | symbol, listener?: Function): this;

Unsubscribe from an event type.
If no listener are provided, it cancels all listeners on that event type.

  • type - the name of the event to unsubscribe from
  • listener - the function used when binding to the event

clear

clear(type?: string | symbol): this;

Unsubscribe from an event or all events.

  • type - the name of the event to unsubscribe from

get

get(type?: string | symbol | '*'): Set<EventHandler> | Map<string | symbol, Set<EventHandler>>;

Get all listeners of the subscribed event type.

  • type - the name of the event to unsubscribe from.
    • If the type is *, return the handler for all subscribed event types.
    • If the type is empty, return the subscribed event Map.

size

size(type?: string | symbol | '*'): number;

Get the number of listeners for the specified event type.

  • type - The event type to get the number of listeners for.
    • If the type is *, return the number of handlers for all subscribed event types.
    • If the type is empty, return the number of subscribed event types.

has

has(type: string | symbol): boolean;

Check the subscribed event type has listener.

  • type - the name of the event to unsubscribe from

Thanks

mitt , tiny-emitter , pico-emitter , emittery