# lite-emit

> A simple, lightweight, and fast event emitter.

Latest version **4.0.0** (published 2025-12-13) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 70/100 (B)** — status: stable.

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2025-12-13 |
| First published | 2022-08-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 12 |
| Author | Ray |
| Maintainers | so1ve |
| Keywords | EventEmitter, EventEmitter2, EventEmitter3, Events, addEventListener, addListener, emit, emits, emitter, event, on, pub/sub, publish, pubsub, reactor, subscribe |

## Links

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

- 4.0.0 (latest) — 2025-12-13
- 3.1.0 — 2025-12-07
- 3.0.0 — 2025-12-06
- 2.3.0 — 2023-08-10
- 2.2.0 — 2023-05-31
- 2.1.0 — 2023-04-22
- 2.0.0 — 2023-04-11
- 1.4.0 — 2022-08-15
- 1.3.1 — 2022-08-15
- 1.3.0 — 2022-08-14
- 1.2.0 — 2022-08-13
- 1.1.2 — 2022-08-12
- 1.1.1 — 2022-08-11
- 1.1.0 — 2022-08-11
- 1.0.0 — 2022-08-10

## README

# lite-emit

[![NPM version](https://img.shields.io/npm/v/lite-emit?color=a1b858&label=)](https://www.npmjs.com/package/lite-emit)

A simple, lightweight, and fast event emitter.

## Usage

```ts
import { LiteEmit } from "lite-emit";

interface Events {
	foo: [string];
	bar: ["bar", number, symbol];
	baz: [42];
}

const emitter = new LiteEmit<Events>();

function fooListener1(str: string) {
	console.log(str);
}

function fooListener2(str: string) {
	console.log(str);
}

function fooListener3(str: string) {
	console.log(str);
}

// Add listeners
emitter.on("foo", fooListener1);
emitter.on("foo", fooListener2);
emitter.on("foo", fooListener3);
emitter.emit("foo", "hello");
emitter.on("baz", (num) => {
	console.log(num);
});
emitter.emit("baz", "42");
// 42

// You can retrieve an `off` function when adding a listener
const offQuxListener2 = emitter.on("qux", (str) => {
	console.log(str);
});
emitter.emit("qux", "hello");
// Output:
// hello
offQuxListener2();
emitter.emit("qux", "hello");
// Output:
// <NONE>

// Remove a specified listener for a specified event
emitter.off("foo", fooListener1);
emitter.emit("foo", "hello");
// Output:
// hello
// hello

// Add wildcard listeners
// Always called on every emit, no matter if the event has listeners or not
emitter.on("*", (event, ...args) => {
	console.log(`Wildcard listener: event=${event}, args=${args}`);
});

// Remove all listeners for a specified event
emitter.off("foo");
// Output:
// <NONE>

emitter.emit("baz", 42);
// Output:
// 42

// Remove all wildcard listeners
emitter.off("*");

// Remove all listeners for all events
emitter.off();
```

## License

[MIT](./LICENSE) License © 2022 [Ray](https://github.com/so1ve)

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