# tiny-emit

> Another event emitter, only tiny.

Latest version **0.2.0** (published 2017-03-13) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2017-03-13 |
| First published | 2017-03-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Christopher Turner |
| Maintainers | tur-nr |
| Keywords | event, emitter, emit, on, once, off |

## Links

- npm: https://www.npmjs.com/package/tiny-emit
- Repository: https://github.com/tur-nr/node-tiny-emit
- Homepage: https://github.com/tur-nr/node-tiny-emit#readme
- Issues: https://github.com/tur-nr/node-tiny-emit/issues
- npm.io page: https://npm.io/package/tiny-emit

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

- 0.2.0 (latest) — 2017-03-13

## README

# tiny-emit

![Dependencies Status](https://david-dm.org/tur-nr/node-tiny-emit.svg)
[![Build Status](https://travis-ci.org/tur-nr/node-tiny-emit.svg?branch=master)](https://travis-ci.org/tur-nr/node-tiny-emit)
[![Coverage Status](https://coveralls.io/repos/github/tur-nr/node-tiny-emit/badge.svg?branch=master)](https://coveralls.io/github/tur-nr/node-tiny-emit?branch=master)
[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)


Another event emitter, only tiny.

## Install

_Yarn_

```sh
yarn add tiny-emit
```

_NPM_

```sh
npm install --save-dev tiny-emit
```

## Usage

```javascript
import tiny from 'tiny-emit';

const emitter = tiny();

emitter.on('foo', (bar) => {
    console.log(bar); // bar
});

emitter.emit('foo', 'bar');
```

### Once

```javascript
let i = 0;

emitter.once('incr', () => (i += 1));

emitter.emit('incr');
emitter.emit('incr');

console.log(i); // 1
```

### Off

There is many ways to switch off a listener for an event. Call the listeners off function returned whenever the listener was added. This works for both `.on()` and `.once()` methods.

```javascript
const off = emitter.on('foo', () => {});
off();
```

Or use the `.off()` method on the emitter.

```javascript
emitter.off('foo', listener); // specific event and listener
emitter.off('foo');           // all listeners for given event
emitter.off();                // every listener for every event
```

## API

#### `#tiny()`

_Returns an emitter object._

### Emitter Object

#### `.on(<event>, <fn>)`

- `event` _String_ The event name.
- `fn` _Function_ The listener function.

_Returns an off Function._

#### `.once(<event>, <fn>)`

- `event` _String_ The event name.
- `fn` _Function_ The listener function.

_Returns an off Function._

#### `.off([event, [fn]])`

- `event` _String_ The event name.
- `fn` _Function_ The listener function.

_Returns void._

#### `.emit(<event>, [...args])`

- `event` _String_ The event name.
- `...args` _Any_ Optional arguments to pass.

_Returns void._

## License

[MIT](LICENSE)

Copyright (c) 2017 [Christopher Turner](https://github.com/tur-nr)

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