fast-equals

  • Version 5.2.2
  • Published
  • 345 kB
  • No dependencies
  • MIT license

Install

npm i fast-equals
yarn add fast-equals
pnpm add fast-equals

Overview

A blazing fast equality comparison, either shallow or deep

Index

Functions

function circularDeepEqual

circularDeepEqual: <A, B>(a: A, b: B) => boolean;
  • Whether the items passed are deeply-equal in value, including circular references.

function circularShallowEqual

circularShallowEqual: <A, B>(a: A, b: B) => boolean;
  • Whether the items passed are shallowly-equal in value, including circular references.

function createCustomEqual

createCustomEqual: <Meta = undefined>(
options?: CustomEqualCreatorOptions<Meta>
) => <A, B>(a: A, b: B) => boolean;
  • Create a custom equality comparison method.

    This can be done to create very targeted comparisons in extreme hot-path scenarios where the standard methods are not performant enough, but can also be used to provide support for legacy environments that cannot polyfill for modern features expected by fast-equals, such as WeakMap or RegExp.prototype.flags.

function deepEqual

deepEqual: <A, B>(a: A, b: B) => boolean;
  • Whether the items passed are deeply-equal in value.

function sameValueZeroEqual

sameValueZeroEqual: <A, B>(a: A, b: B) => boolean;
  • Whether the values passed are strictly equal or both NaN.

function shallowEqual

shallowEqual: <A, B>(a: A, b: B) => boolean;
  • Whether the items passed are shallowly-equal in value.

function strictCircularDeepEqual

strictCircularDeepEqual: <A, B>(a: A, b: B) => boolean;
  • Whether the items passed are deeply-equal in value, including circular references, based on strict comparison.

function strictCircularShallowEqual

strictCircularShallowEqual: <A, B>(a: A, b: B) => boolean;
  • Whether the items passed are shallowly-equal in value, including circular references, based on strict comparison.

function strictDeepEqual

strictDeepEqual: <A, B>(a: A, b: B) => boolean;
  • Whether the items passed are deeply-equal in value based on strict comparison.

function strictShallowEqual

strictShallowEqual: <A, B>(a: A, b: B) => boolean;
  • Whether the items passed are shallowly-equal in value based on strict comparison

Interfaces

interface Cache

interface Cache<Key extends object, Value> {}
  • Cache used to store references to objects, used for circular reference checks.

method delete

