[d24f17c] | 1 | var _curry2 =
|
---|
| 2 | /*#__PURE__*/
|
---|
| 3 | require("./internal/_curry2.js");
|
---|
| 4 |
|
---|
| 5 | var _dissoc =
|
---|
| 6 | /*#__PURE__*/
|
---|
| 7 | require("./internal/_dissoc.js");
|
---|
| 8 |
|
---|
| 9 | var _isInteger =
|
---|
| 10 | /*#__PURE__*/
|
---|
| 11 | require("./internal/_isInteger.js");
|
---|
| 12 |
|
---|
| 13 | var _isArray =
|
---|
| 14 | /*#__PURE__*/
|
---|
| 15 | require("./internal/_isArray.js");
|
---|
| 16 |
|
---|
| 17 | var assoc =
|
---|
| 18 | /*#__PURE__*/
|
---|
| 19 | require("./assoc.js");
|
---|
| 20 | /**
|
---|
| 21 | * Makes a shallow clone of an object. Note that this copies and flattens
|
---|
| 22 | * prototype properties onto the new object as well. All non-primitive
|
---|
| 23 | * properties are copied by reference.
|
---|
| 24 | *
|
---|
| 25 | * @private
|
---|
| 26 | * @param {String|Integer} prop The prop operating
|
---|
| 27 | * @param {Object|Array} obj The object to clone
|
---|
| 28 | * @return {Object|Array} A new object equivalent to the original.
|
---|
| 29 | */
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | function _shallowCloneObject(prop, obj) {
|
---|
| 33 | if (_isInteger(prop) && _isArray(obj)) {
|
---|
| 34 | return [].concat(obj);
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | var result = {};
|
---|
| 38 |
|
---|
| 39 | for (var p in obj) {
|
---|
| 40 | result[p] = obj[p];
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | return result;
|
---|
| 44 | }
|
---|
| 45 | /**
|
---|
| 46 | * Makes a shallow clone of an object, omitting the property at the given path.
|
---|
| 47 | * Note that this copies and flattens prototype properties onto the new object
|
---|
| 48 | * as well. All non-primitive properties are copied by reference.
|
---|
| 49 | *
|
---|
| 50 | * @func
|
---|
| 51 | * @memberOf R
|
---|
| 52 | * @since v0.11.0
|
---|
| 53 | * @category Object
|
---|
| 54 | * @typedefn Idx = String | Int | Symbol
|
---|
| 55 | * @sig [Idx] -> {k: v} -> {k: v}
|
---|
| 56 | * @param {Array} path The path to the value to omit
|
---|
| 57 | * @param {Object} obj The object to clone
|
---|
| 58 | * @return {Object} A new object without the property at path
|
---|
| 59 | * @see R.assocPath
|
---|
| 60 | * @example
|
---|
| 61 | *
|
---|
| 62 | * R.dissocPath(['a', 'b', 'c'], {a: {b: {c: 42}}}); //=> {a: {b: {}}}
|
---|
| 63 | */
|
---|
| 64 |
|
---|
| 65 |
|
---|
| 66 | var dissocPath =
|
---|
| 67 | /*#__PURE__*/
|
---|
| 68 | _curry2(function dissocPath(path, obj) {
|
---|
| 69 | if (obj == null) {
|
---|
| 70 | return obj;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | switch (path.length) {
|
---|
| 74 | case 0:
|
---|
| 75 | return obj;
|
---|
| 76 |
|
---|
| 77 | case 1:
|
---|
| 78 | return _dissoc(path[0], obj);
|
---|
| 79 |
|
---|
| 80 | default:
|
---|
| 81 | var head = path[0];
|
---|
| 82 | var tail = Array.prototype.slice.call(path, 1);
|
---|
| 83 |
|
---|
| 84 | if (obj[head] == null) {
|
---|
| 85 | return _shallowCloneObject(head, obj);
|
---|
| 86 | } else {
|
---|
| 87 | return assoc(head, dissocPath(tail, obj[head]), obj);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | }
|
---|
| 91 | });
|
---|
| 92 |
|
---|
| 93 | module.exports = dissocPath; |
---|