Check if two values deeply match
deepMatch(object, example)
All properties and nested objects mentioned in the example
are required to be
present in object
.
// two objects that look exactly the same; // true // additional properties on the left-hand side are ignored; // true // everything on the right-hand side is required; // false // same for arrays; // true; // false
Regular expressions and functions in the example
are run against the corresponding values in the object
:
; // true; // false; // true; // true; // false; // true
Rules
Values are compared according to the following rules:
- Identical values always match.
- Values of different types never match.
- Values that are no objects only match if they are identical (see above).
- Null values (which are also objects) only match if both are null.
- Arrays match if all items in the example match.
- Objects match if all properties in the example match.
License
MIT