webext-patterns 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +1 -0
- package/index.js +9 -0
- package/package.json +8 -7
- package/readme.md +19 -3
package/index.d.ts
CHANGED
|
@@ -3,3 +3,4 @@ export declare const allStarsRegex: RegExp;
|
|
|
3
3
|
export declare const allUrlsRegex: RegExp;
|
|
4
4
|
export declare function patternToRegex(...matchPatterns: readonly string[]): RegExp;
|
|
5
5
|
export declare function globToRegex(...globs: readonly string[]): RegExp;
|
|
6
|
+
export declare function excludeDuplicatePatterns(matchPatterns: readonly string[]): string[];
|
package/index.js
CHANGED
|
@@ -74,3 +74,12 @@ export function globToRegex(...globs) {
|
|
|
74
74
|
}
|
|
75
75
|
return new RegExp(globs.map(x => getRawGlobRegex(x)).join('|'));
|
|
76
76
|
}
|
|
77
|
+
export function excludeDuplicatePatterns(matchPatterns) {
|
|
78
|
+
if (matchPatterns.includes('<all_urls>')) {
|
|
79
|
+
return ['<all_urls>'];
|
|
80
|
+
}
|
|
81
|
+
if (matchPatterns.includes('*://*/*')) {
|
|
82
|
+
return ['*://*/*'];
|
|
83
|
+
}
|
|
84
|
+
return matchPatterns.filter(possibleSubset => !matchPatterns.some(possibleSuperset => possibleSubset !== possibleSuperset && patternToRegex(possibleSuperset).test(possibleSubset)));
|
|
85
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webext-patterns",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Tool to convert the patterns and globs of your WebExtension manifest to regex",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"browser",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"webext"
|
|
18
18
|
],
|
|
19
19
|
"repository": "fregante/webext-patterns",
|
|
20
|
+
"funding": "https://github.com/sponsors/fregante",
|
|
20
21
|
"license": "MIT",
|
|
21
22
|
"author": "Federico Brigante <me@fregante.com> (https://fregante.com)",
|
|
22
23
|
"type": "module",
|
|
@@ -48,12 +49,12 @@
|
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
50
51
|
"@sindresorhus/tsconfig": "^3.0.1",
|
|
51
|
-
"@types/chrome": "0.0.
|
|
52
|
-
"ava": "^
|
|
53
|
-
"sinon": "^
|
|
54
|
-
"type-fest": "^
|
|
55
|
-
"typescript": "^4.
|
|
56
|
-
"xo": "^0.
|
|
52
|
+
"@types/chrome": "0.0.210",
|
|
53
|
+
"ava": "^5.1.1",
|
|
54
|
+
"sinon": "^15.0.1",
|
|
55
|
+
"type-fest": "^3.5.3",
|
|
56
|
+
"typescript": "^4.9.4",
|
|
57
|
+
"xo": "^0.53.1"
|
|
57
58
|
},
|
|
58
59
|
"webExt": {
|
|
59
60
|
"sourceDir": "demo-extension",
|
package/readme.md
CHANGED
|
@@ -24,17 +24,20 @@ import {patternToRegex} from 'webext-patterns';
|
|
|
24
24
|
|
|
25
25
|
## Usage
|
|
26
26
|
|
|
27
|
-
> **Note**
|
|
28
|
-
> Firefox and Chrome handle globs very slighly differently. `webext-patterns` defaults to Chrome’s logic, but if it detects a Firefox userAgent it will produce a Firefox-compatible regex.
|
|
29
|
-
|
|
30
27
|
```js
|
|
31
28
|
patternToRegex('http://*/*');
|
|
32
29
|
// Returns /^http:[/][/][^/]+[/].+$/
|
|
33
30
|
|
|
34
31
|
globToRegex('*.example.com');
|
|
35
32
|
// Returns /\.example\.com$/
|
|
33
|
+
|
|
34
|
+
excludeDuplicatePatterns(['https://*.google.com/*', 'https://google.com/*']);
|
|
35
|
+
// Returns ['https://*.google.com/*']
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
+
> **Note**
|
|
39
|
+
> Firefox and Chrome handle patterns very slighly differently. `webext-patterns` defaults to Chrome’s logic, but if it detects a Firefox userAgent it will produce a Firefox-compatible regex.
|
|
40
|
+
|
|
38
41
|
## API
|
|
39
42
|
|
|
40
43
|
#### patternToRegex(pattern1, pattern2, etc)
|
|
@@ -84,6 +87,19 @@ googleRegex.test('https://google.it/search'); // -> true
|
|
|
84
87
|
googleRegex.test('https://google.de/search'); // -> false
|
|
85
88
|
```
|
|
86
89
|
|
|
90
|
+
#### excludeDuplicatePatterns([pattern1, pattern2, etc])
|
|
91
|
+
|
|
92
|
+
Accepts an array of patterns and returns a filtered array without the patterns that are already covered by others. For example `"https://*/*"` already covers all "https" URLs, so having `"https://google.com/*"` in the array won't make any difference and therefore it's dropped.
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
excludeDuplicatePatterns([
|
|
96
|
+
"https://*/*",
|
|
97
|
+
"https://google.com/*",
|
|
98
|
+
"https://*.example.com/*",
|
|
99
|
+
]);
|
|
100
|
+
// Returns ["https://*/*"]
|
|
101
|
+
```
|
|
102
|
+
|
|
87
103
|
## Related
|
|
88
104
|
|
|
89
105
|
### Permissions
|