0.0.0 • Published 5 years ago

webext-pattern-to-regex v0.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

webext-pattern-to-regex

Tool to convert the patterns of your WebExtension manifest to regex

This might be incomplete. Please help me test it.

Install

You can just download the standalone bundle (it might take a minute to download) and include the file in your manifest.json, or:

npm install webext-pattern-to-regex
// This module is only offered as a ES Module
import webextPatternToRegex from 'webext-pattern-to-regex';

Usage

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

const gmailRegex = webextPatternToRegex('*://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 = webextPatternToRegex(
	'https://google.com/*',
	'https://google.it/*'
);
googleRegex.test('https://google.it/search'); // -> true
googleRegex.test('https://google.de/search'); // -> false

API

webextPatternToRegex(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