match(payloadIn, payloadTemplate) { var payload = _.cloneDeep(payloadIn); var template = _.cloneDeep(payloadTemplate); // strip all wildcards out of template and payload _.deepMapValues(payloadTemplate, (value, path) => { if (/\<\%\= *\* *\%\>/.test(value)) { _.unset(template, path); _.unset(payload, path); } }); // compare for equality - partially matching on any array defined in template let isMatch = _.isEqualWith(payload, template, (p, t, k) => { // p - from payload, t - from template, k - key if (_.isArray(t)) { // p = (_.isArray(p))? p : [p]; return _(p) .intersectionWith(t, _.isEqual) // finds common .value().length == p.length; // } }) if(!isMatch) this.log.error("paycheck cannot match ", JSON.stringify(payload), JSON.stringify(template)) return isMatch; }
return find(callSites, callSite => isEqualWith(callSite.location, location, (cloc, loc) => { return ( loc.line === cloc.start.line && (loc.column >= cloc.start.column && loc.column <= cloc.end.column) ); })
const isEq = (o1, o2) => { const isEq = isEqualWith(o1, o2, function(val1, val2) { if (isFunction(val1) && isFunction(val2)) { return val1 === val2 || val1.toString() === val2.toString(); } }); return isEq; };
isStructureSame(a, b) { // same structure, excluding arrays return _.isEqualWith(a, b, (a, b) => { // is object and not an array, ie, arrays are considered as values if(!(_.isObject(a) && !_.isArray(a)) && !(_.isObject(b) && !_.isArray(b))) return true; } ) }
/** * Returns whether the two expressions refer to the same object (e.g. a['b'].c and a.b.c) * @param {Object} a * @param {Object} b * @returns {boolean} */ function isEquivalentExp(a, b) { return _.isEqualWith(a, b, (left, right, key) => { if (_.includes(['loc', 'range', 'computed', 'start', 'end'], key)) { return true } if (isComputed(left) || isComputed(right)) { return false } if (key === 'property') { const leftValue = left.name || left.value const rightValue = right.name || right.value return leftValue === rightValue } }) }
/** * Returns whether the two expressions refer to the same object (e.g. a['b'].c and a.b.c) * @param {Object} a * @param {Object} b * @returns {boolean} */ function isEquivalentExp(a, b) { return _.isEqualWith(a, b, function (left, right, key) { if (_.includes(["loc", "range", "computed", "start", "end"], key)) { return true; } if (isComputed(left) || isComputed(right)) { return false; } if (key === "property") { var leftValue = left.name || left.value; var rightValue = right.name || right.value; return leftValue === rightValue; } }); }
function assertDeepMatch( val, msg ) { var actual = this._obj; var expected = val; var isDeep = !!util.flag( this, 'deep' ); if ( isDeep && typeof actual === 'object' && typeof expected === 'object' && ( expected == null || toString.call( expected ) !== '[object RegExp]' ) ) { if ( msg ) { util.flag( this, 'message', msg ); } var matchResult = actual == null && expected == null; if ( matchResult === false ) { matchResult = whatwgUrlComparator( actual, expected ); } // This particular `if` check is critical to correctly verifying URLs if ( matchResult === undefined ) { matchResult = _.isEqualWith( actual, expected, whatwgUrlComparator ); if ( matchResult === false ) { matchResult = ( typeof actual === 'object' && typeof expected === 'object' && actual != null && expected != null && _.isMatchWith( actual, expected, whatwgUrlComparator ) ); } } this.assert( matchResult, 'expected #{this} to deeply match #{exp}', 'expected #{this} to deeply not match #{exp}', expected, actual == null ? actual : pickDeep( actual, keysDeep( expected ) ), true ); } else { _super.apply( this, arguments ); } }
/** * True when two AST nodes are structurally equal. * When comparing objects it ignores the meta-data fields for * comments and source-code position. * @param {Object} a * @param {Object} b * @return {Boolean} */ export default function isEqualAst(a, b) { return _.isEqualWith(a, b, (aValue, bValue, key) => metaDataFields[key]); }
/** * Compares two options objects and returns if they are deep equal to each other. * Objects which are not plain objects (e.g. Models) are compared by reference. * Everything else deep-compared by value. * * @param {Object} options - Options object * @param {Object} original - Original options object * @returns {boolean} - true if options and original are same, false if not */ function optionsEqual(options, original) { return _.isEqualWith(options, original, (value1, value2) => { if (typeof value1 === 'object' && !_.isPlainObject(value1) || typeof value2 === 'object' && !_.isPlainObject(value2)) return value1 === value2; }); }
(a, b) => isEqualWith(a, b, isShallowEqual)
const deepEqual = (a: any, b: any) => isEqualWith(a, b, customizer)
obj.every((value, key) => { return other.has(key) && isEqualWith(value, other.get(key), customizer) })
const deepEqual = (a, b) => isEqualWith(a, b, customizer)