prop-list-matcher.js
2.57 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.filterPropList = exports.createPropListMatcher = void 0;
const filterPropList = {
exact(list) {
return list.filter(m => {
return m.match(/^[^\*\!]+$/);
});
},
contain(list) {
return list.filter(m => {
return m.match(/^\*.+\*$/);
}).map(m => {
return m.substr(1, m.length - 2);
});
},
endWith(list) {
return list.filter(m => {
return m.match(/^\*[^\*]+$/);
}).map(m => {
return m.substr(1);
});
},
startWith(list) {
return list.filter(m => {
return m.match(/^[^\*\!]+\*$/);
}).map(m => {
return m.substr(0, m.length - 1);
});
},
notExact(list) {
return list.filter(m => {
return m.match(/^\![^\*].*$/);
}).map(m => {
return m.substr(1);
});
},
notContain(list) {
return list.filter(m => {
return m.match(/^\!\*.+\*$/);
}).map(m => {
return m.substr(2, m.length - 3);
});
},
notEndWith(list) {
return list.filter(m => {
return m.match(/^\!\*[^\*]+$/);
}).map(m => {
return m.substr(2);
});
},
notStartWith(list) {
return list.filter(m => {
return m.match(/^\![^\*]+\*$/);
}).map(m => {
return m.substr(1, m.length - 2);
});
}
};
exports.filterPropList = filterPropList;
const createPropListMatcher = propList => {
const hasWild = propList.indexOf('*') > -1;
const matchAll = hasWild && propList.length === 1;
const lists = {
exact: filterPropList.exact(propList),
contain: filterPropList.contain(propList),
startWith: filterPropList.startWith(propList),
endWith: filterPropList.endWith(propList),
notExact: filterPropList.notExact(propList),
notContain: filterPropList.notContain(propList),
notStartWith: filterPropList.notStartWith(propList),
notEndWith: filterPropList.notEndWith(propList)
};
return function (prop) {
if (matchAll) return true;
return (hasWild || lists.exact.indexOf(prop) > -1 || lists.contain.some(m => {
return prop.indexOf(m) > -1;
}) || lists.startWith.some(m => {
return prop.indexOf(m) === 0;
}) || lists.endWith.some(m => {
return prop.indexOf(m) === prop.length - m.length;
})) && !(lists.notExact.indexOf(prop) > -1 || lists.notContain.some(m => {
return prop.indexOf(m) > -1;
}) || lists.notStartWith.some(m => {
return prop.indexOf(m) === 0;
}) || lists.notEndWith.some(m => {
return prop.indexOf(m) === prop.length - m.length;
}));
};
};
exports.createPropListMatcher = createPropListMatcher;