# @socket.io/component-emitter

> Event emitter

Latest version **3.1.2** (published 2024-04-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install @socket.io/component-emitter
pnpm add @socket.io/component-emitter
yarn add @socket.io/component-emitter
bun add @socket.io/component-emitter
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.2 |
| Published | 2024-04-26 |
| First published | 2021-10-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 20.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Maintainers | darrachequesne |

## Links

- npm: https://www.npmjs.com/package/@socket.io/component-emitter
- Repository: https://github.com/socketio/emitter
- Homepage: https://github.com/socketio/emitter#readme
- Issues: https://github.com/socketio/emitter/issues
- npm.io page: https://npm.io/package/@socket.io/component-emitter

## Recent versions

- 3.1.2 (latest) — 2024-04-26
- 3.1.1 — 2024-04-10
- 4.0.0 — 2022-11-22
- 3.1.0 — 2022-04-17
- 3.0.0 — 2021-10-14
- 2.0.0 — 2021-10-04

## README

# `@socket.io/component-emitter`

  Event emitter component.

This project is a fork of the [`component-emitter`](https://github.com/sindresorhus/component-emitter) project, with [Socket.IO](https://socket.io/)-specific TypeScript typings.

## Installation

```
$ npm i @socket.io/component-emitter
```

## API

### Emitter(obj)

  The `Emitter` may also be used as a mixin. For example
  a "plain" object may become an emitter, or you may
  extend an existing prototype.

  As an `Emitter` instance:

```js
import { Emitter } from '@socket.io/component-emitter';

var emitter = new Emitter;
emitter.emit('something');
```

  As a mixin:

```js
import { Emitter } from '@socket.io/component-emitter';

var user = { name: 'tobi' };
Emitter(user);

user.emit('im a user');
```

  As a prototype mixin:

```js
import { Emitter } from '@socket.io/component-emitter';

Emitter(User.prototype);
```

### Emitter#on(event, fn)

  Register an `event` handler `fn`.

### Emitter#once(event, fn)

  Register a single-shot `event` handler `fn`,
  removed immediately after it is invoked the
  first time.

### Emitter#off(event, fn)

  * Pass `event` and `fn` to remove a listener.
  * Pass `event` to remove all listeners on that event.
  * Pass nothing to remove all listeners on all events.

### Emitter#emit(event, ...)

  Emit an `event` with variable option args.

### Emitter#listeners(event)

  Return an array of callbacks, or an empty array.

### Emitter#hasListeners(event)

  Check if this emitter has `event` handlers.

## License

MIT

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