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

Commit

Permalink
Add support for $id key
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Jul 18, 2016
1 parent e953226 commit 019f1a0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ function compile(filter) {
}

function compilePropertyReference(property) {
return property === '$type' ? 'f.type' : 'p[' + JSON.stringify(property) + ']';
return property === '$type' ? 'f.type' :
property === '$id' ? 'f.id' :
'p[' + JSON.stringify(property) + ']';
}

function compileComparisonOp(property, value, op, checkType) {
Expand Down
10 changes: 10 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ test('==, $type', function(t) {
t.end();
});

test('==, $id', function(t) {
var f = filter(['==', '$id', 1234]);

t.equal(f({id: 1234}), true);
t.equal(f({id: '1234'}), false);
t.equal(f({properties: {id: 1234}}), false);

t.end();
});

test('!=, string', function(t) {
var f = filter(['!=', 'foo', 'bar']);
t.equal(f({properties: {foo: 'bar'}}), false);
Expand Down

0 comments on commit 019f1a0

Please sign in to comment.