/events

Modern Minimal Typed NodeJS EventEmitter Polyfill

Primary LanguageTypeScriptMIT LicenseMIT

Mirror

This is a Github mirror of this codeberg repo.

This repository is read-only. Please use the above repository for forking, contributing and opening issues.

The original README is attached below for reference purposes. It may be outdated and not reflect the current README.

@3xpo/events

repo image

documentation npm codeberg
mit license mom made pizza mom made pizza
build hopefully succeeded

Installation

pnpm i @3xpo/events

Usage

import EventEmitter from '@3xpo/events';

const emitter = new EventEmitter<{
  event1: (arg1: string, arg2: number) => void;
  event2: (arg1: string) => void;
}>();

emitter.on('event1', (arg1, arg2) => {
  console.log(arg1, arg2);
});

emitter.emit('event1', 'hello', 123);

Note

The EventEmitter is typesafe. If you want a non-typesafe eventemitter, either pass <any> or use NodeEventEmitter.

Note that typesafety is not available in pure JS.