# EventEmitter

> Javascript Event Emitter

Latest version **1.0.0** (published 2016-04-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install EventEmitter
pnpm add EventEmitter
yarn add EventEmitter
bun add EventEmitter
```

## 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.0.0 |
| Published | 2016-04-04 |
| First published | 2016-04-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.12 |
| Dependencies | 6 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 33 |
| Author | Eugene Zlobin |
| Maintainers | zlobin |
| Keywords | event, EventEmitter, javascript, node.js, event driven, on, emit, trigger |

## Links

- npm: https://www.npmjs.com/package/EventEmitter
- Repository: https://github.com/Zlobin/EventEmitter
- Homepage: https://github.com/Zlobin/EventEmitter#readme
- Issues: https://github.com/Zlobin/EventEmitter/issues
- npm.io page: https://npm.io/package/EventEmitter

## Dependencies (6)

- [gulp-size](https://npm.io/package/gulp-size.md) ^2.1.0
- [gulp-babel](https://npm.io/package/gulp-babel.md) ^6.1.2
- [gulp-eslint](https://npm.io/package/gulp-eslint.md) ^2.0.0
- [gulp-rename](https://npm.io/package/gulp-rename.md) ^1.2.2
- [gulp-uglify](https://npm.io/package/gulp-uglify.md) ^1.5.3
- [gulp-sourcemaps](https://npm.io/package/gulp-sourcemaps.md) ^1.6.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.0.0 (latest) — 2016-04-04

## README

# EventEmitter in JavaScript

## Synopsis

EventEmitter is an implementation of the Event-based architecture in JavaScript.

The code is written using the ES2015 approaches, including creation of private property through WeakMap that allows you to not to check for clearing memory, and let it do to the garbage collector.

The module contains the most basic and necessary things: subscription to an event, unsubscribing from the events, running event only once, setting the maximum number of listeners.

The focus is on code readability, speed of execution, getting rid of all the excess.

You can use this library in browser either at the server as within the node.js.

## Dependencies

There are no dependencies. You need only npm installed and just run `npm install` to grab the development dependencies.

## Examples

```javascript
  let EM = new EventEmitter();

  EM.on('foo', () => {
    // some code...
  });

  EM.emit('foo');
```

```javascript
  let EM = new EventEmitter();

  EM.once('foo', () => {
    // some code...
  });

  EM.emit('foo');
```

```javascript
  let EM = new EventEmitter();

  EM.once('foo', (bar, baz) => {
    // some code...
  });

  EM.emit('foo', 'var 1 for bar', 'var 2 for baz');
```

```javascript
  let EM = new EventEmitter();

  EM.on('foo', () => {
    // some code...
  });

  // Note: you can use chaining.
  EM
    .emit('foo')
    .emit('foo')
    .off('foo');
```

```javascript
  // You can set maxNumberOfListeners as a parameter when creating new object.
  let EM = new EventEmitter(1);

  EM.on('foo', () => {
    // some code...
  });
  // Note: it will show notification in console.
  EM.on('foo', () => {
    // some other code...
  });
```

## Testing

Tests are performed using mocha and expect library.

## Building the documentation

You can use JSDoc comments found within the source code.

## Minifying

You can grab minified versions of EventEmitter from /dist path after running `gulp build`.

## Todo

1. Add event's namespace:

```javascript
  EM.on('foo.*', () => {
    // some code...
  });
```

2. Add events through comma:

```javascript
  EM.on('foo,bar,baz', () => {
    // some code...
  });
```

3. Add method "onAny" for listening each event:

```javascript
  EM.onAny(() => {
    // some code...
  });
```

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