-
Notifications
You must be signed in to change notification settings - Fork 16
/
regex.js
50 lines (49 loc) · 1.39 KB
/
regex.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
import { JSONPath } from 'jsonpath-plus';
import Nimma from 'nimma';
import objectScan from '../../../src/index.js';
export default {
_name: 'Regex',
_fixture: 'foo',
objectScanCompiled: {
fn: objectScan(['entries.(fo+bar)']),
result: [['entries', 'fooooobar'], ['entries', 'foobar']]
},
objectScan: {
fn: (v) => objectScan(['entries.(fo+bar)'])(v),
result: [['entries', 'fooooobar'], ['entries', 'foobar']]
},
jsonpathplus: {
fn: (v) => JSONPath({ path: '$.entries.[?(@property.match(/fo+bar/))]', json: v, resultType: 'path' }),
result: [
"$['entries']['foobar']",
"$['entries']['fooooobar']"
]
},
nimma: {
fn: (v) => {
const result = [];
new Nimma(['$.entries.[?(@property.match(/fo+bar/))]']).query(v, {
'$.entries.[?(@property.match(/fo+bar/))]': ({ path }) => {
result.push(path.slice(0));
}
});
return result;
},
result: [['entries', 'foobar'], ['entries', 'fooooobar']]
},
nimmaCompiled: {
fn: (() => {
const n = new Nimma(['$.entries.[?(@property.match(/fo+bar/))]']);
return (v) => {
const result = [];
n.query(v, {
'$.entries.[?(@property.match(/fo+bar/))]': ({ path }) => {
result.push(path.slice(0));
}
});
return result;
};
})(),
result: [['entries', 'foobar'], ['entries', 'fooooobar']]
}
};