Socket
Socket
Sign inDemoInstall

regexemitter

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    regexemitter

a regex eventemitter wirtten in javascript


Version published
Weekly downloads
47
decreased by-20.34%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Regex event emitter

An event emitter which takes regular expressions for event names

For nodejs

Install

npm install regexemitter --save

NPM

Example

/**
  regexeventemitter behaves just like nodejs native emitter except it
  allows regular expressions as event names.
**/

var EventEmitter = require('regexemitter');
var events = new EventEmitter();

// register a new event
events.on( /send this message to (john|dave)/, function ( arg1, arg2 ){

  console.log( 'event:', this.event );
  console.log( 'message:', arg1, arg2 );

});

events.emit( 'send this message to john', 'hello', 'john' );
events.emit( 'send this message to andy', 'hi', 'andy' );
events.emit( 'send this message to dave', 'ahoy', 'dave' );

Output

event: send this message to john
message: hello john

event: send this message to dave
message: ahoy dave

For the browser

Copy index.js to your web server and rename it regexemitter.js.

Example

<script type="text/javascript" src="regexemitter.js"></script>
<script type="text/javascript">

  /**
    regexeventemitter behaves just like nodejs native emitter except it
    allows regular expressions as event names.
  **/

  var events = new EventEmitter();

  // register a new event
  events.on( /send this message to (john|dave)/, function ( arg1, arg2 ){

    console.log( 'event:', this.event );
    console.log( 'message:', arg1, arg2 );

  });

  events.emit( 'send this message to john', 'hello', 'john' );
  events.emit( 'send this message to andy', 'hi', 'andy' );
  events.emit( 'send this message to dave', 'ahoy', 'dave' );

</script>

Output

event: send this message to john
message: hello john

event: send this message to dave
message: ahoy dave

Build Status

npm test

Build Status

FAQs

Last updated on 21 Jul 2013

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc