eq
lang
Performs a SameValueZero comparison between two values to determine if they are equivalent.
Installation
Import
import { eq } from '@tulx/utils';Source Code
Implementation
/**
* Performs a SameValueZero comparison between two values to determine if they are equivalent.
*
* @param value - The value to compare.
* @param other - The other value to compare.
* @returns Returns true if the values are equivalent, else false.
*
* @example
* ```ts
* const object = { 'a': 1 };
* const other = { 'a': 1 };
* eq(object, object); // true
* eq(object, other); // false
* eq('a', 'a'); // true
* eq('a', Object('a')); // false
* eq(NaN, NaN); // true
* ```
*/
export function eq(value: unknown, other: unknown): boolean {
return value === other || (Number.isNaN(value) && Number.isNaN(other));
}
Example
import { eq } from '@tulx/utils';
const object = { 'a': 1 };
const other = { 'a': 1 };
eq(object, object); // true
eq(object, other); // false
eq('a', 'a'); // true
eq('a', Object('a')); // false
eq(NaN, NaN); // trueRelated Functions
castArray
Casts value as an array if it's not one.
clone
Creates a shallow clone of value.
cloneDeep
This method is like clone except that it recursively clones value.
cloneDeepWith
This method is like cloneDeep except that it accepts customizer which is invoked to produce the cloned value.
cloneWith
This method is like clone except that it accepts customizer which is invoked to produce the cloned value.
conformsTo
Checks if object conforms to source by invoking the predicate properties of source with the corresponding property values of object.