mirror of
https://github.com/SukkaW/Surge.git
synced 2026-02-01 19:41:54 +08:00
Chore: Housekeeping & Make ESLint Happy
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
/** Packs two 16-bit integers into one 32-bit integer */
|
||||
export const pack = (a: number, b: number): number => {
|
||||
return (a << 16) | b;
|
||||
};
|
||||
export const pack = (a: number, b: number): number => (a << 16) | b;
|
||||
|
||||
/** Unpacks two 16-bit integers from one 32-bit integer */
|
||||
export const unpack = (value: number, arr: [a: number, b: number] = Array.from(new Array(2).keys()) as any): [a: number, b: number] => {
|
||||
|
||||
@@ -77,13 +77,11 @@ export const appendArrayFromSet = <T>(dest: T[], source: Set<T> | Array<Set<T>>,
|
||||
return dest;
|
||||
};
|
||||
|
||||
export const output = (id: string, type: 'non_ip' | 'ip' | 'domainset') => {
|
||||
return [
|
||||
path.join(OUTPUT_SURGE_DIR, type, id + '.conf'),
|
||||
path.join(OUTPUT_CLASH_DIR, type, id + '.txt'),
|
||||
path.join(OUTPUT_SINGBOX_DIR, type, id + '.json')
|
||||
] as const;
|
||||
};
|
||||
export const output = (id: string, type: 'non_ip' | 'ip' | 'domainset') => [
|
||||
path.join(OUTPUT_SURGE_DIR, type, id + '.conf'),
|
||||
path.join(OUTPUT_CLASH_DIR, type, id + '.txt'),
|
||||
path.join(OUTPUT_SINGBOX_DIR, type, id + '.json')
|
||||
] as const;
|
||||
|
||||
export function withBannerArray(title: string, description: string[] | readonly string[], date: Date, content: string[]) {
|
||||
return [
|
||||
|
||||
@@ -223,9 +223,7 @@ export async function processFilterRules(
|
||||
lineCb(line);
|
||||
}
|
||||
} else {
|
||||
const filterRules = await span.traceChild('download adguard filter').traceAsyncFn(() => {
|
||||
return fetchAssets(filterRulesUrl, fallbackUrls).then(text => text.split('\n'));
|
||||
});
|
||||
const filterRules = await span.traceChild('download adguard filter').traceAsyncFn(() => fetchAssets(filterRulesUrl, fallbackUrls).then(text => text.split('\n')));
|
||||
|
||||
span.traceChild('parse adguard filter').traceSyncFn(() => {
|
||||
for (let i = 0, len = filterRules.length; i < len; i++) {
|
||||
|
||||
@@ -36,14 +36,14 @@ export abstract class RuleOutput<TPreprocessed = unknown> {
|
||||
|
||||
protected pendingPromise = Promise.resolve();
|
||||
|
||||
static jsonToLines = (json: unknown): string[] => stringify(json).split('\n');
|
||||
static readonly jsonToLines = (json: unknown): string[] => stringify(json).split('\n');
|
||||
|
||||
whitelistDomain = (domain: string) => {
|
||||
this.domainTrie.whitelist(domain);
|
||||
return this;
|
||||
};
|
||||
|
||||
static domainWildCardToRegex = (domain: string) => {
|
||||
static readonly domainWildCardToRegex = (domain: string) => {
|
||||
let result = '^';
|
||||
for (let i = 0, len = domain.length; i < len; i++) {
|
||||
switch (domain[i]) {
|
||||
@@ -67,8 +67,7 @@ export abstract class RuleOutput<TPreprocessed = unknown> {
|
||||
constructor(
|
||||
protected readonly span: Span,
|
||||
protected readonly id: string
|
||||
) {
|
||||
}
|
||||
) { }
|
||||
|
||||
protected title: string | null = null;
|
||||
withTitle(title: string) {
|
||||
@@ -199,7 +198,7 @@ export abstract class RuleOutput<TPreprocessed = unknown> {
|
||||
return this;
|
||||
}
|
||||
|
||||
static ipToCidr = (ip: string, version: 4 | 6 = 4) => {
|
||||
static readonly ipToCidr = (ip: string, version: 4 | 6 = 4) => {
|
||||
if (ip.includes('/')) return ip;
|
||||
if (version === 4) {
|
||||
return ip + '/32';
|
||||
@@ -325,11 +324,7 @@ export const fileEqual = async (linesA: string[], source: AsyncIterable<string>)
|
||||
index++;
|
||||
|
||||
if (index > linesA.length - 1) {
|
||||
if (index === linesA.length && lineB === '') {
|
||||
return true;
|
||||
}
|
||||
// The file becomes smaller
|
||||
return false;
|
||||
return (index === linesA.length && lineB === '');
|
||||
}
|
||||
|
||||
const lineA = linesA[index];
|
||||
@@ -353,12 +348,8 @@ export const fileEqual = async (linesA: string[], source: AsyncIterable<string>)
|
||||
}
|
||||
}
|
||||
|
||||
if (index < linesA.length - 1) {
|
||||
// The file becomes larger
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
// The file becomes larger
|
||||
return !(index < linesA.length - 1);
|
||||
};
|
||||
|
||||
export async function compareAndWriteFile(span: Span, linesA: string[], filePath: string) {
|
||||
|
||||
@@ -43,6 +43,4 @@ export const fnv1a52 = (str: string) => {
|
||||
);
|
||||
};
|
||||
|
||||
export const stringHash = (payload: string) => {
|
||||
return fnv1a52(payload).toString(36) + payload.length.toString(36);
|
||||
};
|
||||
export const stringHash = (payload: string) => fnv1a52(payload).toString(36) + payload.length.toString(36);
|
||||
|
||||
@@ -34,9 +34,7 @@ const deepTrieNodeToJSON = (
|
||||
return obj;
|
||||
};
|
||||
|
||||
const createNode = <Meta = any>(parent: TrieNode | null = null): TrieNode => {
|
||||
return [false, parent, new Map<string, TrieNode>(), null] as TrieNode<Meta>;
|
||||
};
|
||||
const createNode = <Meta = any>(parent: TrieNode | null = null): TrieNode => [false, parent, new Map<string, TrieNode>(), null] as TrieNode<Meta>;
|
||||
|
||||
export const hostnameToTokens = (hostname: string): string[] => {
|
||||
const tokens = hostname.split('.');
|
||||
@@ -227,9 +225,7 @@ export const createTrie = <Meta = any>(from?: string[] | Set<string> | null, smo
|
||||
return { node, parent };
|
||||
};
|
||||
|
||||
const contains = (suffix: string): boolean => {
|
||||
return walkIntoLeafWithSuffix(suffix) !== null;
|
||||
};
|
||||
const contains = (suffix: string): boolean => walkIntoLeafWithSuffix(suffix) !== null;
|
||||
|
||||
const walk = (
|
||||
onMatches: (suffix: string[], meta: Meta) => void,
|
||||
|
||||
Reference in New Issue
Block a user