@xyh19/multi-map
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.0 • Public • Published

    Welcome to multi-map 👋

    Version License: MIT

    🏠 Homepage

    Map which Allow Multiple Values for the same Key

    Getting Started

    import { MultiMap } from '@xyh19/multi-map'
    
    const map = new MultiMap([['a', 'value a1'], ['a', 'value a2'], ['b', 'value b']])
    // 'a' ==> 'value a1', 'value a2'
    // 'b' ==> 'value b'
    
    map.set('a', 'value a3')
    // 'a' ==> 'value a1', 'value a2', 'value a3'
    // 'b' ==> 'value b'
    
    map.get('a')
    // readonly ['value a1', 'value a2', 'value a3']
    
    map.size
    // 2
    
    map.count
    // 4
    
    map.has('b')
    // true
    
    map.hasValue('a', 'value 4')
    // false
    
    map.delete('a', 'value a1')
    // 'a' ==> 'value a2', 'value a3'
    // 'b' ==> 'value b'
    
    map.delete('a')
    // 'b' ==> 'value b'
    
    map.clear()
    // Empty

    types

    declare class MultiMap<K, V> {
        constructor(entries?: Iterable<(readonly [K, V])> | null, unique?: boolean);
        get(key: K): Iterable<V>;
        set(key: K, ...items: V[]): void;
        has(key: K, ...value: [V]): boolean;
        delete(key: K, ...value: [V]): boolean;
        clear(): void;
        keys(): IterableIterator<K>;
        values(): IterableIterator<V>;
        entries(): IterableIterator<[K, V]>;
        [Symbol.iterator](): IterableIterator<[K, V]>;
        readonly size: number;
        readonly count: number;
    }
    declare class MultiWeakMap<K extends object, V> {
        constructor(entries?: Iterable<(readonly [K, V])> | null, unique?: boolean);
        get(key: K): Iterable<V>;
        set(key: K, ...values: V[]): void;
        has(key: K, ...value: [V]): boolean;
        delete(key: K, ...value: [V]): boolean;
    }
    
    export { MultiMap, MultiWeakMap };
    

    🤝 Contributing

    Contributions, issues and feature requests are welcome!
    Feel free to check issues page.

    Show your support

    Give a ⭐️ if this project helped you!


    This README was generated with ❤️ by readme-md-generator

    Install

    npm i @xyh19/multi-map

    DownloadsWeekly Downloads

    2

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    23.2 kB

    Total Files

    8

    Last publish

    Collaborators

    • xyh19