source: node_modules/ramda/src/internal/_modify.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 974 bytes
Line 
1var _isArray =
2/*#__PURE__*/
3require("./_isArray.js");
4
5var _isInteger =
6/*#__PURE__*/
7require("./_isInteger.js");
8/**
9 * Makes a shallow clone of an object, applying the given fn to the specified
10 * property with the given value. Note that this copies and flattens prototype
11 * properties onto the new object as well. All non-primitive properties are
12 * copied by reference.
13 *
14 * @private
15 * @param {String|Number} prop The property name to set
16 * @param {Function} fn The function to apply to the property
17 * @param {Object|Array} obj The object to clone
18 * @return {Object|Array} A new object equivalent to the original except for the changed property.
19 */
20
21
22function _modify(prop, fn, obj) {
23 if (_isInteger(prop) && _isArray(obj)) {
24 var arr = [].concat(obj);
25 arr[prop] = fn(arr[prop]);
26 return arr;
27 }
28
29 var result = {};
30
31 for (var p in obj) {
32 result[p] = obj[p];
33 }
34
35 result[prop] = fn(result[prop]);
36 return result;
37}
38
39module.exports = _modify;
Note: See TracBrowser for help on using the repository browser.