Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vilicvane/multikey-map
https://github.com/vilicvane/multikey-map
Last synced: 20 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/vilicvane/multikey-map
- Owner: vilicvane
- License: mit
- Created: 2017-08-21T09:15:01.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-02-18T10:30:03.000Z (10 months ago)
- Last Synced: 2024-11-24T22:32:55.724Z (29 days ago)
- Language: TypeScript
- Size: 261 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![NPM version](https://img.shields.io/npm/v/multikey-map?color=%23cb3837&style=flat-square)](https://www.npmjs.com/package/multikey-map)
[![Repository package.json version](https://img.shields.io/github/package-json/v/vilicvane/multikey-map?color=%230969da&label=repo&style=flat-square)](./package.json)
[![MIT License](https://img.shields.io/badge/license-MIT-999999?style=flat-square)](./LICENSE)
[![Discord](https://img.shields.io/badge/chat-discord-5662f6?style=flat-square)](https://discord.gg/wEVn2qcf8h)# Multikey Map
A simple map implementation that supports multiple keys.
> `multikey-map` uses `mixed-map` internally, which is a map implementation that uses both `Map` and `WeakMap` internally.
## Installation
```sh
npm install multikey-map
```## Usage
```ts
import MultikeyMap from 'multikey-map';let map = new MultikeyMap<[string, number], string | undefined>();
map.set(['foo', 0], 'a');
map.set(['foo', 1], 'b');map.get(['foo', 0]); // 'a'
map.get(['foo', 1]); // 'b'
map.get(['foo', 2]); // undefined
map.has(['foo', 2]); // false
map.hasAndGet(['foo', 2]); // [false, undefined]map.set(['bar', 0], undefined);
map.get(['bar', 0]); // undefined
map.has(['bar', 0]); // true
map.hasAndGet(['bar', 0]); // [true, undefined]
```## License
MIT License.