UNPKG

479 BJavaScriptView Raw
1var jpath = require('..')
2, expect = require('expect.js')
3, data = require('./example-data')
4
5var p = jpath.create("#/store/book[*][@]");
6
7var res = p.resolve(data, function(obj, accum) {
8 if (typeof obj.price === 'number' && obj.price < 10)
9 accum.push(obj);
10 return accum;
11});
12
13// Expect the result to have the two books priced under $10...
14expect(res).to.contain(data["store"]["book"][0]);
15expect(res).to.contain(data["store"]["book"][2]);
16expect(res).to.have.length(2);