1234567891011121314151617181920212223242526272829303132 |
- 'use strict'
- module.exports = {
- prop: prop => obj => obj[prop],
- defaults: (obj, values) => {
- Object.keys(values).forEach(key => {
- if (!obj.hasOwnProperty(key)) {
- obj[key] = values[key]
- }
- })
- },
- forEach: (obj, callback) => {
- Object.keys(obj).forEach(key => {
- callback(key, obj[key])
- })
- },
- reduce: (obj, fnReduce, startValue) => {
- return Object.keys(obj).reduce((acc, key) => {
- return fnReduce.call(null, acc, key, obj[key])
- }, startValue)
- },
- map: (obj, fnMap) => {
- return Object.keys(obj).reduce((mapped, key) => {
- mapped[key] = fnMap(obj[key], key)
- return mapped
- }, {})
- }
- }
|