2022-02-11 11:03:15 +08:00
|
|
|
export const unique = <T>(arr: T[]) => [...new Set(arr)]
|
|
|
|
|
2022-05-25 23:05:17 +08:00
|
|
|
type Many<T> = T | ReadonlyArray<T>
|
2022-03-01 20:44:32 +08:00
|
|
|
// TODO: rename to `ensureArray`
|
2022-02-11 11:03:15 +08:00
|
|
|
/** like `_.castArray`, except falsy value returns empty array. */
|
2022-05-25 23:05:17 +08:00
|
|
|
export const castArray = <T>(arr: Many<T>): T[] => {
|
|
|
|
if (!arr && (arr as any) !== 0) return []
|
2022-02-11 11:03:15 +08:00
|
|
|
return Array.isArray(arr) ? arr : [arr]
|
|
|
|
}
|
2022-03-01 20:44:32 +08:00
|
|
|
|
|
|
|
// TODO: remove import alias
|
|
|
|
// avoid naming conflicts
|
|
|
|
export { castArray as ensureArray } from 'lodash-unified'
|