/** * Replace Items Options Interface * * @template T typeof the items of the array */ export interface ReplaceItemsOptions { /** * Starting index of the array for replacement operation * * @default 0 */ startingIndex?: number; /** * Determines how many items will be deleted from the array * * @default 1 */ deleteCount?: number; /** * Items to replace * * @default [] */ itemsToReplace?: T[]; } /** * Replace by Item Matcher Map Options Interface * * @template T typeof the items of the array */ export interface ReplaceByMapOptions { /** * Items' Matcher Map to replace */ itemsToReplace: Map; /** * Set as `true` to replace all items in the array if matches with the key of the matcher map while iterating * * @default false */ multi?: boolean; } /** * #### Replace * * Replaces an item with passed one of an array * * * * * * Example: * ```typescript * import { replace } from "@thalesrc/js-utils/array"; * * const array = ["a", "b", "c", "a", "b", "c"]; * * replace(array, "b", "x"); // ["a", "x", "c", "a", "b", "c"] * ``` * * Array Prototype Example: * ```typescript * import "@thalesrc/js-utils/array/proto/replace"; * * const array = ["a", "b", "c", "a", "b", "c"]; * * array.replace("b", "x"); // ["a", "x", "c", "a", "b", "c"] * ``` * * * * * @param array Array to replace its item * @param itemToRemove Item to remove * @param itemToReplace Item to replace with * @template T Typeof array items * @return New replaced array */ export declare function replace(array: T[], itemToRemove: T, itemToReplace: T): T[]; /** * #### Replace * * Deletes items and replaces new ones from passed starting index of an array * * * * * * Example: * ```typescript * import { replace } from "@thalesrc/js-utils"; * * const array = ["a", "b", "c", "a", "b", "c"]; * * replace(array, {startingIndex: 3, deleteCount: 1, itemsToReplace: ['x', 'y']}); // ["a", "b", "c", "x", "y", "b", "c"]; * ``` * Array Prototype Example: * ```typescript * import "@thalesrc/js-utils/dist/as-proto/array-replace"; * * const array = ["a", "b", "c", "a", "b", "c"]; * * array.replace({startingIndex: 3, deleteCount: 1, itemsToReplace: ['x', 'y']}); // ["a", "b", "c", "x", "y", "b", "c"]; * ``` * * * * * @param array Array to replace its item * @param replaceOptions Replace options * @template T Typeof array items * @return New replaced array */ export declare function replace(array: T[], replaceOptions: ReplaceItemsOptions): T[]; /** * #### Replace * * Deletes items and replaces new ones by passed matcher map * * * * * * Example: * ```typescript * import { replace } from "@thalesrc/js-utils"; * * const array = ["a", "b", "c", "a", "b", "c"]; * const map = new Map(); * map.set("a", "x") * map.set("b", "y"); * * replace(array, {itemsToReplace: map}); // ["x", "y", "c", "a", "b", "c"]; * replace(array, {itemsToReplace: map, multi: true}); // ["x", "y", "c", "x", "y", "c"]; * ``` * Array Prototype Example: * ```typescript * import "@thalesrc/js-utils/dist/as-proto/array-replace"; * * const array = ["a", "b", "c", "a", "b", "c"]; * const map = new Map(); * map.set("a", "x") * map.set("b", "y"); * * array.replace({itemsToReplace: map}); // ["x", "y", "c", "a", "b", "c"]; * array.replace({itemsToReplace: map, multi: true}); // ["x", "y", "c", "x", "y", "c"]; * ``` * * * * * @param array Array to replace its item * @param replaceOptions Replace options * @template T Typeof array items * @return New replaced array */ export declare function replace(array: T[], replaceOptions: ReplaceByMapOptions): T[];