@xyh19/multi-map
v1.0.0
Published
Map which Allow Multiple Values for the same Key
Downloads
3
Readme
🏠 Homepage
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