Skip to content
This repository was archived by the owner on Nov 21, 2024. It is now read-only.

Commit 19831d9

Browse files
author
Lucas Wojciechowski
committed
Added has and !has operators
1 parent 1459c2b commit 19831d9

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

index.js

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ function compile(filter) {
3232
op === 'none' ? '!(' + filter.slice(1).map(compile).join('||') + ')' :
3333
op === 'in' ? compileIn(filter[1], filter.slice(2)) :
3434
op === '!in' ? '!(' + compileIn(filter[1], filter.slice(2)) + ')' :
35+
op === 'has' ? compare(filter[1], undefined, '!==', false) :
36+
op === '!has' ? compare(filter[1], undefined, '===', false) :
3537
'true';
3638
return '(' + str + ')';
3739
}

test.js

+26
Original file line numberDiff line numberDiff line change
@@ -391,3 +391,29 @@ test('none', function(t) {
391391

392392
t.end();
393393
});
394+
395+
test('has', function(t) {
396+
var f = filter(['has', 'foo']);
397+
t.equal(f({properties: {foo: 0}}), true);
398+
t.equal(f({properties: {foo: 1}}), true);
399+
t.equal(f({properties: {foo: '0'}}), true);
400+
t.equal(f({properties: {foo: true}}), true);
401+
t.equal(f({properties: {foo: false}}), true);
402+
t.equal(f({properties: {foo: null}}), true);
403+
t.equal(f({properties: {foo: undefined}}), false);
404+
t.equal(f({properties: {}}), false);
405+
t.end();
406+
});
407+
408+
test('!has', function(t) {
409+
var f = filter(['!has', 'foo']);
410+
t.equal(f({properties: {foo: 0}}), false);
411+
t.equal(f({properties: {foo: 1}}), false);
412+
t.equal(f({properties: {foo: '0'}}), false);
413+
t.equal(f({properties: {foo: false}}), false);
414+
t.equal(f({properties: {foo: false}}), false);
415+
t.equal(f({properties: {foo: null}}), false);
416+
t.equal(f({properties: {foo: undefined}}), true);
417+
t.equal(f({properties: {}}), true);
418+
t.end();
419+
});

0 commit comments

Comments
 (0)