MCPcopy Index your code
hub / github.com/debug-js/debug / matchesTemplate

Function matchesTemplate

src/common.js:192–225  ·  view source on GitHub ↗

* Checks if the given string matches a namespace template, honoring * asterisks as wildcards. * * @param {String} search * @param {String} template * @return {Boolean}

(search, template)

Source from the content-addressed store, hash-verified

190 * @return {Boolean}
191 */
192 function matchesTemplate(search, template) {
193 let searchIndex = 0;
194 let templateIndex = 0;
195 let starIndex = -1;
196 let matchIndex = 0;
197
198 while (searchIndex < search.length) {
199 if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === '*')) {
200 // Match character or proceed with wildcard
201 if (template[templateIndex] === '*') {
202 starIndex = templateIndex;
203 matchIndex = searchIndex;
204 templateIndex++; // Skip the '*'
205 } else {
206 searchIndex++;
207 templateIndex++;
208 }
209 } else if (starIndex !== -1) { // eslint-disable-line no-negated-condition
210 // Backtrack to the last '*' and try to match more characters
211 templateIndex = starIndex + 1;
212 matchIndex++;
213 searchIndex = matchIndex;
214 } else {
215 return false; // No match
216 }
217 }
218
219 // Handle trailing '*' in template
220 while (templateIndex < template.length && template[templateIndex] === '*') {
221 templateIndex++;
222 }
223
224 return templateIndex === template.length;
225 }
226
227 /**
228 * Disable debug output.

Callers 1

enabledFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…