mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
Test if an array contains a specific number/string.
This commit is contained in:
+7
-1
@@ -5,7 +5,13 @@ var operators = {
|
||||
'<': (l, r) => l < r,
|
||||
'>=': (l, r) => l >= r,
|
||||
'<=': (l, r) => l <= r,
|
||||
'contains': (l, r) => typeof l === 'string' ? l.indexOf(r) > -1 : false,
|
||||
'contains': (l, r) => {
|
||||
return typeof l !== 'undefined'
|
||||
? typeof l.indexOf === 'function'
|
||||
? l.indexOf(r) > -1
|
||||
: false
|
||||
: false;
|
||||
},
|
||||
'and': (l, r) => l && r,
|
||||
'or': (l, r) => l || r
|
||||
};
|
||||
|
||||
@@ -45,6 +45,8 @@ describe('expression', function() {
|
||||
expect(evalExp('x contains "X"', scope)).to.equal(true);
|
||||
expect(evalExp('1 contains "x"', scope)).to.equal(false);
|
||||
expect(evalExp('y contains "x"', scope)).to.equal(false);
|
||||
expect(evalExp('(1..5) contains 3', scope)).to.equal(true);
|
||||
expect(evalExp('(1..5) contains 6', scope)).to.equal(false);
|
||||
expect(evalExp('"<=" == "<="', scope)).to.equal(true);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user