test: improve utils coverage (#4230)

* test: improve utils coverage

* refactor: review - rename isDefined to isNonNullable, update tests and return statement
This commit is contained in:
Thaïs
2024-02-29 13:03:52 -03:00
committed by GitHub
parent 6ec0e5e995
commit 30df6c10ea
85 changed files with 396 additions and 240 deletions

View File

@ -1,5 +1,19 @@
export const moveArrayItem = <Item>(
array: Item[],
/**
* Moves an item in an array from one index to another.
*
* @param array - The array to move an item in.
* @param indices - The indices to move the item from and to.
* @param indices.fromIndex - The index to move the item from.
* @param indices.toIndex - The index to move the item to.
*
* @returns A new array with the item moved to the new index.
*
* @example
* moveArrayItem(['a', 'b', 'c'], { fromIndex: 0, toIndex: 2 })
* => ['b', 'c', 'a']
*/
export const moveArrayItem = <ArrayItem>(
array: ArrayItem[],
{ fromIndex, toIndex }: { fromIndex: number; toIndex: number },
) => {
if (!(fromIndex in array) || !(toIndex in array) || fromIndex === toIndex) {