Repository URL to install this package:
|
Version:
0.7.0 ▾
|
// (c) Copyright 2023 Supertenant Ltd. - all rights reserved.
// See LICENSE file in project root for license terms.
"use strict";function applyCompression(path,prev,next,excludeList){var nType;return isExcluded(path,excludeList)?next:null!=excludeList||prev!==next?typeof prev!=(nType=typeof next)?next:Array.isArray(next)?applyCompressionToArray(prev,next):"object"==nType?applyCompressionToObject(path,prev,next,excludeList):prev!==next?next:void 0:void 0}function applyCompressionToObject(path,prev,next,excludeList){var nValue,pValue,result={};let addedProps=0;for(const nKey in next)next.hasOwnProperty(nKey)&&(nValue=next[nKey],pValue=prev[nKey],void 0!==(pValue=applyCompression(path.concat(nKey),pValue,nValue,excludeList)))&&(result[nKey]=pValue,addedProps++);if(0<addedProps)return result}function applyCompressionToArray(prev,next){if(next.length!==prev.length)return next;let hasChanges=!1;for(let i=0,len=next.length;i<len&&!hasChanges;i++)hasChanges=prev[i]!==next[i];return hasChanges?next:void 0}function isExcluded(path,excludeList){if(null!=excludeList)outer:for(let i=0;i<excludeList.length;i++)if(excludeList[i].length===path.length){for(let j=0;j<excludeList[i].length;j++)if(excludeList[i][j]!==path[j])continue outer;return!0}return!1}module.exports=function(prev,next,excludeList){prev=applyCompression([],prev,next,excludeList);return void 0===prev?{}:prev};