# tiny-emitter

> A tiny (less than 1k) event emitter library

Latest version **2.1.0** (published 2019-02-05) · MIT license · 0 weekly downloads

## Install

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

## 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 | 2.1.0 |
| Published | 2019-02-05 |
| First published | 2014-01-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 75.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 975 |
| Author | Scott Corgan |
| Maintainers | scottcorgan |
| Keywords | event, emitter, pubsub, tiny, events, bind |

## Links

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

## 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.1.0 (latest) — 2019-02-05
- 2.0.2 — 2017-08-17
- 2.0.1 — 2017-07-05
- 2.0.0 — 2017-04-18
- 1.2.0 — 2017-04-18
- 1.1.0 — 2016-06-29
- 1.0.2 — 2015-12-10
- 1.0.1 — 2015-10-14
- 1.0.0 — 2014-09-16
- 0.1.12 — 2014-01-23
- 0.1.11 — 2014-01-09
- 0.1.10 — 2014-01-09
- 0.1.9 — 2014-01-09
- 0.1.8 — 2014-01-09
- 0.1.7 — 2014-01-06
- … 7 more at https://npm.io/package/tiny-emitter/versions

## README

# tiny-emitter

A tiny (less than 1k) event emitter library.

## Install

### npm

```
npm install tiny-emitter --save
```

## Usage

```js
var Emitter = require('tiny-emitter');
var emitter = new Emitter();

emitter.on('some-event', function (arg1, arg2, arg3) {
 //
});

emitter.emit('some-event', 'arg1 value', 'arg2 value', 'arg3 value');
```

Alternatively, you can skip the initialization step by requiring `tiny-emitter/instance` instead. This pulls in an already initialized emitter.

```js
var emitter = require('tiny-emitter/instance');

emitter.on('some-event', function (arg1, arg2, arg3) {
 //
});

emitter.emit('some-event', 'arg1 value', 'arg2 value', 'arg3 value');
```

## Instance Methods

### on(event, callback[, context])

Subscribe to an event

* `event` - the name of the event to subscribe to
* `callback` - the function to call when event is emitted
* `context` - (OPTIONAL) - the context to bind the event callback to

### once(event, callback[, context])

Subscribe to an event only **once**

* `event` - the name of the event to subscribe to
* `callback` - the function to call when event is emitted
* `context` - (OPTIONAL) - the context to bind the event callback to

### off(event[, callback])

Unsubscribe from an event or all events. If no callback is provided, it unsubscribes you from all events.

* `event` - the name of the event to unsubscribe from
* `callback` - the function used when binding to the event

### emit(event[, arguments...])

Trigger a named event

* `event` - the event name to emit
* `arguments...` - any number of arguments to pass to the event subscribers

## Test and Build

Build (Tests, Browserifies, and minifies)

```
npm install
npm run build
```

Test

```
npm install
npm test
```

## License

[MIT](https://github.com/scottcorgan/tiny-emitter/blob/master/LICENSE)

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