# nomatic-events

> Fast, asynchronous, and regex-enabled event framework for Node.js

Latest version **3.0.0** (published 2017-11-27) · ISC license · 0 weekly downloads

## Install

```sh
npm install nomatic-events
pnpm add nomatic-events
yarn add nomatic-events
bun add nomatic-events
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2017-11-27 |
| First published | 2016-09-09 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Brian D. Foster |
| Maintainers | bdfoster |
| Keywords | EventEmitter, EventListener, event, events, emitter, listener, nomatic-lib, nomatic, observer, pattern, typescript |

## Links

- npm: https://www.npmjs.com/package/nomatic-events
- Repository: https://github.com/bdfoster/nomatic-events
- Homepage: https://github.com/bdfoster/nomatic-events#readme
- Issues: https://github.com/bdfoster/nomatic-events/issues
- npm.io page: https://npm.io/package/nomatic-events

## Dependencies (1)

- [@types/node](https://npm.io/package/@types/node.md) ^8.0.0

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 3.0.0 (latest) — 2017-11-27
- 2.2.1 — 2017-11-21
- 2.1.1 — 2017-07-08
- 2.1.0 — 2017-07-03
- 2.0.1 — 2017-07-03
- 2.0.0 — 2017-03-27
- 2.0.0-alpha.2 — 2017-03-27
- 2.0.0-alpha.1 — 2017-03-27
- 2.0.0-alpha.0 — 2017-03-27
- 1.1.1 — 2017-03-27
- 1.1.0 — 2017-03-27
- 1.0.4 — 2017-03-27
- 1.0.3 — 2016-12-09
- 1.0.2 — 2016-11-30
- 1.0.1 — 2016-11-29
- … 14 more at https://npm.io/package/nomatic-events/versions

## README

# nomatic-events
[![Greenkeeper](https://badges.greenkeeper.io/bdfoster/nomatic-events.svg)](https://greenkeeper.io/)
[![GitHub Release](https://img.shields.io/github/release/bdfoster/nomatic-events.svg)](https://github.com/bdfoster/nomatic-events/releases)
[![npm](https://img.shields.io/npm/v/nomatic-events.svg)](https://www.npmjs.com/package/nomatic-events)
[![Build Status](https://img.shields.io/travis/bdfoster/nomatic-events/master.svg)](https://travis-ci.org/bdfoster/nomatic-events)
[![Coverage Status](https://img.shields.io/coveralls/bdfoster/nomatic-events/master.svg)](https://coveralls.io/github/bdfoster/nomatic-events)
[![Known Vulnerabilities](https://snyk.io/test/github/bdfoster/nomatic-events/badge.svg)](https://snyk.io/test/github/bdfoster/nomatic-events)
[![dependencies Status](https://img.shields.io/david/bdfoster/nomatic-events.svg)](https://david-dm.org/bdfoster/nomatic-events)
[![devDependencies Status](https://img.shields.io/david/dev/bdfoster/nomatic-events.svg)](https://david-dm.org/bdfoster/nomatic-events?type=dev)
[![License](https://img.shields.io/github/license/bdfoster/nomatic-events.svg)](https://github.com/bdfoster/nomatic-events/blob/master/LICENSE)

## Installation

You can install from NPM by doing:
```
npm install --save nomatic-events
```

## Usage

### Basic

```javascript
var events = require("nomatic-events");
var EventEmitter = events.EventEmitter;
var emitter = new EventEmitter();

// Supports RegExp for listeners 
var listener = emitter.on(/incoming/i, function(data) {
  console.log("data is now " + data); 
});
// `listener` is an EventListener, but you do not have to capture this.
 
emitter.emit("INCOMING", 42);
```

### Advanced
```javascript
class EventedObject extends EventEmitter {
    constructor() {
        // Call EventEmitter, set maxListeners to 20
        super(20);
        
        this.listenerExecuted = true;
    }
    
    handleIncoming(some, option, or, another) {
        // Variadic arguments supported
        this.emit("INCOMING", some, option, or, another);
    }
}

let evented = new EventedObject();
// Don't have to take every argument supplied by `emit`
evented.on(/IN/, function(some, option, or) {
    console.log(this);
    if (this.listeners) {
        console.log(some, option, or);
        this.listenerExecuted = true;
    } else {
        console.log("Bad context");
    }
});

evented.handleIncoming("See no evil", "Hear no evil", "Speak no evil", 42);
// "See no evil"
// "Hear no evil"
// "Speak no evil"
```

## Async
You can also use `AsyncEventEmitter` and `AsyncEventListener` to handle Promise-based callbacks.
### Example
```javascript
var events = require("nomatic-events");
var AsyncEventEmitter = events.AsyncEventEmitter;
var emitter = new AsyncEventEmitter();
var fs = require('fs');
var files = null;
var listener = emitter.on(/incoming/i, function(data) {
    return new Promise((resolve, reject) => {
        fs.readdir(__dirname, (err, list) => {
            if (err) reject(err);
            files = list;
            resolve();
        });
    })
});
// `listener` is an AsyncEventListener, but you do not have to capture this.
 
// Executed asynchronously 
emitter.emit("INCOMING", 42).then(() => {
    // 'files' isn't null!
    console.log(files);
});
// 'files' will still be null until promise resolves
```

## Testing
Pride is taken when developing tests, you can find unit tests for both EventEmitter and EventListener
[here](test/unit).

## TypeScript
This package is written in TypeScript and declaration files are added to the NPM package.
However, you do not even need to know what TypeScript is in order to use this package,
let alone install the compiler. NPM packages include the compiled project.

---
_Source: https://npm.io/package/nomatic-events · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
