UNPKG

@enonic/js-utils

Version:
39 lines (37 loc) 880 B
// array/findIndex.ts function findIndex(array, callbackFn) { const length = array.length >>> 0; for (let i = 0; i < length; i++) { if (callbackFn(array[i], i, array)) { return i; } } return -1; } // storage/indexing/updateIndexConfigs.ts function updateIndexConfigs({ configs, updates = [] }) { const dereffedConfigs = JSON.parse(JSON.stringify(configs)); for (let i = 0; i < updates.length; i++) { const anUpdate = updates[i]; const j = findIndex( dereffedConfigs, //({path}: IndexConfigsItem) => path === anUpdate.path (item) => item.path === anUpdate.path ); if (j !== -1) { dereffedConfigs.splice(j, 1, anUpdate); } else { dereffedConfigs.push(anUpdate); } } dereffedConfigs.sort( (a, b) => a.path > b.path ? 1 : -1 ); return dereffedConfigs; } export { updateIndexConfigs };