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.
- Host: GitHub
- URL: https://github.com/uzmoi/bimap
- Owner: uzmoi
- License: mit
- Created: 2021-12-16T13:12:36.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-07-19T08:31:45.000Z (almost 3 years ago)
- Last Synced: 2025-03-11T23:35:41.554Z (2 months ago)
- Topics: bimap
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@rizzzse/bimap
- Size: 342 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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() {
// ...
}
}
```