Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xixixao/object-map
map a function over some Object's values to produce a new Object
https://github.com/xixixao/object-map
Last synced: 3 months ago
JSON representation
map a function over some Object's values to produce a new Object
- Host: GitHub
- URL: https://github.com/xixixao/object-map
- Owner: xixixao
- Created: 2015-10-27T13:01:11.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-06-21T05:15:37.000Z (over 8 years ago)
- Last Synced: 2024-10-08T15:11:23.921Z (4 months ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Map a function over the values of an Object to produce a new Object with the same keys.
The API is modelled after the native [Array#map](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/map) method.
## Installation
```bash
$ npm install --save object-map
```## Example
```js
var objectMap = require('object-map');var target = {
foo: 1,
bar: 2
};var result = objectMap(target, function(value) {
return value * value;
});
// => {foo: 1, bar: 4}
```## API
`objectMap(target, callback[, thisArg])`
- `target` an object who's properties are iterated using `hasOwnProperty`
- `callback` a function producing a value of the new Object, taking three arguments:
- `currentValue` the value currently associated with the key
- `key` the current key
- `object` the original object passed to `objectMap`
- `thisArg` Optional. Value to use as `this` when executing `callback`.## License
[MIT](https://tldrlegal.com/license/mit-license)