# swh-event-emitter

> Basic JavaScript event emitter

Latest version **0.0.3** (published 2017-03-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install swh-event-emitter
pnpm add swh-event-emitter
yarn add swh-event-emitter
bun add swh-event-emitter
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2017-03-06 |
| First published | 2017-03-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Sam Weissman-Hohler |
| Maintainers | samweissmanhohler |

## Links

- npm: https://www.npmjs.com/package/swh-event-emitter
- Repository: https://github.com/sweissman59/event-emitter
- Homepage: https://github.com/sweissman59/event-emitter#readme
- Issues: https://github.com/sweissman59/event-emitter/issues
- npm.io page: https://npm.io/package/swh-event-emitter

## Recent versions

- 0.0.3 (latest) — 2017-03-06
- 0.0.2 — 2017-03-06
- 0.0.1 — 2017-03-06

## README

# swh-event-emitter
A simple event emitter package which allows for registering handlers for
events, registering one time handlers, emitting events, and removing handlers.

# Installation
Requires Node 6.4.0 or newer.
```
npm install swh-event-emitter
```

#Usage
```javascript
var EventEmitter = require('swh-event-emitter');

// EventEmitter can be limitted to supported events by providing an
// array of supported event names, and True for the event safe arg.
var emitter = new EventEmitter(['event1', 'event2'], true);

// Should issue a warning for trying to emit an unsupported event.
emitter.emitEvent('unsupportedEvent');

// Should issue a warning for trying to register a handler for an
// unsupported event.
emitter.registerHandler('unsupportedEvent', function(){});

// Should return the array of supported events.
emitter.getEvents();

// Should return True.
emitter.hasEvent('event1');

var handler = function(...rest) {
	console.log('Handler for event1 called with args: ' + JSON.stringify(rest));
}
var handlerBundle = emitter.registerHandler('event1', handler);
emitter.emitEvent('event1', 1, 'foo', {bar: 1}, ['blah', 'hooray']);

// Remove handler using the same event name and handler reference.
emitter.removeHandler('event1', handler);

// The HandlerBundle object returned when registering a handler allows for easy removal
// later without storing the event name, handler function, and emitter separately.
handlerBundle.remove();

// A one time event will be called at most one time. Like normal handlers they can be
// removed at any time.
emitter.registerOneTimeHandler('event1', handler);
emitter.emitEvent('event1', 'test');

// The handler shouldn't be called again here.
emitter.emitEvent('event1', 'test');

// Remove all handlers for a single event.
emitter.removeAllEventHandlers('event1');

// Remove all handlers for all events.
emitter.removeAllHandlers();
```

#Tests
Clone this repository, then from the directory run
```
npm test
```
Test results will print to the console, with additional code coverage information
available in the `coverage` directory.

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