Skip to content

Commit

Permalink
rename to castArray
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Jul 12, 2024
1 parent fa87d49 commit d48a9ea
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/array/toArray.ts → src/array/castArray.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function toArray<T, U = never>(
export function castArray<T, U = never>(
value: T,
): T extends readonly (infer U)[] ? U[] : [T]

export function toArray<T>(value: T | readonly T[]): any {
export function castArray<T>(value: T | readonly T[]): any {
return Array.isArray(value) ? [...value] : [value]
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export function toArrayIfExists<T>(
export function castArrayIfExists<T>(
value: T | readonly T[],
): T extends any[]
? T[number][]
: T extends readonly any[]
? readonly T[number][]
: Exclude<T, null | undefined>[] | undefined

export function toArrayIfExists<T>(value: T | readonly T[]): any {
export function castArrayIfExists<T>(value: T | readonly T[]): any {
return Array.isArray(value) ? [...value] : value != null ? [value] : undefined
}

0 comments on commit d48a9ea

Please sign in to comment.