# namespace-emitter

> tiny event emitter with namespaces

Latest version **2.0.1** (published 2018-01-30) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2018-01-30 |
| First published | 2015-12-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/namespace-emitter) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 15 |
| Author | sethvincent |
| Maintainers | sethvincent |
| Keywords | eventemitter, events, namespaces |

## Links

- npm: https://www.npmjs.com/package/namespace-emitter
- Repository: https://github.com/sethvincent/namespace-emitter
- Homepage: https://github.com/sethvincent/namespace-emitter#readme
- Issues: https://github.com/sethvincent/namespace-emitter/issues
- npm.io page: https://npm.io/package/namespace-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.0.1 (latest) — 2018-01-30
- 2.0.0 — 2017-07-21
- 1.0.0 — 2015-12-23

## README

# namespace-emitter

A small event emitter with namespaces.

Not meant as a replacement for node's events module, but as a small component for browser js.

## Install

    npm install --save namespace-emitter

## Example

```js
var emitter = require('namespace-emitter')()

emitter.on('*', function () {
  console.log('all events emitted', this.event)
})

emitter.on('example', function () {
  console.log('example event emitted')
})

emitter.emit('example')
// -> example event emitted
// -> all events emitted example

emitter.on('demo', function () {
  console.log('multiple events with `demo` namespace emitted', this.event)
})

emitter.emit('demo:cool')
// -> all events emitted demo:cool
// -> multiple events with `demo` namespace emitted demo:cool

emitter.emit('demo:awesome')
// -> all events emitted demo:awesome
// -> multiple events with `demo` namespace emitted demo:awesome

emitter.emit('demo:great')
// -> all events emitted demo:great
// -> multiple events with `demo` namespace emitted demo:great
```

## API

### createNamespaceEmitter

Create an event emitter with namespaces

**Examples**

```javascript
var emitter = require('./index')()

emitter.on('*', function () {
  console.log('all events emitted', this.event)
})

emitter.on('example', function () {
  console.log('example event emitted')
})
```

### emit

Emit an event. Optionally namespace the event. Handlers are fired in the order in which they were added with exact matches taking precedence. Separate the namespace and event with a `:`

**Parameters**

-   `event` **String** – the name of the event, with optional namespace
-   `data` **...Any** – data variables that will be passed as arguments to the event listener

**Examples**

```javascript
emitter.emit('example')
emitter.emit('demo:test')
emitter.emit('data', { example: true}, 'a string', 1)
```

### off

Stop listening to an event. Stop all listeners on an event by only passing the event name. Stop a single listener by passing that event handler as a callback.
You must be explicit about what will be unsubscribed: `emitter.off('demo')` will unsubscribe an `emitter.on('demo')` listener, 
`emitter.off('demo:example')` will unsubscribe an `emitter.on('demo:example')` listener

**Parameters**

-   `event` **String** 
-   `fn` **[Function]** – the specific handler

**Examples**

```javascript
emitter.off('example')
emitter.off('demo', function () {})
```

### on

Create en event listener.

**Parameters**

-   `event` **String** 
-   `fn` **Function** 

**Examples**

```javascript
emitter.on('example', function () {})
emitter.on('demo', function () {})
```

### once

Create en event listener that fires once.

**Parameters**

-   `event` **String** 
-   `fn` **Function** 

**Examples**

```javascript
emitter.once('example', function () {})
emitter.once('demo', function () {})
```

## License

[MIT](LICENSE.md)

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