# little-emitter

> A tiny event emitter for node and the browser

Latest version **0.3.5** (published 2020-11-16) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.5 |
| Published | 2020-11-16 |
| First published | 2015-04-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Alex Chao |
| Maintainers | alexchao |
| Keywords | event, emitter, eventemitter |

## Links

- npm: https://www.npmjs.com/package/little-emitter
- Repository: https://github.com/Alex1990/little-emitter
- Homepage: https://github.com/Alex1990/little-emitter#readme
- Issues: https://github.com/Alex1990/little-emitter/issues
- npm.io page: https://npm.io/package/little-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

- 0.3.5 (latest) — 2020-11-16
- 0.3.4 — 2019-06-30
- 0.3.3 — 2019-06-30
- 0.3.2 — 2019-06-23
- 0.3.1 — 2019-06-23
- 0.3.0 — 2019-06-23
- 0.2.0 — 2018-12-20
- 0.1.4 — 2018-12-20
- 0.1.3 — 2015-06-19
- 0.1.2 — 2015-04-17
- 0.1.1 — 2015-04-17
- 0.1.0 — 2015-04-17

## README

# little-emitter

[![Build Status](https://travis-ci.org/Alex1990/little-emitter.svg?branch=master)](https://travis-ci.org/Alex1990/little-emitter)
[![npm](https://img.shields.io/npm/v/little-emitter.svg)](https://www.npmjs.com/package/little-emitter)

A tiny event emitter for node and the browser.

## Install

```bash
npm install little-emitter --save
```

## Usage

The little-emitter can be as a CommonJS/AMD module or a method on global object, such as `window` in browser.

**Node:**

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

emitter.on('init', function(){ console.log('init'); });
emitter.emit('init'); // "init"
emitter.off('init');
```
**Browser:**

```js
var emitter = new Emitter();
```

It can be as a mixin:

```js
var foo = { name: 'Foo' };
Emitter(foo);
// Or
// new Emitter(foo);
// foo = new Emitter(foo);

foo.on('say', function(){ console.log(this.name); });
foo.emit('say'); // "Foo"
```

## API

The `Emitter` instance methods:

### on(type, fn)

**Alias:** `addEventListener`

Attach a listener to the emitter.

### once(type, fn)

**Alias:** `one`

Attach a listener which is executed at most once.

### off(type, fn)

**Alias:** `removeEventListener`/`removeAllListeners`

- If nothing is passed, all listeners will be removed.
- If only the `type` parameter is passed, the given type listeners will be removed.
- If the `type` and `fn` are specified, the earliest bound listener for the given type will be removed.

### emit(type, [arg1], [arg2], ...)

**Alias:** `trigger`

Emit the specified type event and pass some arguments to the listener optionally.

### getListeners(type)

**Alias:** `listeners`

Return the given type listeners or all listeners or an empty array.

## License

MIT.

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