-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmultiple-paths.js
57 lines (54 loc) · 1.54 KB
/
multiple-paths.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
import Nimma from 'nimma';
import objectScan from '../../../src/index.js';
const jsonpathComment = (
'[Reference](https://stackoverflow.com/questions/55497833/jsonpath-union-of-multiple-different-paths)'
);
const nimmaComment = 'Path deduplication has to be done in custom code';
export default {
_name: 'Multiple Paths',
_fixture: 'tree',
_result: [[['F.*.I', '*.G.I'], 'I'], [['*.*.A'], 'A']],
objectScanCompiled: objectScan(['F.*.I', '*.G.I', '*.*.A'], { rtn: ['matchedBy', 'property'] }),
objectScan: (v) => objectScan(['F.*.I', '*.G.I', '*.*.A'], { rtn: ['matchedBy', 'property'] })(v),
jsonpath: {
comment: jsonpathComment
},
jsonpathplus: {
comment: jsonpathComment
},
nimma: {
comment: nimmaComment,
fn: (v) => {
const result = [];
const fn = ({ path }) => {
result.push(path.slice(0));
};
new Nimma(['$.F.*.I', '$.*.G.I', '$.*.*.A']).query(v, {
'$.F.*.I': fn,
'$.*.G.I': fn,
'$.*.*.A': fn
});
return result;
},
result: [['F', 'B', 'A'], ['F', 'G', 'I'], ['F', 'G', 'I']]
},
nimmaCompiled: {
comment: nimmaComment,
fn: (() => {
const n = new Nimma(['$.F.*.I', '$.*.G.I', '$.*.*.A']);
return (v) => {
const result = [];
const fn = ({ path }) => {
result.push(path.slice(0));
};
n.query(v, {
'$.F.*.I': fn,
'$.*.G.I': fn,
'$.*.*.A': fn
});
return result;
};
})(),
result: [['F', 'B', 'A'], ['F', 'G', 'I'], ['F', 'G', 'I']]
}
};