import { PlainObject } from "../models.mjs"; //#region src/array/last.d.ts /** * Get the last items matching the given value * * @param array Array to search in * @param callback Callback to get an item's value for matching * @param value Value to match against * @returns Last item that matches the value, or `undefined` if no match is found * * @example * ```typescript * last( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * 10, * ); // => {id: 3, value: 10} * ``` */ declare function last unknown>(array: Item[], callback: Callback, value: ReturnType): Item | undefined; /** * Get the first item matching the given value by key * * @param array Array to search in * @param key Key to get an item's value for matching * @param value Value to match against * @returns Last item that matches the value, or `undefined` if no match is found * * @example * ```typescript * last( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * 10, * ); // => {id: 3, value: 10} * ``` */ declare function last(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined; /** * Get the last item matching the filter * * @param array Array to search in * @param filter Filter callback to match items * @returns Last item that matches the filter, or `undefined` if no match is found * * @example * ```typescript * last( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value === 10, * ); // => {id: 3, value: 10} * ``` */ declare function last(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item | undefined; /** * Get the last item from an array * * @param array Array to get from * @returns Last item from the array, or `undefined` if the array is empty * * @example * ```typescript * last([1, 2, 3]); // => 3 * ``` */ declare function last(array: Item[]): Item | undefined; declare namespace last { var _a: typeof lastOrDefault; export { _a as default }; } /** * Get the last item matching the given value * * _Available as `lastOrDefault` and `last.default`_ * * @param array Array to search in * @param defaultValue Default value to return if no match is found * @param callback Callback to get an item's value for matching * @param value Value to match against * @returns Last item that matches the value, or the default value if no match is found * * @example * ```typescript * lastOrDefault( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * {id: -1, value: 30}, * item => item.value, * 30, * ); // => {id: -1, value: 30} * ``` */ declare function lastOrDefault unknown>(array: Item[], defaultValue: Item, callback: Callback, value: ReturnType): Item; /** * Get the last item matching the given value by key * * _Available as `lastOrDefault` and `last.default`_ * * @param array Array to search in * @param defaultValue Default value to return if no match is found * @param key Key to get an item's value for matching * @param value Value to match against * @returns Last item that matches the value, or the default value if no match is found * * @example * ```typescript * lastOrDefault( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * {id: -1, value: 30}, * 'value', * 30, * ); // => {id: -1, value: 30} * ``` */ declare function lastOrDefault(array: Item[], defaultValue: Item, key: ItemKey, value: Item[ItemKey]): Item; /** * Get the last item matching the filter * * _Available as `lastOrDefault` and `last.default`_ * * @param array Array to search in * @param defaultValue Default value to return if no match is found * @param filter Filter callback to match items * @returns Last item that matches the filter, or the default value if no match is found * * @example * ```typescript * lastOrDefault( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * {id: -1, value: 30}, * item => item.value === 30, * ); // => {id: -1, value: 30} * ``` */ declare function lastOrDefault(array: Item[], defaultValue: Item, filter: (item: Item, index: number, array: Item[]) => boolean): Item; /** * Get the last item from an array * * _Available as `lastOrDefault` and `last.default`_ * * @param array Array to get from * @param defaultValue Default value to return if the array is empty * @returns Last item from the array, or the default value if the array is empty * * @example * ```typescript * lastOrDefault([], {id: -1, value: 30}); // => {id: -1, value: 30} * ``` */ declare function lastOrDefault(array: Item[], defaultValue: Item): Item; //#endregion export { last, lastOrDefault };