@aws/pdk
Version:
All documentation is located at: https://aws.github.io/aws-pdk
39 lines (32 loc) • 974 B
JavaScript
var _isArray =
/*#__PURE__*/
require("./_isArray.js");
var _isInteger =
/*#__PURE__*/
require("./_isInteger.js");
/**
* Makes a shallow clone of an object, applying the given fn to the specified
* property with the given value. Note that this copies and flattens prototype
* properties onto the new object as well. All non-primitive properties are
* copied by reference.
*
* @private
* @param {String|Number} prop The property name to set
* @param {Function} fn The function to apply to the property
* @param {Object|Array} obj The object to clone
* @return {Object|Array} A new object equivalent to the original except for the changed property.
*/
function _modify(prop, fn, obj) {
if (_isInteger(prop) && _isArray(obj)) {
var arr = [].concat(obj);
arr[prop] = fn(arr[prop]);
return arr;
}
var result = {};
for (var p in obj) {
result[p] = obj[p];
}
result[prop] = fn(result[prop]);
return result;
}
module.exports = _modify;