@xyh19/multi-map
Version:
Map which Allow Multiple Values for the same Key
90 lines (67 loc) • 2.31 kB
Markdown
<h1 align="center">Welcome to multi-map 👋</h1>
<p>
<img alt="Version" src="https://img.shields.io/badge/version-1.0.0-blue.svg?cacheSeconds=2592000" />
<a href="#" target="_blank">
<img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-yellow.svg" />
</a>
</p>
### 🏠 [Homepage](https://gitee.com/xxXyh1908/multi-map/#readme)
<h2>Map which Allow Multiple Values for the same Key</h2>
## Getting Started
```js
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
```ts
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!<br />Feel free to check [issues page](https://gitee.com/xxXyh1908/multi-map/issues).
## Show your support
Give a ⭐️ if this project helped you!
***
_This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_