@zexson/eventmanager
Version:
Shared utilities for Nex framework
101 lines (64 loc) โข 2.49 kB
Markdown
# @zexson/eventmanager
A lightweight, zero-dependency event manager for your JavaScript or TypeScript applications. Designed for simplicity, `NexEventManager` allows you to register, emit, and manage events easily.
--
This package was originally designed by the **Zexson Team** for internal use in their own projects. However, you're welcome to use it freely in your own applications. Contributions and feedback are appreciated.
## ๐ Features
* Register event listeners with `on`
* Register one-time listeners with `once`
* Emit events asynchronously
* Clear specific or all listeners
* TypeScript-ready out of the box
## ๐ฆ Installation
```bash
npm install @zexson/eventmanager
```
## ๐งช Usage
```ts
import { NexEventManager } from '@zexson/eventmanager'
// Register a normal event
NexEventManager.on('startup', () => {
console.log('Application started!')
})
// Register a one-time event
NexEventManager.once('init', () => {
console.log('Initialized once.')
})
// Emit the events
NexEventManager.emit('startup')
NexEventManager.emit('init')
NexEventManager.emit('init') // Won't trigger again
// Clear all listeners
NexEventManager.clear()
// Clear specific event listeners
NexEventManager.clear('startup')
```
## ๐ API
### `NexEventManager.on(event: string, func: (...args: any[]) => any): void`
Registers a persistent event listener.
### `NexEventManager.once(event: string, func: (...args: any[]) => any): void`
Registers a one-time listener that runs once and then auto-removes.
### `NexEventManager.emit(event: string, ...args: any[]): void`
Emits an event asynchronously and calls all matching listeners.
### `NexEventManager.clear(event?: string): void`
Clears all listeners for a specific event or all if no event is specified.
## ๐ง Why use this?
* Perfect for small tools, CLI apps, or custom systems.
* Cleaner than `EventEmitter` if you need minimal async eventing.
* Fully async-friendly and works in both Node.js and browsers.
## ๐ซ Connect with Us
- [Our Website](https://zexson.vercel.app)
- [Our YouTube Channel](https://www.youtube.com/@Signor_P)
- [My GitHub](https://github.com/SignorMassimo)
- [Zexson Team Instagram](https://www.instagram.com/zexsonteam)
- [Contact us for support](https://www.instagram.com/_signor_p_)
## ๐ License
MIT
Made with โค๏ธ for you by Zexson Team.