# emitus

> Small Typescript Event Emitter

Latest version **2.3.2** (published 2018-09-20) · MIT license · 0 weekly downloads

## Install

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

## 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 | 2.3.2 |
| Published | 2018-09-20 |
| First published | 2016-04-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | José Luis Quintana |
| Maintainers | joseluisq |
| Keywords | emitter, event, handler, api, custom, extend |

## Links

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

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

- 2.3.2 (latest) — 2018-09-20
- 2.3.1 — 2018-08-14
- 2.3.0 — 2018-01-29
- 2.2.1 — 2018-01-13
- 2.2.0 — 2018-01-13
- 2.1.0 — 2018-01-13
- 2.0.3 — 2017-07-01
- 2.0.2 — 2017-04-16
- 2.0.1 — 2017-04-16
- 2.0.0 — 2017-04-15
- 1.1.4 — 2017-02-05
- 1.1.3 — 2016-12-06
- 1.1.2 — 2016-12-03
- 1.1.0 — 2016-12-03
- 1.0.9 — 2016-12-03
- … 9 more at https://npm.io/package/emitus/versions

## README

# Emitus [![npm](https://img.shields.io/npm/v/emitus.svg)](https://www.npmjs.com/package/emitus) [![npm](https://img.shields.io/npm/dt/emitus.svg)](https://www.npmjs.com/package/emitus) [![Build Status](https://travis-ci.org/joseluisq/emitus.svg?branch=master)](https://travis-ci.org/joseluisq/emitus) [![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)

> Small [Typescript](https://www.typescriptlang.org/) [Event Emitter](https://nodejs.org/api/events.html). :zap:

__Some differences with Mitt__

[Mitt](https://github.com/developit/mitt) is a pretty cool and very small event emitter library out there, but __Emitus__ differs with it in some aspects such as:

- Emitus has been written and tested entirely in [Typescript](./src/index.ts).
- It uses an array of events instead of a hash.
- It uses a simple `for()` iteration loop with `if()` controls, no map functions or coercion.
- It doesn't support 'emit-all' or some wildcard feature.
- Its size is just `285bytes` minimized + gzipped (UMD) and `844bytes` (CommonJS).

## Install

[Yarn](https://github.com/yarnpkg/)

```sh
yarn add emitus --dev
```

[NPM](https://www.npmjs.com/)

```sh
npm install emitus --save-dev
```

[UMD](https://github.com/umdjs/umd/) file is also available on [unpkg](https://unpkg.com):

```html
<script src="https://unpkg.com/emitus/dist/emitus.umd.min.js"></script>
```

You can also use the library via `window.emitus`.

## Usage

```ts
import { emitus, EmitusListener } from 'emitus'

interface Args { a: number, b: string }

const myArgs: Args = { a: 1, b: '2' }
const myEvent: EmitusListener<Args> = (name, args) => console.log(name, args)

const e = emitus()
e.on('MY_EVENT', myEvent)
e.emit('MY_EVENT', myArgs)
```

## API

### on

Register a custom event listener.

```ts
e.on (eventName: string, listener: EmitusListener): void
```

### off

Unregister a custom event listener.

```ts
e.off (eventName: string, listener?: EmitusListener): void
```

### emit

Calls listener registered for the event named `eventName` passing the supplied (optional) arguments.

```ts
e.emit (eventName: string, args?: any): void
```

## Contributions
Feel free to send some [pull request](https://github.com/joseluisq/emitus/pulls) or [issues](https://github.com/joseluisq/emitus/issues).

## License
MIT license

© 2018 [José Luis Quintana](http://git.io/joseluisq)

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