https://github.com/landau/zipmap
Returns a map with the keys mapped to the corresponding vals.
https://github.com/landau/zipmap
Last synced: 8 months ago
JSON representation
Returns a map with the keys mapped to the corresponding vals.
- Host: GitHub
- URL: https://github.com/landau/zipmap
- Owner: landau
- License: isc
- Created: 2014-03-26T02:22:22.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T02:27:11.000Z (over 2 years ago)
- Last Synced: 2025-08-09T19:45:33.385Z (8 months ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-micro-npm-packages-zh - zipmap - 压拼成一个对象. (模块 / 对象)
- fucking-awesome-micro-npm-packages - zipmap - Returns a map with the keys mapped to the corresponding vals. zipmap also accepts a single value of objects or pairs. (Modules / Object)
- awesome-micro-npm-packages - zipmap - Returns a map with the keys mapped to the corresponding vals. zipmap also accepts a single value of objects or pairs. (Modules / Object)
- awesome-micro-npm-packages - zipmap - Returns a map with the keys mapped to the corresponding vals. zipmap also accepts a single value of objects or pairs. (Modules / Object)
README
[](https://travis-ci.org/landau/zipmap)
zipmap
======
Returns a map with the keys mapped to the corresponding vals. `zipmap` also accepts a single value of objects or pairs.
> Note: If you use objects, you must use the props `key` and `value`
```js
/**
* Returns a map with the keys mapped to the corresponding vals.
*
* @param {array} keys
* @param {array} [vals]
*
* @return {object}
*/
function zipmap(keys, vals) { }
```
## Install
`npm i -S zipmap`
## Usage
```js
var assert = require('assert');
var zipmap = require('zipmap');
var keys = ['a', 'b', 'c'];
var vals = [1, 2, 3];
var map = zipmap(keys, vals);
assert.deepEqual(map, { a: 1, b: 2, c: 3 });
```
Or use an array of objects
```js
var objs = [
{ key: 'foo', value: 'bar' },
{ key: 'hi', value: 'bye' },
];
var out = {
foo: 'bar',
hi: 'bye'
};
var map = zipmap(objs);
assert.deepEqual(map, out);
```
or use an array of pairs
```js
var pairs = [
['foo', 'bar'],
['hi', 'bye']
];
var out = {
foo: 'bar',
hi: 'bye'
};
var map = zipmap(pairs);
assert.deepEqual(map, out);
```
## Changelog
#### 1.1.1
- Return empty obj when given an array of len 0
#### 1.1.0
- Add single argument handling which allows objects or pairs