1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | Object.defineProperty(exports, "__esModule", { value: true });
|
7 | exports.filterByKey = exports.filterByTag = exports.includesTagValue = exports.ANY_TAG_VALUE = exports.isBindingTagFilter = exports.isBindingAddress = void 0;
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | function isBindingKey(selector) {
|
13 | if (selector == null || typeof selector !== 'object')
|
14 | return false;
|
15 | return (typeof selector.key === 'string' &&
|
16 | typeof selector.deepProperty === 'function');
|
17 | }
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | function isBindingAddress(bindingSelector) {
|
23 | return (typeof bindingSelector !== 'function' &&
|
24 | (typeof bindingSelector === 'string' ||
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | isBindingKey(bindingSelector)));
|
30 | }
|
31 | exports.isBindingAddress = isBindingAddress;
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | function isBindingTagFilter(filter) {
|
37 | if (filter == null || !('bindingTagPattern' in filter))
|
38 | return false;
|
39 |
|
40 | const tagPattern = filter.bindingTagPattern;
|
41 | return (tagPattern instanceof RegExp ||
|
42 | typeof tagPattern === 'string' ||
|
43 | typeof tagPattern === 'object');
|
44 | }
|
45 | exports.isBindingTagFilter = isBindingTagFilter;
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | const ANY_TAG_VALUE = (tagValue, tagName, tagMap) => tagName in tagMap;
|
61 | exports.ANY_TAG_VALUE = ANY_TAG_VALUE;
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | function includesTagValue(...itemValues) {
|
68 | return tagValue => {
|
69 | return itemValues.some(itemValue =>
|
70 |
|
71 | tagValue === itemValue ||
|
72 |
|
73 | (Array.isArray(tagValue) && tagValue.includes(itemValue)));
|
74 | };
|
75 | }
|
76 | exports.includesTagValue = includesTagValue;
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | function filterByTag(tagPattern) {
|
82 | let filter;
|
83 | let regex = undefined;
|
84 | if (tagPattern instanceof RegExp) {
|
85 |
|
86 | regex = tagPattern;
|
87 | }
|
88 | if (typeof tagPattern === 'string' &&
|
89 | (tagPattern.includes('*') || tagPattern.includes('?'))) {
|
90 |
|
91 | regex = wildcardToRegExp(tagPattern);
|
92 | }
|
93 | if (regex != null) {
|
94 |
|
95 | filter = b => b.tagNames.some(t => regex.test(t));
|
96 | }
|
97 | else if (typeof tagPattern === 'string') {
|
98 |
|
99 | filter = b => b.tagNames.includes(tagPattern);
|
100 | }
|
101 | else {
|
102 |
|
103 | const tagMap = tagPattern;
|
104 | filter = b => {
|
105 | for (const t in tagMap) {
|
106 | if (!matchTagValue(tagMap[t], t, b.tagMap))
|
107 | return false;
|
108 | }
|
109 |
|
110 | return true;
|
111 | };
|
112 | }
|
113 |
|
114 | const tagFilter = filter;
|
115 | tagFilter.bindingTagPattern = regex !== null && regex !== void 0 ? regex : tagPattern;
|
116 | return tagFilter;
|
117 | }
|
118 | exports.filterByTag = filterByTag;
|
119 | function matchTagValue(tagValueOrMatcher, tagName, tagMap) {
|
120 | const tagValue = tagMap[tagName];
|
121 | if (tagValue === tagValueOrMatcher)
|
122 | return true;
|
123 | if (typeof tagValueOrMatcher === 'function') {
|
124 | return tagValueOrMatcher(tagValue, tagName, tagMap);
|
125 | }
|
126 | return false;
|
127 | }
|
128 |
|
129 |
|
130 |
|
131 |
|
132 | function filterByKey(keyPattern) {
|
133 | if (typeof keyPattern === 'string') {
|
134 | const regex = wildcardToRegExp(keyPattern);
|
135 | return binding => regex.test(binding.key);
|
136 | }
|
137 | else if (keyPattern instanceof RegExp) {
|
138 | return binding => keyPattern.test(binding.key);
|
139 | }
|
140 | else if (typeof keyPattern === 'function') {
|
141 | return keyPattern;
|
142 | }
|
143 | return () => true;
|
144 | }
|
145 | exports.filterByKey = filterByKey;
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 | function wildcardToRegExp(pattern) {
|
153 |
|
154 |
|
155 | let regexp = pattern.replace(/[\-\[\]\/\{\}\(\)\+\.\\\^\$\|\:]/g, '\\$&');
|
156 |
|
157 |
|
158 |
|
159 | regexp = regexp.replace(/\*/g, '[^.:]*').replace(/\?/g, '[^.:]');
|
160 | return new RegExp(`^${regexp}$`);
|
161 | }
|
162 |
|
\ | No newline at end of file |