element-plus/packages/utils/arrays.ts
Jungzl 7bba5332f1
chore: update dependencies (#18573)
* chore: update dependencies

typescript: v5.5
vue-tsc: v2
eslint: v8-latest
@commitlint/*: v18

* fix: apply suggestions

* fix: ignore some ts errors
2024-10-29 10:01:58 +08:00

16 lines
483 B
TypeScript

import { isArray } from './types'
export const unique = <T>(arr: T[]) => [...new Set(arr)]
type Many<T> = T | ReadonlyArray<T>
// TODO: rename to `ensureArray`
/** like `_.castArray`, except falsy value returns empty array. */
export const castArray = <T>(arr: Many<T>): T[] => {
if (!arr && (arr as any) !== 0) return []
return isArray(arr) ? arr : [arr as T]
}
// TODO: remove import alias
// avoid naming conflicts
export { castArray as ensureArray } from 'lodash-unified'