Skip to content

Commit

Permalink
Add support for <all_urls>
Browse files Browse the repository at this point in the history
Fixes #3
  • Loading branch information
fregante committed Jan 24, 2021
1 parent 37a4eb8 commit 00ce6ad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@ function getRawRegex(matchPattern: string): string {
}

export function patternToRegex(...matchPatterns: readonly string[]): RegExp {
if (matchPatterns.includes('<all_urls>')) {
return /^(https?|file|ftp):[/]+/;
}

return new RegExp(matchPatterns.map(getRawRegex).join('|'));
}
9 changes: 9 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ map.set('*://mail.google.com/*', [
'https://mail.google.com/foobar',
]);

map.set('<all_urls>', [
'http://mail.google.com/foo/baz/bar',
'https://mail.google.com/foobar',
'file:///foo/bar.html',
'file:///foo',
'http://bfred.it',
'ftp://example.com',
]);

for (const [pattern, urls] of map) {
test(macro, pattern, urls);
}

0 comments on commit 00ce6ad

Please sign in to comment.