Options that can be passed to compare.

interface CompareOptions<T, U> {
    equals?: ((item1: T, item2: U) => boolean);
    onMatch?: ((item1: T, item2: U, index1: number, index2: number) => void | Promise<void>);
    onMissing?: ((item: T, index: number) => void | Promise<void>);
    onNew?: ((item: U, index: number) => void | Promise<void>);
}

Type Parameters

  • T
  • U

Properties

equals?: ((item1: T, item2: U) => boolean)

A custom function for determining equality. If not specified, strict equality (===) is used.

onMatch?: ((item1: T, item2: U, index1: number, index2: number) => void | Promise<void>)

Invoked for each pair of items in the first and second arrays that are considered equivalent. Note that if there are multiple items in the second array that could match a given item in the first, the callback will only be invoked for the first match.

Type declaration

    • (item1, item2, index1, index2): void | Promise<void>
    • Parameters

      • item1: T

        The item in the first array.

      • item2: U

        The item in the second array that is equal to the first.

      • index1: number

        The index of the item in the first array.

      • index2: number

        The index of the item in the second array.

      Returns void | Promise<void>

onMissing?: ((item: T, index: number) => void | Promise<void>)

Invoked for each item in the first array that isn't in the second.

Type declaration

    • (item, index): void | Promise<void>
    • Parameters

      • item: T

        The missing item.

      • index: number

        The index of the missing item in the first array.

      Returns void | Promise<void>

onNew?: ((item: U, index: number) => void | Promise<void>)

Invoked for each item in the second array that isn't in the first.

Type declaration

    • (item, index): void | Promise<void>
    • Parameters

      • item: U

        The new item.

      • index: number

        The index of the new item in the second array.

      Returns void | Promise<void>