Comparing version 2.6.0 to 2.7.0
@@ -601,2 +601,52 @@ 'use strict'; | ||
/** | ||
* Returns the object with each value being run throuh the function. (Better description needed. lol) | ||
* | ||
* @example | ||
* | ||
* let x = { | ||
* a: 1, | ||
* d: {f: 4} | ||
* } | ||
* | ||
* ob.mapValues(x, (x) => x*3 ) | ||
* // → { | ||
* // a: 3, | ||
* // d: {f: 12} | ||
* //} | ||
* @param {object|any[]} subject The object or array to compare to | ||
* @param {function} func The function to operate on each value | ||
* @returns {object|any[]} | ||
*/ | ||
mapValues: function mapValues(subject, func) { | ||
subject = ob.flatten(subject); | ||
var shallowSubject = (0, _functions.makeFlattenedShallow)(subject); | ||
var _iteratorNormalCompletion7 = true; | ||
var _didIteratorError7 = false; | ||
var _iteratorError7 = undefined; | ||
try { | ||
for (var _iterator7 = Object.keys(shallowSubject)[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) { | ||
var key = _step7.value; | ||
shallowSubject[key] = func(shallowSubject[key]); | ||
} | ||
} catch (err) { | ||
_didIteratorError7 = true; | ||
_iteratorError7 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion7 && _iterator7.return) { | ||
_iterator7.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError7) { | ||
throw _iteratorError7; | ||
} | ||
} | ||
} | ||
return ob.expand(shallowSubject); | ||
}, | ||
/** | ||
* Merges the enumerable attributes of two objects deeply. | ||
@@ -688,9 +738,9 @@ * | ||
if ((0, _typeOf2.default)(keys) === 'array') { | ||
var _iteratorNormalCompletion7 = true; | ||
var _didIteratorError7 = false; | ||
var _iteratorError7 = undefined; | ||
var _iteratorNormalCompletion8 = true; | ||
var _didIteratorError8 = false; | ||
var _iteratorError8 = undefined; | ||
try { | ||
for (var _iterator7 = keys[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) { | ||
var desiredKey = _step7.value; | ||
for (var _iterator8 = keys[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) { | ||
var desiredKey = _step8.value; | ||
@@ -702,12 +752,12 @@ if (actualKey === desiredKey) { | ||
} catch (err) { | ||
_didIteratorError7 = true; | ||
_iteratorError7 = err; | ||
_didIteratorError8 = true; | ||
_iteratorError8 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion7 && _iterator7.return) { | ||
_iterator7.return(); | ||
if (!_iteratorNormalCompletion8 && _iterator8.return) { | ||
_iterator8.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError7) { | ||
throw _iteratorError7; | ||
if (_didIteratorError8) { | ||
throw _iteratorError8; | ||
} | ||
@@ -759,9 +809,9 @@ } | ||
if ((0, _typeOf2.default)(subject) === 'array') { | ||
var _iteratorNormalCompletion8 = true; | ||
var _didIteratorError8 = false; | ||
var _iteratorError8 = undefined; | ||
var _iteratorNormalCompletion9 = true; | ||
var _didIteratorError9 = false; | ||
var _iteratorError9 = undefined; | ||
try { | ||
for (var _iterator8 = subject[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) { | ||
var i = _step8.value; | ||
for (var _iterator9 = subject[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) { | ||
var i = _step9.value; | ||
@@ -771,12 +821,12 @@ values = values.concat(ob.values(i)); | ||
} catch (err) { | ||
_didIteratorError8 = true; | ||
_iteratorError8 = err; | ||
_didIteratorError9 = true; | ||
_iteratorError9 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion8 && _iterator8.return) { | ||
_iterator8.return(); | ||
if (!_iteratorNormalCompletion9 && _iterator9.return) { | ||
_iterator9.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError8) { | ||
throw _iteratorError8; | ||
if (_didIteratorError9) { | ||
throw _iteratorError9; | ||
} | ||
@@ -783,0 +833,0 @@ } |
{ | ||
"name": "objob", | ||
"version": "2.6.0", | ||
"version": "2.7.0", | ||
"description": "A tool for controlling and manipulating javascript object fields and output.", | ||
@@ -5,0 +5,0 @@ "main": "lib/objob.js", |
@@ -456,2 +456,31 @@ 'use strict'; | ||
/** | ||
* Returns the object with each value being run throuh the function. (Better description needed. lol) | ||
* | ||
* @example | ||
* | ||
* let x = { | ||
* a: 1, | ||
* d: {f: 4} | ||
* } | ||
* | ||
* ob.mapValues(x, (x) => x*3 ) | ||
* // → { | ||
* // a: 3, | ||
* // d: {f: 12} | ||
* //} | ||
* @param {object|any[]} subject The object or array to compare to | ||
* @param {function} func The function to operate on each value | ||
* @returns {object|any[]} | ||
*/ | ||
mapValues: function(subject, func){ | ||
subject = ob.flatten(subject); | ||
let shallowSubject = makeFlattenedShallow(subject); | ||
for(let key of Object.keys(shallowSubject)) { | ||
shallowSubject[key] = func(shallowSubject[key]); | ||
} | ||
return ob.expand(shallowSubject); | ||
}, | ||
/** | ||
* Merges the enumerable attributes of two objects deeply. | ||
@@ -458,0 +487,0 @@ * |
Sorry, the diff of this file is not supported yet
656494
42
3118