-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathvalue.js
46 lines (45 loc) · 1.03 KB
/
value.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import jmespath from 'jmespath';
import jsonpath from 'jsonpath';
import { JSONPath } from 'jsonpath-plus';
import Nimma from 'nimma';
import objectScan from '../../../src/index.js';
export default {
_name: 'Get Value',
_fixture: 'cond',
_result: 2,
objectScanCompiled: objectScan([['a', 0, 'y']], {
rtn: 'value',
abort: true
}),
objectScan: (v) => objectScan([['a', 0, 'y']], {
rtn: 'value',
abort: true
})(v),
jsonpath: (v) => jsonpath.value(v, '$.a[0].y'),
jsonpathplus: {
fn: (v) => JSONPath({ path: '$.a[0].y', json: v }),
result: [2]
},
jmespath: (v) => jmespath.search(v, 'a[0].y'),
nimma: (v) => {
let result;
new Nimma(['$.a[0].y']).query(v, {
'$.a[0].y': ({ value }) => {
result = value;
}
});
return result;
},
nimmaCompiled: (() => {
const n = new Nimma(['$.a[0].y']);
return (v) => {
let result;
n.query(v, {
'$.a[0].y': ({ value }) => {
result = value;
}
});
return result;
};
})()
};