MCPcopy Create free account
hub / github.com/activejs/activejs / findEqualitiesByReference

Function findEqualitiesByReference

packages/core/src/tests/utils.ts:527–554  ·  view source on GitHub ↗
(A: any, B: any)

Source from the content-addressed store, hash-verified

525}
526
527export function findEqualitiesByReference(A: any, B: any): any[] {
528 if (A == null || B == null || typeof A !== 'object' || typeof B !== 'object') {
529 return [];
530 }
531 if (A === B) {
532 return [A]; // or [B]
533 }
534
535 const deepObjectExtract = (o, r = []) => {
536 if (o == null || typeof o !== 'object') {
537 return r;
538 }
539
540 r.push(o);
541
542 if (!Array.isArray(o)) {
543 o = Object.values(o);
544 }
545
546 o.forEach(c => deepObjectExtract(c, r));
547 return r;
548 };
549
550 const AO = deepObjectExtract(A);
551 const BO = deepObjectExtract(B);
552
553 return AO.filter(o => BO.includes(o));
554}
555
556export const CUSTOM_MATCHERS = {
557 toHaveSharedReferenceIn: () => {

Callers 1

utils.tsFile · 0.85

Calls 1

deepObjectExtractFunction · 0.85

Tested by

no test coverage detected