@enonic/js-utils
Version:
Enonic XP JavaScript Utils
91 lines (90 loc) • 3.09 kB
JavaScript
;
function _type_of(obj) {
"@swc/helpers - typeof";
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = function(target, all) {
for(var name in all)__defProp(target, name, {
get: all[name],
enumerable: true
});
};
var __copyProps = function(to, from, except, desc) {
if (from && (typeof from === "undefined" ? "undefined" : _type_of(from)) === "object" || typeof from === "function") {
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
try {
var _loop = function() {
var key = _step.value;
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: function() {
return from[key];
},
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
};
for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally{
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally{
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
return to;
};
var __toCommonJS = function(mod) {
return __copyProps(__defProp({}, "__esModule", {
value: true
}), mod);
};
// object/deleteIn.ts
var deleteIn_exports = {};
__export(deleteIn_exports, {
default: function() {
return deleteIn_default;
}
});
module.exports = __toCommonJS(deleteIn_exports);
function deleteIn(obj) {
for(var _len = arguments.length, paths = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
paths[_key - 1] = arguments[_key];
}
if (!obj || !paths) {
return;
}
var uniformPath = [];
for(var i = 0; i < paths.length; i++){
var path = paths[i];
if (typeof path === "string") {
path.split(".").forEach(function(p) {
return uniformPath.push(p);
});
} else if (Array.isArray(path)) {
path.forEach(function(p) {
return uniformPath.push(p);
});
} else {
uniformPath.push(path);
}
}
for(var i1 = 0; i1 < uniformPath.length - 1; i1++){
obj = obj[uniformPath[i1]];
if (typeof obj === "undefined") {
return;
}
}
delete obj[uniformPath.pop()];
}
var deleteIn_default = deleteIn;