# multimap

> multi-map which allow multiple values for the same key

Latest version **1.1.0** (published 2019-11-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install multimap
pnpm add multimap
yarn add multimap
bun add multimap
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2019-11-12 |
| First published | 2014-07-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/multimap) |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 16 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 17 |
| Author | villa.gao |
| Maintainers | korynunn, villadora |
| Keywords | keys, map, multiple |

## Links

- npm: https://www.npmjs.com/package/multimap
- Repository: https://github.com/villadora/multi-map
- Homepage: https://github.com/villadora/multi-map#readme
- Issues: https://github.com/villadora/multi-map/issues
- npm.io page: https://npm.io/package/multimap

## Recent versions

- 1.1.0 (latest) — 2019-11-12
- 1.0.2 — 2016-03-10
- 1.0.1 — 2015-09-23
- 1.0.0 — 2015-09-18
- 0.1.1 — 2014-12-19
- 0.1.0 — 2014-08-27
- 0.0.2 — 2014-07-16
- 0.0.1 — 2014-07-16

## README

# Multimap - Map which Allow Multiple Values for the same Key

[![NPM version](https://badge.fury.io/js/multimap.svg)](http://badge.fury.io/js/multimap)
[![Build Status](https://travis-ci.org/villadora/multi-map.png?branch=master)](https://travis-ci.org/villadora/multi-map)

## Install

```bash
npm install multimap --save
```

## Usage


If you'd like to use native version when it exists and fallback to polyfill if it doesn't, but without implementing `Map` on global scope, do:

```javascript
var Multimap = require('multimap');
var m = new Multimap();
```

If the global es6 `Map` exists or `Multimap.Map` is set, `Multimap` will use the `Map` as inner store, that means Object can be used as key.

```javascript
var Multimap = require('multimap');

// if harmony is on
/* nothing need to do */
// or if you are using es6-shim
Multimap.Map = ShimMap;

var m = new Multimap();
var key = {};
m.set(key, 'one');

```

Otherwise, an object will be used, all the keys will be transformed into string.


### In Modern Browser

Just download the `index.js` as `Multimap.js`.

```
<script src=Multimap.js"></script>
<script>
var map = new Multimap([['a', 1], ['b', 2], ['c', 3]]);
map = map.set('b', 20);
map.get('b'); // [2, 20]
</script>
```

Or use as an AMD loader:

```
require(['./Multimap.js'], function (Multimap) {
  var map = new Multimap([['a', 1], ['b', 2], ['c', 3]]);
  map = map.set('b', 20);
  map.get('b'); // [2, 20]
});
```

* Browsers should support `Object.defineProperty` and `Array.prototype.forEach`.


## API

Following shows how to use `Multimap`:

```javascript
var Multimap = require('multimap');

var map = new Multimap([['a', 'one'], ['b', 1], ['a', 'two'], ['b', 2]]);

map.size;                 // 4
map.count;                // 2

map.get('a');             // ['one', 'two']
map.get('b');             // [1, 2]

map.has('a');             // true
map.has('foo');           // false

map.has('a', 'one');      // true
map.has('b', 3);          // false

map.set('a', 'three');
map.size;                 // 5
map.count;                // 2
map.get('a');             // ['one', 'two', 'three']

map.set('b', 3, 4);
map.size;                 // 7
map.count;                // 2

map.delete('a', 'three'); // true
map.delete('x');          // false
map.delete('a', 'four');  // false
map.delete('b');          // true

map.size;                 // 2
map.count;                // 1

map.set('b', 1, 2);
map.size;                 // 4
map.count;                // 2


map.forEach(function (value, key) {
  // iterates { 'one', 'a' }, { 'two', 'a' }, { 1, b }, { 2, 'b' }
});

map.forEachEntry(function (entry, key) {
  // iterates {['one', 'two'], 'a' }, {[1, 2], 'b' }
});


var keys = map.keys();      // iterator with ['a', 'b']
keys.next().value;          // 'a'
var values = map.values();  // iterator ['one', 'two', 1, 2]

map.clear();                // undefined
map.size;                   // 0
map.count;                  // 0
```




## License

(The MIT License)

Copyright (c) 2013, Villa.Gao <jky239@gmail.com>;
All rights reserved.

---
_Source: https://npm.io/package/multimap · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
