fix: contains operator does not support Drop, fixes #492

This commit is contained in:
Harttle
2022-04-18 00:43:18 +08:00
parent eec381ec72
commit 9e024ff2bc
3 changed files with 21 additions and 2 deletions
+3 -1
View File
@@ -1,6 +1,6 @@
import { isComparable } from '../drop/comparable'
import { Context } from '../context/context'
import { isFunction } from '../util/underscore'
import { isFunction, toValue } from '../util/underscore'
import { isTruthy } from '../render/boolean'
export interface Operators {
@@ -39,6 +39,8 @@ export const defaultOperators: Operators = {
return l <= r
},
'contains': (l: any, r: any) => {
l = toValue(l)
r = toValue(r)
return l && isFunction(l.indexOf) ? l.indexOf(r) > -1 : false
},
'and': (l: any, r: any, ctx: Context) => isTruthy(l, ctx) && isTruthy(r, ctx),