# more-maps

> A collection of additional map-like data structures. Including a bidirectional map, a multi map, and a bidirectional multi map.

Latest version **2.1.0** (published 2023-09-01) · ISC license · 0 weekly downloads

## Install

```sh
npm install more-maps
pnpm add more-maps
yarn add more-maps
bun add more-maps
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2023-09-01 |
| First published | 2023-08-21 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 16.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | maximilianMairinger |
| Maintainers | zzrv |
| Keywords | maps, bidirectional, more, multimap, bidirectional-map, bidirectional-mapping, map, mapping, dict, dictionary, bidirectional-dictionary |

## Links

- npm: https://www.npmjs.com/package/more-maps
- Repository: https://github.com/maximilianMairinger/moreMaps
- Homepage: https://github.com/maximilianMairinger/moreMaps#readme
- Issues: https://github.com/maximilianMairinger/moreMaps/issues
- npm.io page: https://npm.io/package/more-maps

## Dependencies (3)

- [iterare](https://npm.io/package/iterare.md) ^1.2.1
- [key-index](https://npm.io/package/key-index.md) ^1.4.16
- [fast-linked-list](https://npm.io/package/fast-linked-list.md) ^3.2.3

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 2.1.0 (latest) — 2023-09-01
- 2.0.0 — 2023-08-24
- 1.2.2 — 2023-08-23
- 1.2.1 — 2023-08-23
- 1.2.0 — 2023-08-23
- 1.1.1 — 2023-08-23
- 1.1.0 — 2023-08-21
- 1.0.0 — 2023-08-21
- 0.0.1 — 2023-08-21

## README

# More Maps

A collection of additional map-like data structures. Including a bidirectional map, a multi map, and a bidirectional multi map.

## Installation

```shell
 $ npm i more-maps
```

## Usage

### BidirectionalMap

A map that allows bidirectional lookup between keys and values. It extends the built-in `Map` class.

```ts
import { BidirectionalMap } from "more-maps"

const map = new BidirectionalMap<string, number>()

map.set("one", 1)
map.set("two", 2)

console.log(map.get("one")) // 1
console.log(map.reverse.get(2)) // "two"

console.log(map.reverse.reverse === map) // true
```

Be aware that if you set the same value twice to a different key, the second key will overwrite the first one in the reverse map. So make sure they do not conflict. If you want to avoid this, use the BidirectionalMultiMap.


### MultiMap

A map that allows multiple values per key. It stores the values in an array. It provides methods to add, retrieve, and delete values. 

```ts
import { MultiMap } from "more-maps"

const map = new MultiMap<string, number>()

map.add("one", 1)
map.add("one", 2)
map.add("one", 3)
map.add("two", 4)

console.log(map.getAll("one")) // [1, 2, 3]
console.log(map.get("one")) // 1
console.log(map.get("two")) // 4

map.delete("one", 2)
console.log(map.getAll("one")) // [1, 3]

map.delete("one")
console.log(map.getAll("one")) // []
console.log(map.get("one")) // undefined
```

### BidirectionalMultiMap

A bidirectional version of the MultiMap. It allows bidirectional lookup between keys and values, and also supports adding and deleting values.

```ts
import { BidirectionalMultiMap } from "more-maps"

const map = new BidirectionalMultiMap<string, number>()

map.add("one", 1)
map.add("one", 2)
map.add("two", 3)
map.add("three", 2)

console.log(map.getAll("one")) // [1, 2]
console.log(map.reverse.getAll(2)) // ["one", "three"]

map.delete("one", 2)
console.log(map.getAll("one")) // [1]
console.log(map.reverse.getAll(2)) // ["three"]
```

## Contribute

All feedback is appreciated. Create a pull request or write an issue.

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