fix: coerce to Array in map and where filter

This commit is contained in:
harttle
2020-04-01 02:22:44 +08:00
parent d65ed408f0
commit c923598b40
12 changed files with 187 additions and 284 deletions
+6 -1
View File
@@ -1,8 +1,13 @@
import { isString, isObject, isArray } from './underscore'
export function toCollection (val: any) {
export function toEnumerable (val: any) {
if (isArray(val)) return val
if (isString(val) && val.length > 0) return [val]
if (isObject(val)) return Object.keys(val).map((key) => [key, val[key]])
return []
}
export function toArray (val: any) {
if (isArray(val)) return val
return [ val ]
}