@rizzzse/bimap
    TypeScript icon, indicating that this package has built-in type declarations

    1.2.0 • Public • Published

    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.

    // 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"
    class MyBiMap<K, V> extends BiMap<K, V> {
        declare readonly inverse: MyBiMap<V, K>;
        myMethod() {
            // ...
        }
    }

    Install

    npm i @rizzzse/bimap

    DownloadsWeekly Downloads

    5

    Version

    1.2.0

    License

    MIT

    Unpacked Size

    7.85 kB

    Total Files

    7

    Last publish

    Collaborators

    • rizzzse