@enonic/js-utils
Version:
Enonic XP JavaScript Utils
92 lines (91 loc) • 3.3 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);
};
// storage/indexing/updateIndexConfigs.ts
var updateIndexConfigs_exports = {};
__export(updateIndexConfigs_exports, {
updateIndexConfigs: function() {
return updateIndexConfigs;
}
});
module.exports = __toCommonJS(updateIndexConfigs_exports);
// array/findIndex.ts
function findIndex(array, callbackFn) {
var length = array.length >>> 0;
for(var i = 0; i < length; i++){
if (callbackFn(array[i], i, array)) {
return i;
}
}
return -1;
}
// storage/indexing/updateIndexConfigs.ts
function updateIndexConfigs(param) {
var _loop = function(i) {
var anUpdate = updates[i];
var j = findIndex(dereffedConfigs, //({path}: IndexConfigsItem) => path === anUpdate.path
function(item) {
return item.path === anUpdate.path;
});
if (j !== -1) {
dereffedConfigs.splice(j, 1, anUpdate);
} else {
dereffedConfigs.push(anUpdate);
}
};
var configs = param.configs, _param_updates = param.updates, updates = _param_updates === void 0 ? [] : _param_updates;
var dereffedConfigs = JSON.parse(JSON.stringify(configs));
for(var i = 0; i < updates.length; i++)_loop(i);
dereffedConfigs.sort(function(a, b) {
return a.path > b.path ? 1 : -1;
});
return dereffedConfigs;
}