Skip to main content

compare

Does a type or deep value comparison of two objects.

Signature

compare(a: {}, b: {}, compareValues: boolean): boolean

Parameters

NameTypeOptionalDescription
a{}NoSpecifies the first variable.
b{}NoSpecifies the second variable.
compareValuesbooleanNoSpecifies if the values or just the structure needs to be compared.

Return value

Returns true if the objects are identical.

Example

import { compare } from "@tripetto/runner";

compare({ a: 1, b: 2 }, { a: 1, b: 3 }, false); // Returns `true`
compare({ a: 1, b: 2 }, { a: 1, c: 3 }, false); // Returns `false`
compare({ a: 1, b: 2 }, { a: 1, b: 3 }, true); // Returns `false`
compare({ a: 1, b: 2 }, { a: 1, b: 2 }, true); // Returns `true`