# @libp2p/interfaces

> Common code shared by the various libp2p interfaces

Latest version **3.3.2** (published 2023-05-04) · Apache-2.0 OR MIT license · 0 weekly downloads

## Install

```sh
npm install @libp2p/interfaces
pnpm add @libp2p/interfaces
yarn add @libp2p/interfaces
bun add @libp2p/interfaces
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.3.2 |
| Published | 2023-05-04 |
| First published | 2022-01-04 |
| Weekly downloads | 0 |
| License | Apache-2.0 OR MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=16.0.0 |
| Dependencies | 0 |
| Unpacked size | 30.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 74 |
| Maintainers | jacobheun, npm-service-account-libp2p, alanshaw, vascosantos, achingbrain, daviddias |
| Keywords | interface, libp2p |

## Links

- npm: https://www.npmjs.com/package/@libp2p/interfaces
- Repository: https://github.com/libp2p/js-libp2p-interfaces
- Homepage: https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/interfaces#readme
- Issues: https://github.com/libp2p/js-libp2p-interfaces/issues
- npm.io page: https://npm.io/package/@libp2p/interfaces

## Recent versions

- 3.3.2 (latest) — 2023-05-04
- 3.3.2-d853d124 (next) — 2023-06-19
- 3.3.2-ea8a0637 — 2023-06-19
- 3.3.2-ab0e3980 — 2023-06-19
- 3.3.2-3dfc236e — 2023-06-16
- 3.3.2-8c6b6d24 — 2023-06-15
- 3.3.2-d2f1eff4 — 2023-06-15
- 3.3.2-5a9fb4d6 — 2023-06-15
- 3.3.2-883082ca — 2023-06-15
- 3.3.2-1c6702c8 — 2023-06-15
- 3.3.1 — 2023-01-18
- 3.3.0 — 2023-01-17
- 3.2.0 — 2023-01-03
- 3.1.0 — 2022-12-19
- 3.0.6 — 2022-12-16
- … 56 more at https://npm.io/package/@libp2p/interfaces/versions

## README

# @libp2p/interfaces <!-- omit in toc -->

[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-interfaces.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-interfaces)
[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-interfaces/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-interfaces/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)

> Common code shared by the various libp2p interfaces

## Table of contents <!-- omit in toc -->

- [Install](#install)
- [Usage](#usage)
  - [AbortError](#aborterror)
  - [Events](#events)
  - [AbortOptions](#abortoptions)
  - [Startable](#startable)
- [API Docs](#api-docs)
- [License](#license)
- [Contribution](#contribution)

## Install

```console
$ npm i @libp2p/interfaces
```

## Usage

### AbortError

Throw an error with a `.code` property of `'ABORT_ERR'`:

```js
import { AbortError } from '@libp2p/interfaces/errors'

throw new AbortError()
```

### Events

Typed events:

```js
import { EventEmitter, CustomEvent } from '@libp2p/interfaces/events'

export interface MyEmitterEvents {
  'some-event': CustomEvent<number>;
}

class MyEmitter extends EventEmitter<MyEmitterEvents> {

}

// later
const myEmitter = new MyEmitter()
myEmitter.addEventListener('some-event', (evt) => {
  const num = evt.detail // <-- inferred as number
})
```

### AbortOptions

```js
import type { AbortOptions } from '@libp2p/interfaces'
```

### Startable

Lifecycles for components

```js
import { start, stop, isStartable } from '@libp2p/interfaces/startable'
import type { Startable } from '@libp2p/interfaces/startable'

class MyStartable implements Startable {
  // .. implementation methods
}

const myStartable = new MyStartable()

isStartable(myStartable) // returns true

await start(myStartable)
await stop(myStartable)
```

## API Docs

- <https://libp2p.github.io/js-libp2p-interfaces/modules/_libp2p_interfaces.html>

## License

Licensed under either of

- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)

## Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

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