# tap-map

> A better Map with .tap()

Latest version **1.0.0** (published 2019-09-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install tap-map
pnpm add tap-map
yarn add tap-map
bun add tap-map
```

## 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.0.0 |
| Published | 2019-09-27 |
| First published | 2019-09-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Shawn Allen |
| Maintainers | shawnbot |
| Keywords | map, tap |

## Links

- npm: https://www.npmjs.com/package/tap-map
- npm.io page: https://npm.io/package/tap-map

## Alternatives

- [ext-list](https://npm.io/package/ext-list.md) — 6.3M weekly downloads
- [@lexical/selection](https://npm.io/package/@lexical/selection.md) — 3.8M weekly downloads
- [@lexical/text](https://npm.io/package/@lexical/text.md) — 3.6M weekly downloads
- [@lexical/clipboard](https://npm.io/package/@lexical/clipboard.md) — 3.0M weekly downloads
- [@tiptap/extension-mention](https://npm.io/package/@tiptap/extension-mention.md) — 3.0M weekly downloads

## Recent versions

- 1.0.0 (latest) — 2019-09-27

## README

# TapMap
The TapMap class extends JavaScript's native [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) with a single, powerful method:

```js
const map = new TapMap()
// "set the key 'foo' to 'bar' if 'foo' is not set"
map.tap('foo', 'bar')       // 'bar'
map.get('foo')              // 'bar'

// "set the key 'foo' to `Math.random()` if 'foo' is not set"
map.tap('foo', Math.random) // 'bar' (already set)
map.tap('bar', Math.random) // 0.3144890857392...
```

The default factory function returns a `new TapMap`, so you can
use it to quickly build and then query deep structures:

```js
const map = new TapMap()
map.tap(1).tap(2).tap(3, '!') // '!'
map.get(1).get(2)             // TapMap({3: '!'})
```

...or you can provide your own factory:

```js
const map = new TapMap()
const values = ['foo', 'bar', 'foo', 'baz']
// it's better not to define this in the loop
const makeList = () => []
for (const [index, value] of Object.entries(values)) {
  map.tap(value, makeList).push(index)
}
for (const [value, indices] of map.entries()) {
  console.log(`${value}: ${indices.join(', ')}`)
}
```

## Install
```
npm install tap-map
```

## Usage
```js
const TapMap = require('tap-map')
const map = new TapMap()
// do your worst
```

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