@monstermann/fn
Version:
A utility library for TypeScript.
20 lines • 615 B
TypeScript
//#region src/array/insertAtOrThrow.d.ts
/**
* `insertAtOrThrow(array, index, value)`
*
* Inserts `value` at the specified `index` in `array`, returning a new array with the inserted element, or throws an error if the index is out of bounds.
*
* ```ts
* insertAtOrThrow([1, 2, 3], 1, 10); // [1, 10, 2, 3]
* ```
*
* ```ts
* pipe([1, 2, 3], insertAtOrThrow(1, 10)); // [1, 10, 2, 3]
* ```
*/
declare const insertAtOrThrow: {
<T>(idx: number, value: NoInfer<T>): (target: readonly T[]) => T[];
<T>(target: readonly T[], idx: number, value: NoInfer<T>): T[];
};
//#endregion
export { insertAtOrThrow };