-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathkey.js
67 lines (66 loc) · 1.35 KB
/
key.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import jsonpath from 'jsonpath';
import { JSONPath } from 'jsonpath-plus';
import Nimma from 'nimma';
import objectScan from '../../../src/index.js';
export default {
_name: 'Get Key',
_fixture: 'cond',
objectScanCompiled: {
fn: objectScan(['*[*].y']),
result: [
['b', 0, 'y'],
['a', 0, 'y']
]
},
objectScan: {
fn: (v) => objectScan(['*[*].y'])(v),
result: [
['b', 0, 'y'],
['a', 0, 'y']
]
},
jsonpath: {
fn: (v) => jsonpath.paths(v, '$.*[*].y'),
result: [
['$', 'a', 0, 'y'],
['$', 'b', 0, 'y']
]
},
jsonpathplus: {
fn: (v) => JSONPath({ path: '$.*[*].y', json: v, resultType: 'path' }),
result: ["$['a'][0]['y']", "$['b'][0]['y']"]
},
nimma: {
fn: (v) => {
const result = [];
new Nimma(['$.*[*].y']).query(v, {
'$.*[*].y': ({ path }) => {
result.push(path.slice(0));
}
});
return result;
},
result: [
['a', 0, 'y'],
['b', 0, 'y']
]
},
nimmaCompiled: {
fn: (() => {
const n = new Nimma(['$.*[*].y']);
return (v) => {
const result = [];
n.query(v, {
'$.*[*].y': ({ path }) => {
result.push(path.slice(0));
}
});
return result;
};
})(),
result: [
['a', 0, 'y'],
['b', 0, 'y']
]
}
};