webext-patterns

Tool to convert the patterns of your WebExtension manifest to regex

Usage no npm install needed!

<script type="module">
  import webextPatterns from 'https://cdn.skypack.dev/webext-patterns';
</script>

README

webext-patterns

Tool to convert the patterns and globs of your WebExtension manifest to regex

This might be incomplete. Please help me test it by adding more pattern and URLs to the tests.

Install

You can download the standalone bundle and include it in your manifest.json.

Or use npm:

npm install webext-patterns
// This module is only offered as a ES Module
import {patternToRegex} from 'webext-patterns';

Usage

patternToRegex('http://*/*');
// Returns /^http:\/\/?.+\/.+$/

const gmailRegex = patternToRegex('*://mail.google.com/*');
gmailRegex.test('https://mail.google.com/a/b/c'); // -> true
gmailRegex.test('https://photos.google.com/a/b/c'); // -> false

// Also accepts an array of patterns and returns a single regex
const googleRegex = patternToRegex(
    'https://google.com/*',
    'https://google.it/*'
);
googleRegex.test('https://google.it/search'); // -> true
googleRegex.test('https://google.de/search'); // -> false

API

patternToRegex(pattern1, pattern2, etc)

Accepts any number of string arguments and returns a single regex to match all of them.

Related

Permissions

Others

License

MIT © Federico Brigante