MCPcopy Create free account
hub / github.com/Snapchat/Valdi / createTargetFilter

Function createTargetFilter

valdi/vscode_debugger/src/common/urlUtils.ts:415–447  ·  view source on GitHub ↗
(
  ...targetUrls: ReadonlyArray<string>
)

Source from the content-addressed store, hash-verified

413 * Creates a function to filter a target URL.
414 */
415export const createTargetFilter = (
416 ...targetUrls: ReadonlyArray<string>
417): ((testUrl: string) => boolean) => {
418 const standardizeMatch = (aUrl: string) => {
419 aUrl = aUrl.toLowerCase();
420
421 const fileUrl = fileUrlToAbsolutePath(aUrl);
422 if (fileUrl) {
423 // Strip file:///, if present
424 aUrl = fileUrl;
425 } else if (isValidUrl(aUrl) && aUrl.includes('://')) {
426 // Strip the protocol, if present
427 aUrl = aUrl.substr(aUrl.indexOf('://') + 3);
428 }
429
430 // Remove optional trailing /
431 if (aUrl.endsWith('/')) {
432 aUrl = aUrl.substr(0, aUrl.length - 1);
433 }
434
435 return aUrl;
436 };
437
438 const escaped = targetUrls.map(url =>
439 escapeRegexSpecialChars(standardizeMatch(url), '/*').replace(/\*/g, '.*'),
440 );
441 const targetUrlRegex = new RegExp('^(' + escaped.join('|') + ')$', 'g');
442
443 return testUrl => {
444 targetUrlRegex.lastIndex = 0;
445 return targetUrlRegex.test(standardizeMatch(testUrl));
446 };
447};

Callers 2

testAllFunction · 0.90

Calls 6

escapeRegexSpecialCharsFunction · 0.90
standardizeMatchFunction · 0.85
replaceMethod · 0.65
mapMethod · 0.45
joinMethod · 0.45
testMethod · 0.45

Tested by 1

testAllFunction · 0.72