import { createErrorReporter } from "./error-reporter" ; import { createExtant } from "./extant" ; export const createObj = ( ctx , isExactMatching = false ) => function obj ( ... entriesWithRest ) { return function objFn ( a , msg ? ) { return createErrorReporter ( "obj" , ctx , msg , [ a , entriesWithRest ] , false , true ) ( ( ) => { const isExtant = createExtant ( ctx ) ; const isDeepParentExactMatch = ctx . getObjExactStack ( ) . reduce ( ( acc , item ) => acc || item , false ) ; let isLooseMatching = ! ( isExactMatching || isDeepParentExactMatch ) ; let entriesMatch = true ; let entryCount = 0 ; for ( let i = 0 ; i < entriesWithRest . length ; i ++ ) { const entry = entriesWithRest [ i ] ; if ( entry === "..." ) { isLooseMatching = isLooseMatching || true ; continue ; } const [ key , predicate ] = Array . isArray ( entry ) ? entry : [ entry , isExtant ] ; ctx . pushObjStack ( key , isExactMatching ) ; let result ; if ( ctx . abortEarly ) { result = isExtant ( a ) && predicate ( a [ key ] ) ; } else { result = predicate ( isExtant ( a ) ? a [ key ] : undefined ) ; } ctx . popObjStack ( ) ; entriesMatch = entriesMatch && result ; entryCount ++ ; } if ( isLooseMatching ) return entriesMatch ; return entriesMatch && Object . keys ( a ) . length === entryCount ; } ) ; } ; } ;