# @servie/events

> Tiny type-safe event emitter

Latest version **3.0.0** (published 2021-04-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install @servie/events
pnpm add @servie/events
yarn add @servie/events
bun add @servie/events
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2021-04-13 |
| First published | 2019-06-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 20.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 26 |
| Author | Blake Embrey |
| Maintainers | blakeembrey |
| Keywords | events, emitter, types, typescript, micro |

## Links

- npm: https://www.npmjs.com/package/@servie/events
- Repository: https://github.com/serviejs/events
- Issues: https://github.com/serviejs/events/issues
- npm.io page: https://npm.io/package/@servie/events

## 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

- 3.0.0 (latest) — 2021-04-13
- 2.0.1 — 2021-04-09
- 2.0.0 — 2021-04-09
- 1.0.0 — 2019-06-12

## README

# Events

[![NPM version][npm-image]][npm-url]
[![NPM downloads][downloads-image]][downloads-url]
[![Build status][build-image]][build-url]
[![Build coverage][coverage-image]][coverage-url]
[![Bundle size][bundlephobia-image]][bundlephobia-url]

> Tiny type-safe event emitter.

## Installation

```
npm install @servie/events --save
```

## Usage

```ts
import { Emitter, once, ALL_EVENTS } from "@servie/events";

// Define an events interface using keys & argument tuples.
interface Events {
  test: [boolean];
  other: [string];
}

// Initialize an `Emitter` using your `Events` interface.
const events = new Emitter<Events>();

// Add or remove listeners.
const listener = (...args) => console.log(args);
const off = events.on("test", listener);

// Emit an event.
events.emit("test", true);

// Listen to _all_ events, i.e. for debugging.
const eachListener = ({ type, args }) => console.log(type, args);
const off = events.on(ALL_EVENTS, eachListener);

// "Once" utility.
const runOnce = (...args) => console.log(args);
once(events, "test", runOnce);

// Remove the listener.
off();
```

## TypeScript

This project is written using [TypeScript](https://github.com/Microsoft/TypeScript) and publishes the definitions directly to NPM.

## License

MIT

[npm-image]: https://img.shields.io/npm/v/@servie/events
[npm-url]: https://npmjs.org/package/@servie/events
[downloads-image]: https://img.shields.io/npm/dm/@servie/events
[downloads-url]: https://npmjs.org/package/@servie/events
[build-image]: https://img.shields.io/github/workflow/status/serviejs/events/CI/main
[build-url]: https://github.com/serviejs/events/actions/workflows/ci.yml?query=branch%3Amain
[coverage-image]: https://img.shields.io/codecov/c/gh/serviejs/events
[coverage-url]: https://codecov.io/gh/serviejs/events
[bundlephobia-image]: https://img.shields.io/bundlephobia/minzip/@servie/events.svg
[bundlephobia-url]: https://bundlephobia.com/result?p=@servie/events

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