nodejs/README.md - 정리, version 0.1.1

This commit is contained in:
freestrings
2019-03-26 18:28:54 +09:00
parent 5e29b5e7a7
commit 3e3d9e8770
3 changed files with 163 additions and 3 deletions

View File

@ -27,4 +27,73 @@ describe('select test', () => {
done();
}
});
});
describe('filter test', () => {
it('complex filter1', (done) => {
let json = {
'store': {
'book': [
{
'category': 'reference',
'author': 'Nigel Rees',
'title': 'Sayings of the Century',
'price': 8.95,
},
{
'category': 'fiction',
'author': 'Evelyn Waugh',
'title': 'Sword of Honour',
'price': 12.99,
},
{
'category': 'fiction',
'author': 'Herman Melville',
'title': 'Moby Dick',
'isbn': '0-553-21311-3',
'price': 8.99,
},
{
'category': 'fiction',
'author': 'J. R. R. Tolkien',
'title': 'The Lord of the Rings',
'isbn': '0-395-19395-8',
'price': 22.99,
},
],
'bicycle': {
'color': 'red',
'price': 19.95,
},
},
'expensive': 10,
};
let target = [
{
category: 'fiction',
author: 'Evelyn Waugh',
title: 'Sword of Honour',
price: 12.99,
},
{
category: 'fiction',
author: 'J. R. R. Tolkien',
title: 'The Lord of the Rings',
isbn: '0-395-19395-8',
price: 22.99,
},
{
category: 'reference',
author: 'Nigel Rees',
title: 'Sayings of the Century',
price: 8.95,
}]
;
let result = jsonpath.select(json, '$..book[?((@.price == 12.99 || $.store.bicycle.price < @.price) || @.category == "reference")]');
if (JSON.stringify(result) === JSON.stringify(target)) {
done();
}
});
});