Feat: Surge DOMAIN-WILDCARD -> Clash DOMAIN-REGEX

This commit is contained in:
SukkaW
2024-08-13 02:01:15 +08:00
parent 5bceb6cac7
commit f35958208f
6 changed files with 35 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
import { 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;
@@ -28,3 +29,7 @@ export const writeFile: Write = async (destination: string, input, dir = dirname
}
return fsp.writeFile(destination, input, { encoding: 'utf-8' });
};
export const domainWildCardToRegex = (domain: string) => {
return makeRe(domain, { contains: false, strictSlashes: true }).source;
};