# event-emitter-object

> A simple event emitter object that you can plug into your javascript libraries.

Latest version **4.0.4** (published 2021-05-25) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

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

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 4.0.4 |
| Published | 2021-05-25 |
| First published | 2019-05-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 75.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Murat Gözel |
| Maintainers | muratgozel |
| Keywords | events, event-emitter, javascript, browser |

## Links

- npm: https://www.npmjs.com/package/event-emitter-object
- Repository: https://github.com/muratgozel/event-emitter-object
- Homepage: https://github.com/muratgozel/event-emitter-object#readme
- Issues: https://github.com/muratgozel/event-emitter-object/issues
- Funding: https://ko-fi.com/muratgozel
- npm.io page: https://npm.io/package/event-emitter-object

## 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

- 4.0.4 (latest) — 2021-05-25
- 4.0.3 — 2021-05-25
- 4.0.2 — 2021-01-10
- 4.0.1 — 2020-12-30
- 4.0.0 — 2020-12-30
- 1.1.4 — 2020-11-22
- 1.1.3 — 2020-06-01
- 1.1.2 — 2020-05-03
- 1.1.1 — 2020-04-29
- 1.1.0 — 2020-04-29
- 1.0.8 — 2020-03-14
- 1.0.7 — 2020-02-04
- 1.0.5 — 2019-11-03
- 1.0.4 — 2019-06-17
- 1.0.3 — 2019-06-17
- … 9 more at https://npm.io/package/event-emitter-object/versions

## README

# Javascript Event Emitter Object
A simple event emitter object that you can plug into your javascript libraries.

![NPM](https://img.shields.io/npm/l/event-emitter-object)
[![npm version](https://badge.fury.io/js/event-emitter-object.svg)](https://badge.fury.io/js/event-emitter-object)
![npm bundle size](https://img.shields.io/bundlephobia/min/event-emitter-object)
![npm](https://img.shields.io/npm/dy/event-emitter-object)

API is very similar to [the node.js events][305ab206].

  [305ab206]: https://nodejs.org/api/events.html "node.js events api"

## Install
```sh
npm install event-emitter-object
```

## Import
There are different types of distributions depending on your use case. Essentially, the package can be imported via require:
```js
const EventEmitterObject = require('event-emitter-object')
```
or via script tag:
```html
<script src="https://cdn.jsdelivr.net/npm/event-emitter-object@4/dist/event-emitter-object.iife.js" crossorigin type="text/javascript"></script>
```
but there are lots of other options. See distribution report below.

## Usage
Simple logger:
```js
const {create} = require('event-emitter-object')

const logger = create()

logger.on('criticalError', function(err) {
  // send log to the server
})

// ... when an error happens:
logger.emit('criticalError', new Error('resourceNotFound'))
```
When arguments and return values matter:
```js
const emailMessages = create()

emailMessages.on('emailMessage', function(recipient, subject, message) {
  // send an email and return the id of the sent message
  return {id: 1}
})

const results = emailMessages.emit('emailMessage', ['sample@example.com', 'Hey', 'Lorem ipsum.'])
// results == [{ok: 1}]
```
Return values are always array because multiple event functions can be attached to the same event:
```js
const emailMessages = create()

emailMessages.on('emailMessage', function(recipient, subject, message) {
  // send an email and return the id of the sent message
  return {id: 1}
})

emailMessages.on('emailMessage', function(recipient, subject, message) {
  return 'ok'
})

const results = emailMessages.emit('emailMessage', ['sample@example.com', 'Hey', 'Lorem ipsum.'])
// results == [{ok: 1}, 'ok']
```
An event that will be invoked by the emitter just once:
```js
const analytics = create()

analytics.on('view', function(id, title) {
  // save visitor and landing page info
  return 'done'
}, {once: true})

analytics.on('view', function(id, title) {
  // send page view to the analytics server
  return 'ok'
})

const results = analytics.emit('view', [1, 'Homepage'])
// results == ['done', 'ok']

const results2 = analytics.emit('view', [2, 'Contact'])
// results2 == ['ok']
```

## Distributions Report

This is an auto-generated report that shows the type, name and size of the bundles available to use individually.

[comment]: # (DISTRIBUTIONS_REPORT_START)
```js
[
  "event-emitter-object.amd.js (1.08 KB)",
  "event-emitter-object.amd.polyfilled.js (10.61 KB)",
  "event-emitter-object.cjs.js (1.08 KB)",
  "event-emitter-object.cjs.polyfilled.js (10.64 KB)",
  "event-emitter-object.es.js (1.06 KB)",
  "event-emitter-object.es.polyfilled.js (10.63 KB)",
  "event-emitter-object.iife.js (1.10 KB)",
  "event-emitter-object.iife.polyfilled.js (10.63 KB)",
  "event-emitter-object.umd.js (1.30 KB)",
  "event-emitter-object.umd.polyfilled.js (10.82 KB)"
]
```
[comment]: # (DISTRIBUTIONS_REPORT_END)

## Babel Polyfills Report

This is an auto-generated report that shows the pollyfils added by core-js based on the targets configuration described below.

[comment]: # (BABEL_POLYFILLS_REPORT_START)
```js
// polyfills:
[]
// based on the targets:
{
  "android": "4.4.3",
  "chrome": "49",
  "edge": "18",
  "firefox": "78",
  "ie": "10",
  "ios": "6",
  "opera": "73",
  "safari": "5.1",
  "samsung": "4"
}
```
[comment]: # (BABEL_POLYFILLS_REPORT_END)

---

Thanks for watching 🐬

[![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/F1F1RFO7)

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