# mitt-emitter

> Simple pub/sub

Latest version **1.0.5** (published 2021-05-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install mitt-emitter
pnpm add mitt-emitter
yarn add mitt-emitter
bun add mitt-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 | 1.0.5 |
| Published | 2021-05-02 |
| First published | 2021-05-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 19.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | thiagoanselmo |
| Keywords | events, eventemitter, emitter, pubsub |

## Links

- npm: https://www.npmjs.com/package/mitt-emitter
- Repository: https://github.com/thiagoanselmo/mitt-emitter.git/src/master
- Homepage: https://github.com/thiagoanselmo/mitt-emitter#readme
- Issues: https://github.com/thiagoanselmo/mitt-emitter/issues
- npm.io page: https://npm.io/package/mitt-emitter

## Recent versions

- 1.0.5 (latest) — 2021-05-02
- 1.0.4 — 2021-05-02
- 1.0.3 — 2021-05-02
- 1.0.2 — 2021-05-02
- 1.0.1 — 2021-05-02
- 1.0.0 — 2021-05-02

## README

# mitt-emitter
This is a redesigned package to add the concept of topics like RabbitMQ. You can now use the special characters "*" and "#" to get a topic.

The original package you can find at: https://github.com/developit/mitt - © [Jason Miller]

-   **Familiar:** same names & ideas as [Node's EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter)
-   **Functional:** methods don't rely on `this`
-   **Great Name:** somehow [mitt-emitter](https://npm.im/mitt-emitter) wasn't taken

## Table of Contents

-   [Install](#install)
-   [Usage](#usage)

## Install

This project uses [node](http://nodejs.org) and [npm](https://npmjs.com). Go check them out if you don't have them locally installed.

```sh
$ npm install --save mitt-emitter
```

Then with a module bundler like [rollup](http://rollupjs.org/) or [webpack](https://webpack.js.org/), use as you would anything else:

```javascript
// using ES6 modules
import MittEmitter from 'mitt-emitter'

// using CommonJS modules
var MittEmitter = require('mitt-emitter')
```

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

```html
<script src="https://unpkg.com/mitt-emitter/dist/mitt-emitter.umd.js"></script>
```

## Usage

```js
import MittEmitter from 'mitt-emitter'

const emitter = new MittEmitter();

// listen to an event
emitter.on('foo', e => console.log('foo', e) )

// listen topic event
emitter.on('organization.*.device.1', (type, e) => console.log(type, e) )
emitter.emit('organization.1.device.1', { a: 'b' })

// listen topic event
emitter.on('organization.*.device.*', (type, e) => console.log(type, e) )
emitter.emit('organization.2.device.2', { a: 'b' })

// listen topic event
emitter.on('organization.*.device.#', (type, e) => console.log(type, e) )
emitter.emit('organization.1.device.1.apple.linux', { a: 'b' })

// listen topic event
emitter.on('organization.#', (type, e) => console.log(type, e) )
emitter.emit('organization.1.device.1.apple.linux', { a: 'b' })

// working with handler references:
function onFoo() {}
emitter.on('foo', onFoo)   // listen
emitter.off('foo', onFoo)  // unlisten
```
## License

[MIT License](https://opensource.org/licenses/MIT) © [Thiago Anselmo](https://jasonformat.com/)

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