- A powerful EventEmitter module based on Map and Set.
- 🚀 High Performance: Designed for speed and efficiency in event management.
- 🛠️ Easy to Use: Provides intuitive methods for adding, removing, and emitting events.
- 🖥️ Versatile Compatibility: Supports ESM and CJS, ensuring seamless integration with modern JavaScript environments.
Note: Before installation, you need to install 'typescript' globally with the package manager you use.
npm install erffy/erfevents
pnpm add erffy/erfevents
yarn add erffy/erfevents
bun add erffy/erfevents
// TypeScript / ESM
import EventEmitter from 'erfevents';
//
// CJS
const EventEmitter = require('erfevents').default;
//
const ee = new EventEmitter();
ee.on('test', console.log);
ee.emit('test');
ee.on('limitedRun', console.log, 3); // Only emit 3 times
for (let i = 0; i < 5; i++) ee.emit('limitedRun', i);
//
ee.once('runOnce', console.log);
// or
ee.on('runOnce', console.log, 1);
//
function seeDetails() {
console.log('Hello')
}
ee.on('see', seeDetails);
ee.emit('see', 'test');
console.log(seeDetails.emitLimit);
console.log(seeDetails.emitTimes);
console.log(seeDetails.emitted); // or ee.isEmitted(seeDetails)