-
-
Notifications
You must be signed in to change notification settings - Fork 0
equal()
Eugene Lazutkin edited this page Nov 9, 2020
·
2 revisions
This function compares two JavaScript objects for deep equivalency. It can handle objects with circular dependencies.
import equal from 'deep6';
// or: import {equal} from 'deep6';
equal({a: [1]}, {a: [1]}); // true
equal({a: [1]}, {a: [2]}); // false
equal({a: [1]}, {b: [1]}); // false
Arguments:
-
a
— a required argument. It can be anything. -
b
— a required argument. It can be anything. -
options
— an optional object. The following optional properties are recognized:-
circular
— a boolean flag. Whentrue
, special algorithms are used to detect internal loops in objects.- It is totally safe to turn it on for all objects, but checks will require more memory and more CPU. In some cases, for performance reasons, you may want to turn it off.
-
symbols
— a boolean flag. Whentrue
, symbol properties would be checked for equivalency as well.- Normally symbol properties are hidden from enumerating using classical means.
-
ignoreFunctions
— a boolean flag. Whentrue
, if both properties are functions, they are assumed to be equivalent automatically. -
loose
— a boolean flag. Whentrue
, primitives are compared with==
rather than===
. - Any other properties documented in unify().
The default:
{circular: true}
. -
The function returns a boolean value, which indicates the equivalence of its first two arguments.
Implemented using unify():
const defaultOptions = {circular: true};
const equal = (a, b, options = defaultOptions) => !!unify(a, b, null, options);