Is there a javascript library that will allow me to express object predicates in a DSL similar to MongoDB's query language? For the sake of clarity in a large program, I'd like to be able to say:
var obj = {
a: 1,
b: 'abcdefg'
}, qry = {
a: { $gt: 0 },
b: /^abc/
};
if(query(qry).matches(obj)) {
// do something appropriate since
}
instead of:
var obj = {
a: 1,
b: 'abcdefg'
};
if(obj.a>0 && qry.b.test(obj.b)) {
// do something appropriate
}
I'm using Node.js, so anything on NPM would be great. It would be an added bonus if the library can select objects out of an array as well as just matching individual objects.
I reviewed these two related questions, but they weren't particularly helpful for my situation: