diff --git a/index.js b/index.js index c44a890..0801576 100644 --- a/index.js +++ b/index.js @@ -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) { diff --git a/test.js b/test.js index 0e84896..46cbbbb 100644 --- a/test.js +++ b/test.js @@ -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);