UNPKG

react-hooks-global-states

Version:

This is a package to easily handling global-state across your react-components using hooks.

53 lines (52 loc) 2.34 kB
/** * @description It performs a shallow comparison of the values. * @param value1 - The first value to compare. * @param value2 - The second value to compare. * @returns True if the values are equal, false otherwise. */ export declare const shallowCompare: <T>(value1: T, value2: T) => boolean; export declare const isArray: (value: unknown) => value is unknown[]; export declare const isMap: (value: unknown) => value is Map<unknown, unknown>; export declare const isSet: (value: unknown) => value is Set<unknown>; /** * @description Determines whether a simple equality check (using `===`) is sufficient * to compare the provided values. This helps decide when a deep equality check * is unnecessary or inefficient. * * Simple equality checks are considered valid when: * - The values have different types (comparison will trivially return false) * - Either value is null or undefined * - Both values are primitive types (string, number, boolean, symbol, bigint) * - Both values are Date objects * - Both values are functions * * @param value1 - The first value to compare. * @param value2 - The second value to compare. * @returns `true` if a simple `===` check is sufficient, `false` if a deep comparison may be required. * * @example * ```ts * canCheckSimpleEquality(42, 42); // true (primitive numbers) * canCheckSimpleEquality({ a: 1 }, { a: 1 }); // false (objects) * canCheckSimpleEquality([1, 2], [1, 2]); // false (arrays) * canCheckSimpleEquality('a', 1); // true (different types, shallow check enough) * ``` */ export declare const canCheckSimpleEquality: (value1: unknown, value2: unknown) => boolean; /** * @description Performs a shallow comparison between two arrays. */ export declare const isEqualArray: <T>(array1: T[], array2: T[]) => array1 is T[]; /** * @description Performs a shallow comparison between two maps. */ export declare const isEqualMap: <K, V>(map1: Map<K, V>, map2: Map<K, V>) => map1 is Map<K, V>; /** * @description Performs a shallow comparison between two sets. */ export declare const isEqualSet: <T>(set1: Set<T>, set2: Set<T>) => set1 is Set<T>; /** * @description Performs a shallow comparison between two objects. */ export declare const isEqualObject: <T extends Record<string, unknown>>(value1: T, value2: T) => boolean; export default shallowCompare;