⚠️ Warning: The @discordiumjs/emitter package will be released alongside discordium.js and is not currently available on npm. For now, it cannot be downloaded from npm.
✨ A modern, powerful, and lightweight EventEmitter designed for seamless integration with TypeScript projects, built to complement discordium.js.
- 🚀 Optimized: High performance for handling events efficiently.
- 🔒 Type-Safe: Leverages TypeScript to ensure robust and predictable event handling.
- ⚡ Lightweight: Minimal footprint, designed to be fast and easy to use.
Install the package using your favorite package manager:
# npm
npm install @discordiumjs/emitter
# yarn
yarn add @discordiumjs/emitter
# pnpm
pnpm add @discordiumjs/emitter
# bun
bun add @discordiumjs/emitter
Here’s a quick example to get you started:
import { EventEmitter } from "@discordiumjs/emitter";
const emitter = new EventEmitter<{
message: (content: string) => void;
error: (error: Error) => void;
}>();
// Listen for events
emitter.on("message", (content) => {
console.log("Received message:", content);
});
emitter.on("error", (error) => {
console.error("An error occurred:", error);
});
// Emit events
emitter.emit("message", "Hello, world!");
emitter.emit("error", new Error("Something went wrong"));
The EventEmitter
ensures type safety, preventing incorrect event names or parameters:
// TypeScript will throw an error for these:
emitter.emit("unknownEvent", 123); // Error: "unknownEvent" is not defined in the event map.
emitter.on("message", (count: number) => {}); // Error: Parameter type mismatch.
- 💖 Special thanks to all contributors who make this project possible.
- Contributions are welcome! If you have ideas or improvements, feel free to open an issue or submit a pull request on GitHub.
This project is licensed under the GNU GPL 3.0 License.