# simple-listen

> Utility for adding event listeners with simple unsubscribing

Latest version **1.1.2** (published 2016-10-02) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install simple-listen
pnpm add simple-listen
yarn add simple-listen
bun add simple-listen
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2016-10-02 |
| First published | 2016-03-22 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Kye Hohenberger |
| Maintainers | tkh44 |
| Keywords | es6, event, listener, event listener, browser, listen |

## Links

- npm: https://www.npmjs.com/package/simple-listen
- Repository: https://github.com/tkh44/simple-listen
- Homepage: https://github.com/tkh44/simple-listen#readme
- Issues: https://github.com/tkh44/simple-listen/issues
- npm.io page: https://npm.io/package/simple-listen

## Recent versions

- 1.1.2 (latest) — 2016-10-02
- 1.1.0 — 2016-07-12
- 1.0.1 — 2016-05-26
- 1.0.0 — 2016-05-26
- 0.1.0 — 2016-03-28
- 0.0.4 — 2016-03-23
- 0.0.3 — 2016-03-22

## README

# Simple Listen

Small utility for adding event listeners that returns the listener for easy unsubscribing

## Installation

```
$ npm install simple-listen
```

##API

###`listen(el, events, cb, capture, context)`

- `el` - the DOM element you are attaching events to
- `events` - [string|array[string]] - the event types to attach
- `cb` - [function] - the function to call when event fires
- `capture` - [boolean] - `false` - use capture
- `context` - [object] - `null` - the context applied to `cb`

## Example

```js
import listen from 'simple-listen';

const el = document.getElementById('clickable');
const callback = (e) => console.log(e.type);

const myListener = listen(el, 'click mouseenter mouseleave', callback);
myListener(); // remove event listener

// Multiple listeners
const listeners = [];
listeners.push(listen(el, 'click', callback));
listeners.push(listen(el, 'mouseenter', callback));
listeners.push(listen(el, 'mouseleave', callback));
listeners.push(listen(window, 'scroll', callback));
listeners.push(listen(window, 'resize', callback));

// quickly remove the event listeners
listeners.forEach((listener) => listener());
```

# License

Modified BSD

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