import { PlainObject } from "../models.mjs"; //#region src/array/swap.d.ts /** * Swap two smaller arrays within a larger array * * If either of the smaller arrays are not present in the larger array, or if they overlap, the larger array will be returned unchanged * * @param array Array of items to swap * @param first First array * @param second Second array * @param callback Callback to get an item's value for matching * @returns Original array with items swapped _(or unchanged if unable to swap)_ * * @example * ```typescript * swap( * [ * {id: 1, name: 'Alice'}, * {id: 2, name: 'Bob'}, * {id: 3, name: 'Charlie'}, * ], * [ * {id: 2, name: 'Bob'}, * ], * [ * {id: 3, name: 'Charlie'}, * ], * item => item.id, * ); // => [ * // {id: 1, name: 'Alice'}, * // {id: 3, name: 'Charlie'}, * // {id: 2, name: 'Bob'}, * // ] * ``` */ declare function swap(array: Item[], first: Item[], second: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[]; /** * Swap two smaller arrays within a larger array * * If either of the smaller arrays are not present in the larger array, or if they overlap, the larger array will be returned unchanged * * @param array Array of items to swap * @param first First array * @param second Second array * @param key Key to get an item's value for matching * @returns Original array with items swapped _(or unchanged if unable to swap)_ * * @example * ```typescript * swap( * [ * {id: 1, name: 'Alice'}, * {id: 2, name: 'Bob'}, * {id: 3, name: 'Charlie'}, * ], * [ * {id: 2, name: 'Bob'}, * ], * [ * {id: 3, name: 'Charlie'}, * ], * 'id', * ); // => [ * // {id: 1, name: 'Alice'}, * // {id: 3, name: 'Charlie'}, * // {id: 2, name: 'Bob'}, * // ] * ``` */ declare function swap(array: Item[], first: Item[], second: Item[], key: ItemKey): Item[]; /** * Swap two smaller arrays within a larger array * * If either of the smaller arrays are not present in the larger array, or if they overlap, the larger array will be returned unchanged * * @param array Array of items to swap * @param first First array * @param second Second array * @returns Original array with items swapped _(or unchanged if unable to swap)_ * * @example * ```typescript * swap( * [1, 2, 3, 4, 5, 6], * [1, 2], * [5, 6], * ); // => [5, 6, 3, 4, 1, 2] * ``` */ declare function swap(array: Item[], first: Item[], second: Item[]): Item[]; /** * Swap two indiced items in an array * * If either of the items are not present in the array, the array will be returned unchanged * * @param array Array of items to swap * @param first First item * @param second Second item * @param callback Callback to get an item's value for matching * @returns Original array with items swapped _(or unchanged if unable to swap)_ * * @example * ```typescript * swap( * [ * {id: 1, name: 'Alice'}, * {id: 2, name: 'Bob'}, * {id: 3, name: 'Charlie'}, * ], * {id: 2, name: 'Bob'}, * {id: 3, name: 'Charlie'}, * item => item.id, * ); // => [ * // {id: 1, name: 'Alice'}, * // {id: 3, name: 'Charlie'}, * // {id: 2, name: 'Bob'}, * // ] * ``` */ declare function swap(array: Item[], first: Item, second: Item, callback: (item: Item, index: number, array: Item[]) => unknown): Item[]; /** * Swap two indiced items in an array * * If either of the items are not present in the array, the array will be returned unchanged * * @param array Array of items to swap * @param first First item * @param second Second item * @param key Key to get an item's value for matching * @returns Original array with items swapped _(or unchanged if unable to swap)_ * * @example * ```typescript * swap( * [ * {id: 1, name: 'Alice'}, * {id: 2, name: 'Bob'}, * {id: 3, name: 'Charlie'}, * ], * {id: 2, name: 'Bob'}, * {id: 3, name: 'Charlie'}, * 'id', * ); // => [ * // {id: 1, name: 'Alice'}, * // {id: 3, name: 'Charlie'}, * // {id: 2, name: 'Bob'}, * // ] * ``` */ declare function swap(array: Item[], first: Item, second: Item, key: ItemKey): Item[]; /** * Swap two indiced items in an array * * @param array Array of items to swap * @param first First item * @param second Second item * @returns Original array with items swapped _(or unchanged if unable to swap)_ * * @example * ```typescript * swap( * [1, 2, 3, 4, 5, 6], * 2, * 5, * ); // => [1, 5, 3, 4, 2, 6] * ``` */ declare function swap(array: Item[], first: Item, second: Item): Item[]; declare namespace swap { var indices: typeof swapIndices; } /** * Swap two indiced items in an array * * If either index is out of bounds, the array will be returned unchanged * * _Available as `swapIndices` and `swap.indices`_ * * @param array Array of items to swap * @param first First index _(can be negative to count from the end)_ * @param second Second index _(can be negative to count from the end)_ * @returns Original array with items swapped _(or unchanged if unable to swap)_ */ declare function swapIndices(array: Item[], first: number, second: number): Item[]; //#endregion export { swap };