An open API service indexing awesome lists of open source software.

https://github.com/uzmoi/bimap

A simple and tiny bi-directional map that extends ES2015's Map.
https://github.com/uzmoi/bimap

bimap

Last synced: about 2 months ago
JSON representation

A simple and tiny bi-directional map that extends ES2015's Map.

Awesome Lists containing this project

README

        

# bimap

A simple and tiny bi-directional map that extends ES2015's Map.
BiMap can be operated with the same interface as Map, and you can get an inverted BiMap with `inverse`.

```ts
// cjs
const { BiMap, WeakBiMap } = require("@rizzzse/bimap");
// esm
import { BiMap, WeakBiMap } from "@rizzzse/bimap";

const bimap = new BiMap([["key", "value"]]);
bimap.get("key"); // === "value"
bimap.inverse.get("value"); // === "key"

bimap.set("key2", "value");
bimap.has("key"); // === false
bimap.get("key2"); // === "value"
bimap.inverse.get("value"); // === "key2"
```

```ts
class MyBiMap extends BiMap {
declare readonly inverse: MyBiMap;
myMethod() {
// ...
}
}
```