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:
917 bytes
|
Line | |
---|
1 | var _isArray =
|
---|
2 | /*#__PURE__*/
|
---|
3 | require("./_isArray.js");
|
---|
4 |
|
---|
5 | var _isInteger =
|
---|
6 | /*#__PURE__*/
|
---|
7 | require("./_isInteger.js");
|
---|
8 | /**
|
---|
9 | * Makes a shallow clone of an object, setting or overriding 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 {*} val The new value
|
---|
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 |
|
---|
22 | function _assoc(prop, val, obj) {
|
---|
23 | if (_isInteger(prop) && _isArray(obj)) {
|
---|
24 | var arr = [].concat(obj);
|
---|
25 | arr[prop] = val;
|
---|
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] = val;
|
---|
36 | return result;
|
---|
37 | }
|
---|
38 |
|
---|
39 | module.exports = _assoc; |
---|
Note:
See
TracBrowser
for help on using the repository browser.