0.1.0 • Published 8 years ago
lomap v0.1.0
_map
Install
$ npm install --save lomap
Usage
const _map = require('lomap')
const obj = {foo: 123, bar: 456}
// simple case: pick some fields
_map(obj, ['foo'])
// {foo: 123}
// level up: pick with different name
_map(obj, {foo2: 'foo'})
// {foo2: 123}
// final move: pick and process with a handler function
_map(obj, ['foo'], val => val + 1)
// {foo: 123}
API
_map(source, selection, handler)
source
Type: object
Required: true
Source object.
selection
Type: array
object
An array of keys to select or key-value pair to set different to target object.
handler
Type: function
Default: val => val
Process each value with a handler function.
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
License
0.1.0
8 years ago