Skip to content

A small and fast event emitter for node.js and browser with wildcards and regular expressions

License

Notifications You must be signed in to change notification settings

Syneware/fancy-events

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fancy Events

A small and fast event emitter for node.js and browser with wildcards and regular expressions

Installing

npm install fancy-events

EventEmitter

Options

  • mode?: 'wildcard' | 'regex' | 'simple' = 'wildcard'
  • includeStack?: boolean = false
  • delimiter?: string = '.'

Methods

  • addListener: (event: string, cb: Function, options?: { once?: boolean; }) => void;
  • on: (event: string, cb: Function) => void;
  • once: (event: string, cb: Function) => void;
  • removeListener: (event: string, listener: Function) => void;
  • off: (event: string, listener: Function) => void;
  • removeAllListeners: (event: string) => void;
  • eventNames: () => string[];
  • listenerCount: (event: string) => number;
  • listeners: (event: string) => Listener[];
  • emit: (event: string, ...params: any) => void;

Example

import EventEmitter from 'fancy-events';
// OR
const EventEmitter = require('fancy-events');

const em = new EventEmitter();

em.on('todo.*', (e, data) => {
    console.log(e, data);
});

//...

em.emit('todo.add', {test: 'data'});

Browser

<script src="https://unpkg.com/fancy-events@1.2.2/dist/fancy-events.min.js"></script>
<script>
    const em = new EventEmitter();

    em.on('todo.*', (e, data) => {
        console.log(e, data);
    });

    //...

    em.emit('todo.add', {test: 'data'});
</script>

About

A small and fast event emitter for node.js and browser with wildcards and regular expressions

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published