MCPcopy Create free account
hub / github.com/facebook/Rapid / _parseHashParam

Method _parseHashParam

modules/core/ValidationSystem.js:175–193  ·  view source on GitHub ↗

* _parseHashParam * Converts hash parameters for severity overrides to regex matchers * @param {String} val - The value retrieved, e.g. `crossing_ways/bridge*,crossing_ways/tunnel*` * @return {Array} Array of Objects like { type: RegExp, subtype: RegExp }

(val = '')

Source from the content-addressed store, hash-verified

173 * @return {Array} Array of Objects like { type: RegExp, subtype: RegExp }
174 */
175 _parseHashParam(val = '') {
176 let result = [];
177 const rules = val.split(',').map(s => s.trim()).filter(Boolean);
178 for (const rule of rules) {
179 const parts = rule.split('/', 2); // "type/subtype"
180 const type = parts[0];
181 const subtype = parts[1] ?? '*';
182 if (!type || !subtype) continue;
183 result.push({ type: makeRegExp(type), subtype: makeRegExp(subtype) });
184 }
185 return result;
186
187 function makeRegExp(str) {
188 const escaped = str
189 .replace(/[-\/\\^$+?.()|[\]{}]/g, '\\$&') // escape all reserved chars except for the '*'
190 .replace(/\*/g, '.*'); // treat a '*' like '.*'
191 return new RegExp(`^${escaped}$`);
192 }
193 }
194
195
196 /**

Callers 1

initAsyncMethod · 0.95

Calls 2

filterMethod · 0.80
splitMethod · 0.80

Tested by

no test coverage detected