Refactor: add more parsing

This commit is contained in:
SukkaW
2024-09-21 16:24:13 +08:00
parent 6425b6096e
commit 1783cccf7f
5 changed files with 97 additions and 39 deletions

View File

@@ -61,6 +61,17 @@ export const domainWildCardToRegex = (domain: string) => {
return result;
};
export const identity = <T>(x: T): T => x;
export const appendArrayFromSet = <T>(dest: T[], source: Set<T>, transformer: (item: T) => T = identity) => {
const iterator = source.values();
let step: IteratorResult<T, undefined>;
while ((step = iterator.next(), !step.done)) {
dest.push(transformer(step.value));
}
};
export const output = (id: string, type: 'non_ip' | 'ip' | 'domainset') => {
return [
path.join(OUTPUT_SURGE_DIR, type, id + '.conf'),