mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-13 01:30:37 +08:00
Reafactor: rewrite domain wildcard to regex
This commit is contained in:
parent
640bac160c
commit
991b192fa7
@ -1,7 +1,6 @@
|
||||
import path, { dirname } from 'path';
|
||||
import fs from 'fs';
|
||||
import fsp from 'fs/promises';
|
||||
import { makeRe } from 'picomatch';
|
||||
|
||||
export const isTruthy = <T>(i: T | 0 | '' | false | null | undefined): i is T => !!i;
|
||||
|
||||
@ -31,7 +30,24 @@ export const writeFile: Write = async (destination: string, input, dir = dirname
|
||||
};
|
||||
|
||||
export const domainWildCardToRegex = (domain: string) => {
|
||||
return makeRe(domain, { contains: false, strictSlashes: true }).source;
|
||||
let result = '^';
|
||||
for (let i = 0, len = domain.length; i < len; i++) {
|
||||
switch (domain[i]) {
|
||||
case '.':
|
||||
result += String.raw`\.`;
|
||||
break;
|
||||
case '*':
|
||||
result += '[a-zA-Z0-9-.]*?';
|
||||
break;
|
||||
case '?':
|
||||
result += '[a-zA-Z0-9-.]';
|
||||
break;
|
||||
default:
|
||||
result += domain[i];
|
||||
}
|
||||
}
|
||||
result += '$';
|
||||
return result;
|
||||
};
|
||||
|
||||
const OUTPUT_SURGE_DIR = path.resolve(__dirname, '../../List');
|
||||
|
||||
@ -34,7 +34,6 @@
|
||||
"mnemonist": "^0.39.8",
|
||||
"path-scurry": "^1.11.1",
|
||||
"picocolors": "^1.0.1",
|
||||
"picomatch": "^4.0.2",
|
||||
"punycode": "^2.3.1",
|
||||
"table": "^6.8.2",
|
||||
"tar-stream": "^3.1.7",
|
||||
@ -50,7 +49,6 @@
|
||||
"@types/better-sqlite3": "^7.6.11",
|
||||
"@types/chai": "^4.3.17",
|
||||
"@types/mocha": "^10.0.7",
|
||||
"@types/picomatch": "^3.0.1",
|
||||
"@types/punycode": "^2.1.4",
|
||||
"@types/tar-stream": "^3.1.3",
|
||||
"chai": "4",
|
||||
|
||||
14
pnpm-lock.yaml
generated
14
pnpm-lock.yaml
generated
@ -53,9 +53,6 @@ importers:
|
||||
picocolors:
|
||||
specifier: ^1.0.1
|
||||
version: 1.0.1
|
||||
picomatch:
|
||||
specifier: ^4.0.2
|
||||
version: 4.0.2
|
||||
punycode:
|
||||
specifier: ^2.3.1
|
||||
version: 2.3.1
|
||||
@ -96,9 +93,6 @@ importers:
|
||||
'@types/mocha':
|
||||
specifier: ^10.0.7
|
||||
version: 10.0.7
|
||||
'@types/picomatch':
|
||||
specifier: ^3.0.1
|
||||
version: 3.0.1
|
||||
'@types/punycode':
|
||||
specifier: ^2.1.4
|
||||
version: 2.1.4
|
||||
@ -446,9 +440,6 @@ packages:
|
||||
'@types/node@20.14.11':
|
||||
resolution: {integrity: sha512-kprQpL8MMeszbz6ojB5/tU8PLN4kesnN8Gjzw349rDlNgsSzg90lAVj3llK99Dh7JON+t9AuscPPFW6mPbTnSA==}
|
||||
|
||||
'@types/picomatch@3.0.1':
|
||||
resolution: {integrity: sha512-1MRgzpzY0hOp9pW/kLRxeQhUWwil6gnrUYd3oEpeYBqp/FexhaCPv3F8LsYr47gtUU45fO2cm1dbwkSrHEo8Uw==}
|
||||
|
||||
'@types/punycode@2.1.4':
|
||||
resolution: {integrity: sha512-trzh6NzBnq8yw5e35f8xe8VTYjqM3NE7bohBtvDVf/dtUer3zYTLK1Ka3DG3p7bdtoaOHZucma6FfVKlQ134pQ==}
|
||||
|
||||
@ -1905,8 +1896,6 @@ snapshots:
|
||||
dependencies:
|
||||
undici-types: 5.26.5
|
||||
|
||||
'@types/picomatch@3.0.1': {}
|
||||
|
||||
'@types/punycode@2.1.4': {}
|
||||
|
||||
'@types/retry@0.12.5': {}
|
||||
@ -2821,7 +2810,8 @@ snapshots:
|
||||
|
||||
picomatch@2.3.1: {}
|
||||
|
||||
picomatch@4.0.2: {}
|
||||
picomatch@4.0.2:
|
||||
optional: true
|
||||
|
||||
pirates@4.0.6: {}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user