fix: some filters throw on nil input, see #481

This commit is contained in:
Harttle
2022-02-27 02:07:59 +08:00
parent 21b78d9ba0
commit 7dfb620d30
14 changed files with 182 additions and 93 deletions
+2 -1
View File
@@ -1,4 +1,4 @@
import { isString, isObject, isArray } from './underscore'
import { isNil, isString, isObject, isArray } from './underscore'
export function toEnumerable (val: any) {
if (isArray(val)) return val
@@ -8,6 +8,7 @@ export function toEnumerable (val: any) {
}
export function toArray (val: any) {
if (isNil(val)) return []
if (isArray(val)) return val
return [ val ]
}
+7 -1
View File
@@ -3,6 +3,8 @@ import { Drop } from '../drop/drop'
const toStr = Object.prototype.toString
const toLowerCase = String.prototype.toLowerCase
export const hasOwnProperty = Object.hasOwnProperty
export function isString (value: any): value is string {
return typeof value === 'string'
}
@@ -72,7 +74,7 @@ export function forOwn <T> (
) {
obj = obj || {}
for (const k in obj) {
if (Object.hasOwnProperty.call(obj, k)) {
if (hasOwnProperty.call(obj, k)) {
if (iteratee(obj[k], k, obj) === false) break
}
}
@@ -150,3 +152,7 @@ export function caseInsensitiveCompare (a: any, b: any) {
if (a > b) return 1
return 0
}
export function argumentsToValue<F extends (...args: any) => any> (fn: F) {
return (...args: Parameters<F>) => fn(...args.map(toValue))
}