fix: don't mutate user provided array (#10014)

* fix(builders): don't mutate user provided array

* test: add normalize array tests

* chore: revert vscode autochange

* Update util.test.ts

* refactor: remove unnecessary clone

---------

Co-authored-by: Vlad Frangu <me@vladfrangu.dev>
Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
Co-authored-by: Almeida <github@almeidx.dev>
This commit is contained in:
Parbez
2024-05-01 02:16:21 +05:30
committed by GitHub
parent 798f28cb9b
commit 7ea3638dbc
3 changed files with 19 additions and 3 deletions

View File

@@ -5,7 +5,7 @@
* @param arr - The (possibly variadic) data to normalize
*/
export function normalizeArray<ItemType>(arr: RestOrArray<ItemType>): ItemType[] {
if (Array.isArray(arr[0])) return arr[0];
if (Array.isArray(arr[0])) return [...arr[0]];
return arr as ItemType[];
}