fix: contains regression (#677)

* fix: `contains` regression on string-like objects, #675

* chore: fix build docs on macos
This commit is contained in:
Jun Yang
2024-03-21 23:56:10 +08:00
committed by GitHub
parent 01029aba87
commit 05223c4378
3 changed files with 19 additions and 14 deletions
+2 -2
View File
@@ -2,7 +2,7 @@ import { isComparable } from '../drop/comparable'
import { Context } from '../context'
import { toValue } from '../util'
import { isFalsy, isTruthy } from '../render/boolean'
import { isArray, isString } from '../util/underscore'
import { isArray, isFunction } from '../util/underscore'
export type UnaryOperatorHandler = (operand: any, ctx: Context) => boolean;
export type BinaryOperatorHandler = (lhs: any, rhs: any, ctx: Context) => boolean;
@@ -35,7 +35,7 @@ export const defaultOperators: Operators = {
'contains': (l: any, r: any) => {
l = toValue(l)
if (isArray(l)) return l.some((i) => equal(i, r))
if (isString(l)) return l.indexOf(toValue(r)) > -1
if (isFunction(l?.indexOf)) return l.indexOf(toValue(r)) > -1
return false
},
'not': (v: any, ctx: Context) => isFalsy(toValue(v), ctx),