mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Refactor: continues to rewrite to TS
This commit is contained in:
28
Build/lib/clash.ts
Normal file
28
Build/lib/clash.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
// @ts-check
|
||||
import Trie from 'mnemonist/trie';
|
||||
|
||||
// https://dreamacro.github.io/clash/configuration/rules.html
|
||||
const CLASH_SUPPORTED_RULE_TYPE = [
|
||||
'DOMAIN',
|
||||
'DOMAIN-SUFFIX',
|
||||
'DOMAIN-KEYWORD',
|
||||
'GEOIP',
|
||||
'IP-CIDR',
|
||||
'IP-CIDR6',
|
||||
'SRC-IP-CIDR',
|
||||
'SRC-PORT',
|
||||
'DST-PORT',
|
||||
'PROCESS-NAME',
|
||||
'PROCESS-PATH'
|
||||
];
|
||||
|
||||
export const surgeRulesetToClashClassicalTextRuleset = (rules: string[] | Set<string>) => {
|
||||
const trie = Trie.from(rules);
|
||||
return CLASH_SUPPORTED_RULE_TYPE.flatMap(
|
||||
type => trie.find(`${type},`)
|
||||
);
|
||||
};
|
||||
|
||||
export const surgeDomainsetToClashDomainset = (domainset: string[]) => {
|
||||
return domainset.map(i => (i[0] === '.' ? `+${i}` : i));
|
||||
};
|
||||
Reference in New Issue
Block a user