mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-17 05:10:40 -07:00
fix: some filters throw on nil input, see #481
This commit is contained in:
@@ -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 ]
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user