<commit_before># event-wire

[![Build Status](https://img.shields.io/travis/nodeca/event-wire/master.svg?style=flat)](https://travis-ci.org/nodeca/event-wire)
[![NPM version](https://img.shields.io/npm/v/event-wire.svg?style=flat)](https://www.npmjs.org/package/event-wire)
[![Coverage Status](https://img.shields.io/coveralls/nodeca/event-wire/master.svg?style=flat)](https://coveralls.io/r/nodeca/event-wire?branch=master)

> Mediator with dynamic responsibility chains.

Idea if this package is to have hybrid of [EventEmitter](http://nodejs.org/api/events.html)
and [chain-of-Responsibility](http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern).
In short - dynamic channels with wildcards, and guaranteed execution order for
listeners.

Features:

- sync & async listeners
- wildards
- exclusions


## Install

```bash
npm install event-wire --save
```

## API


### constructor

```js
var wire = new require('event-wire');
// or
var wire = require('event-wire')();
```

Create new `event-wire` instanse.


### .emit(channels [, obj, callback])

Sends message with `obj` param into the `channels` (String|Array). Once all
sync and ascync handlers finished, optional `callback(err)` (if specified) fired.


### .on(channels [, options], handler)

Registers `handler` to be executed upon messages in the a single channel
or a sequence of channels stored in `channels` parameter. Handler can be
either sync function:

```js
wire.on('foobar', function () {
  // do stuff here
});

wire.on('foobar', function (obj) {
  // do stuff here
});
```

Or it might be an async function with `callback(err)` second argument:

```js
wire.on('foobar', function (obj, callback) {
  // do stuff here
  callback(null);
});
```

Each handler can termitate chain execution by returning not falsy result (error)

Options:<commit_msg>docs update<commit_after># event-wire

[![Build Status](https://img.shields.io/travis/nodeca/event-wire/master.svg?style=flat)](https://travis-ci.org/nodeca/event-wire)
[![NPM version](https://img.shields.io/npm/v/event-wire.svg?style=flat)](https://www.npmjs.org/package/event-wire)
[![Coverage Status](https://img.shields.io/coveralls/nodeca/event-wire/master.svg?style=flat)](https://coveralls.io/r/nodeca/event-wire?branch=master)

> Mediator with dynamic responsibility chains.

Idea if this package is to have hybrid of [EventEmitter](http://nodejs.org/api/events.html)
and [chain-of-Responsibility](http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern).
In short - dynamic channels with wildcards, and guaranteed execution order for
listeners.

Features:

- sync & async listeners
- wildards
- exclusions


## Install

```bash
npm install event-wire --save
```

## API


### constructor

```js
var wire = new require('event-wire');
// or
var wire = require('event-wire')();
```

Create new `event-wire` instanse.


### .emit(channels [, obj, callback])

Sends message with `obj` param into the `channels` (String|Array). Once all
sync and ascync handlers finished, optional `callback(err)` (if specified) fired.


### .on(channels [, options], handler)

Registers `handler` to be executed upon messages in the a single channel
or a sequence of channels stored in `channels` parameter. Handler can be
either sync, async or generator function:

```js
wire.on('foobar', function () {
  // do stuff here
  return new Error('test'); // You can return error
});

wire.on('foobar', function (obj) {
  // do stuff here
});

wire.on('foobar', function (callback) {
  // do stuff here
  callback();
});

wire.on('foobar', function (obj, callback) {
  // do stuff here
  callback();
});

wire.on('foobar', function* (obj) {
  // do stuff here
  yield ...
});
```

Each handler can termitate chain execution by returning not falsy result (error)

Options:
{'fraction_non_alphanumeric': 0.1570597567424643, 'fraction_numerical': 0.0, 'mean_word_length': 4.506550218340611, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 12, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3240833', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1185, 'n_words': 338}