# emitter-listener

> (Meta)observability for EventEmitters.

Latest version **1.1.2** (published 2018-10-06) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install emitter-listener
pnpm add emitter-listener
yarn add emitter-listener
bun add emitter-listener
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2018-10-06 |
| First published | 2013-11-30 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 12.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Forrest L Norvell |
| Maintainers | othiym23 |
| Keywords | wow, such, introspection, amaze, listener, so, observe |

## Links

- npm: https://www.npmjs.com/package/emitter-listener
- Repository: https://github.com/othiym23/emitter-listener
- Issues: https://github.com/othiym23/emitter-listener/issues
- npm.io page: https://npm.io/package/emitter-listener

## Dependencies (1)

- [shimmer](https://npm.io/package/shimmer.md) ^1.2.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.1.2 (latest) — 2018-10-06
- 1.1.1 — 2017-11-20
- 1.1.0 — 2017-11-20
- 1.0.1 — 2013-12-07
- 1.0.0 — 2013-11-30

## README

## Add dynamic instrumentation to emitters

`shimmer` does a bunch of the work necessary to wrap other methods in
a wrapper you provide:

```javascript
var EventEmitter = require('events').EventEmitter;
var wrapEmitter = require('emitter-listener');

var ee = new EventEmitter();

var id = 0;

wrapEmitter(
  ee,
  function mark(listener) {
    listener.id = id++;
  },
  function prepare(listener) {
    console.log('listener id is %d', listener.id);
  }
);
```

### Mandatory disclaimer

There are times when it's necessary to monkeypatch default behavior in
JavaScript and Node. However, changing the behavior of the runtime on the fly
is rarely a good idea, and you should be using this module because you need to,
not because it seems like fun.

#### wrapEmitter(emitter, mark, prepare)

Wrap an EventEmitter's event listeners. Each listener will be passed to
`mark` when it is registered with `.addListener()` or `.on()`, and then
each listener is passed to `prepare` to be wrapped before it's called
by the `.emit()` call. `wrapListener` deals with the single listener
vs array of listeners logic, and also ensures that edge cases like
`.removeListener()` being called from within an `.emit()` for the same
event type is handled properly.

The wrapped EE can be restored to its pristine state by using
emitter.__unwrap(), but this should only be used if you *really* know
what you're doing.

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