delete: (key: Key) => boolean;

    method get

    get: (key: Key) => Value | undefined;

      method set

      set: (key: Key, value: any) => any;

        interface CircularState

        interface CircularState<Meta> extends State<Meta> {}

          property cache

          readonly cache: Cache<any, any>;

            interface ComparatorConfig

            interface ComparatorConfig<Meta> {}

              property areArraysEqual

              areArraysEqual: TypeEqualityComparator<any, Meta>;
              • Whether the arrays passed are equal in value. In strict mode, this includes additional properties added to the array.

              property areDatesEqual

              areDatesEqual: TypeEqualityComparator<any, Meta>;
              • Whether the dates passed are equal in value.

              property areErrorsEqual

              areErrorsEqual: TypeEqualityComparator<any, Meta>;
              • Whether the errors passed are equal in value.

              property areFunctionsEqual

              areFunctionsEqual: TypeEqualityComparator<any, Meta>;
              • Whether the functions passed are equal in value.

              property areMapsEqual

              areMapsEqual: TypeEqualityComparator<any, Meta>;
              • Whether the maps passed are equal in value. In strict mode, this includes additional properties added to the map.

              property areNumbersEqual

              areNumbersEqual: TypeEqualityComparator<any, Meta>;
              • Whether the numbers passed are equal in value.

              property areObjectsEqual

              areObjectsEqual: TypeEqualityComparator<any, Meta>;
              • Whether the objects passed are equal in value. In strict mode, this includes non-enumerable properties added to the map, as well as symbol properties.

              property arePrimitiveWrappersEqual

              arePrimitiveWrappersEqual: TypeEqualityComparator<any, Meta>;
              • Whether the primitive wrappers passed are equal in value.

              property areRegExpsEqual

              areRegExpsEqual: TypeEqualityComparator<any, Meta>;
              • Whether the regexps passed are equal in value.

              property areSetsEqual

              areSetsEqual: TypeEqualityComparator<any, Meta>;
              • Whether the sets passed are equal in value. In strict mode, this includes additional properties added to the set.

              property areTypedArraysEqual

              areTypedArraysEqual: TypeEqualityComparator<any, Meta>;
              • Whether the typed arrays passed are equal in value. In strict mode, this includes additional properties added to the typed array.

              property areUrlsEqual

              areUrlsEqual: TypeEqualityComparator<any, Meta>;
              • Whether the URLs passed are equal in value.

              interface CustomEqualCreatorOptions

              interface CustomEqualCreatorOptions<Meta> {}

                property circular

                circular?: boolean;
                • Whether circular references should be supported. It causes the comparison to be slower, but for objects that have circular references it is required to avoid stack overflows.

                property createCustomConfig

                createCustomConfig?: CreateCustomComparatorConfig<Meta>;
                • Create a custom configuration of type-specific equality comparators. This receives the default configuration, which allows either replacement or supersetting of the default methods.

                property createInternalComparator

                createInternalComparator?: (
                compare: EqualityComparator<Meta>
                ) => InternalEqualityComparator<Meta>;
                • Create a custom internal comparator, which is used as an override to the default entry point for nested value equality comparisons. This is often used for doing custom logic for specific types (such as handling a specific class instance differently than other objects) or to incorporate meta in the comparison. See the recipes for examples.

                property createState

                createState?: CreateState<Meta>;
                • Create a custom state object passed between the methods. This allows for custom cache and/or meta values to be used.

                property strict

                strict?: boolean;
                • Whether the equality comparison is strict, meaning it matches all properties (including symbols and non-enumerable properties) with equal shape of descriptors.

                interface DefaultState

                interface DefaultState<Meta> extends State<Meta> {}

                  property cache

                  readonly cache: undefined;

                    interface Dictionary

                    interface Dictionary<Value = any> {}

                      property $$typeof

                      $$typeof?: any;

                        index signature

                        [key: string | symbol]: Value;

                          interface State

                          interface State<Meta> {}

                            property cache

                            readonly cache: Cache<any, any> | undefined;
                            • Cache used to identify circular references

                            property equals

                            readonly equals: InternalEqualityComparator<Meta>;
                            • Method used to determine equality of nested value.

                            property meta

                            meta: Meta;
                            • Additional value that can be used for comparisons.

                            property strict

                            readonly strict: boolean;
                            • Whether the equality comparison is strict, meaning it matches all properties (including symbols and non-enumerable properties) with equal shape of descriptors.

                            Type Aliases

                            type AnyEqualityComparator

                            type AnyEqualityComparator<Meta> = (a: any, b: any, state: State<Meta>) => boolean;

                              type CreateCustomComparatorConfig

                              type CreateCustomComparatorConfig<Meta> = (
                              config: ComparatorConfig<Meta>
                              ) => Partial<ComparatorConfig<Meta>>;

                                type CreateState

                                type CreateState<Meta> = () => {
                                cache?: Cache<any, any> | undefined;
                                meta?: Meta;
                                };

                                  type EqualityComparator

                                  type EqualityComparator<Meta> = <A, B>(a: A, b: B, state: State<Meta>) => boolean;

                                    type EqualityComparatorCreator

                                    type EqualityComparatorCreator<Meta> = (
                                    fn: EqualityComparator<Meta>
                                    ) => InternalEqualityComparator<Meta>;

                                      type InternalEqualityComparator

                                      type InternalEqualityComparator<Meta> = (
                                      a: any,
                                      b: any,
                                      indexOrKeyA: any,
                                      indexOrKeyB: any,
                                      parentA: any,
                                      parentB: any,
                                      state: State<Meta>
                                      ) => boolean;

                                        type PrimitiveWrapper

                                        type PrimitiveWrapper = Boolean | Number | String;

                                          type TypedArray

                                          type TypedArray =
                                          | Float32Array
                                          | Float64Array
                                          | Int8Array
                                          | Int16Array
                                          | Int32Array
                                          | Uint16Array
                                          | Uint32Array
                                          | Uint8Array
                                          | Uint8ClampedArray;
                                          • Type which encompasses possible instances of TypedArray classes.

                                            **NOTE**: This does not include BigInt64Array and BitUint64Array because those are part of ES2020 and not supported by certain TS configurations. If using either in areTypedArraysEqual, you can cast the instance as TypedArray and it will work as expected, because runtime checks will still work for those classes.

                                          type TypeEqualityComparator

                                          type TypeEqualityComparator<Type, Meta = undefined> = (
                                          a: Type,
                                          b: Type,
                                          state: State<Meta>
                                          ) => boolean;

                                            Package Files (1)

                                            Dependencies (0)

                                            No dependencies.

                                            Dev Dependencies (44)

                                            Peer Dependencies (0)

                                            No peer dependencies.

                                            Badge

                                            To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                            You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/fast-equals.

                                            • Markdown
                                              [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/fast-equals)
                                            • HTML
                                              <a href="https://www.jsdocs.io/package/fast-equals"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>