emitly

0.1.4 • Public • Published

Emitly

A simple event emitter for JavaScript.


Table of Contents

Install

npm:

npm install emitly

Yarn:

yarn add emitly

GitHub:

git clone https://github.com/mazecodes/emitly.git

Usage

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.

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AwesomeFeature)
  3. Commit your changes (git commit -m "Add Awesome Feature")
  4. Push to the branch (git push origin feature/AwesomeFeature)
  5. Open a Pull Request

Author

Maze Peterson:

Show your support

Give a if you liked this project!

License

MIT © Maze Peterson

Package Sidebar

Install

npm i emitly

Weekly Downloads

5

Version

0.1.4

License

MIT

Unpacked Size

13 kB

Total Files

11

Last publish

Collaborators

  • mazecodes