0.1.4 • Published 5 years ago
emitly v0.1.4
Table of Contents
Install
npm:
npm install emitlyYarn:
yarn add emitlyGitHub:
git clone https://github.com/mazecodes/emitly.gitUsage
Make an instance:
const Emitly = require('emitly');
const emitly = new Emitly();You can also make Emitly case-insensitive if you want:
const emitly = new Emitly({
caseSensitive: false,
});Listen to an event:
emitly.on('event', message => {
console.log(`Event: ${message}`);
});You can also attach multiple handlers to an event at the same time:
emitly.on(
'event',
() => console.log('Handler 1'),
() => console.log('Handler 2'),
() => console.log('Handler 3')
);Trigger an event:
emitly.emit('event');You can pass multiple values to handlers:
emitly.emit('event', 'Message 1', 'Message 2');Remove a specific event handler:
emitly.off('event', handler);Remove all handlers for an event:
emitly.clear('event');All events
Listen to all events:
emitly.onAll((type, message) => {
console.log(`Event type: ${type}`);
});Trigger all events:
emitly.emitAll();Remove all events:
emitly.clearAll();RegExps
You can listen to RegExps to catch specific events:
emitly.on(/^event/, type => {
console.log(`Event type: ${type}`);
});You can also trigger events with RegExps:
emitly.emit(/foo$/, 'bar');Handlers Category
Handlers have two categories: normal and regex.
You can clear a specific category like this:
emitly.clearAll('normal');Contributing
All contributions, issues and feature requests are welcome! Please feel free to check issues page.
- Fork the project
- Create your feature branch (
git checkout -b feature/AwesomeFeature) - Commit your changes (
git commit -m "Add Awesome Feature") - Push to the branch (
git push origin feature/AwesomeFeature) - Open a Pull Request
Author
Maze Peterson:
Show your support
Give a ⭐ if you liked this project!
License
MIT © Maze Peterson