mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Chore: make ESLint Happy
This commit is contained in:
@@ -5,7 +5,7 @@ import { OUTPUT_CLASH_DIR, OUTPUT_SINGBOX_DIR, OUTPUT_SURGE_DIR } from '../const
|
||||
|
||||
export const isTruthy = <T>(i: T | 0 | '' | false | null | undefined): i is T => !!i;
|
||||
|
||||
export const fastStringArrayJoin = (arr: string[], sep: string) => {
|
||||
export function fastStringArrayJoin(arr: string[], sep: string) {
|
||||
let result = '';
|
||||
for (let i = 0, len = arr.length; i < len; i++) {
|
||||
if (i !== 0) {
|
||||
@@ -14,7 +14,7 @@ export const fastStringArrayJoin = (arr: string[], sep: string) => {
|
||||
result += arr[i];
|
||||
}
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
interface Write {
|
||||
(
|
||||
@@ -23,12 +23,12 @@ interface Write {
|
||||
): Promise<unknown>
|
||||
}
|
||||
|
||||
export const mkdirp = (dir: string) => {
|
||||
export function mkdirp(dir: string) {
|
||||
if (fs.existsSync(dir)) {
|
||||
return;
|
||||
}
|
||||
return fsp.mkdir(dir, { recursive: true });
|
||||
};
|
||||
}
|
||||
|
||||
export const writeFile: Write = async (destination: string, input, dir = dirname(destination)) => {
|
||||
const p = mkdirp(dir);
|
||||
@@ -40,7 +40,7 @@ export const writeFile: Write = async (destination: string, input, dir = dirname
|
||||
|
||||
export const removeFiles = async (files: string[]) => Promise.all(files.map((file) => fsp.rm(file, { force: true })));
|
||||
|
||||
export const domainWildCardToRegex = (domain: string) => {
|
||||
export function domainWildCardToRegex(domain: string) {
|
||||
let result = '^';
|
||||
for (let i = 0, len = domain.length; i < len; i++) {
|
||||
switch (domain[i]) {
|
||||
@@ -59,11 +59,11 @@ export const domainWildCardToRegex = (domain: string) => {
|
||||
}
|
||||
result += '$';
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
export const identity = <T>(x: T): T => x;
|
||||
|
||||
export const appendArrayFromSet = <T>(dest: T[], source: Set<T> | Array<Set<T>>, transformer: (item: T) => T = identity) => {
|
||||
export function appendArrayFromSet<T>(dest: T[], source: Set<T> | Array<Set<T>>, transformer: (item: T) => T = identity) {
|
||||
const casted = Array.isArray(source) ? source : [source];
|
||||
for (let i = 0, len = casted.length; i < len; i++) {
|
||||
const iterator = casted[i].values();
|
||||
@@ -75,13 +75,15 @@ export const appendArrayFromSet = <T>(dest: T[], source: Set<T> | Array<Set<T>>,
|
||||
}
|
||||
|
||||
return dest;
|
||||
};
|
||||
}
|
||||
|
||||
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 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 function withBannerArray(title: string, description: string[] | readonly string[], date: Date, content: string[]) {
|
||||
return [
|
||||
@@ -96,7 +98,7 @@ export function withBannerArray(title: string, description: string[] | readonly
|
||||
];
|
||||
};
|
||||
|
||||
export const mergeHeaders = (headersA: RequestInit['headers'] | undefined, headersB: RequestInit['headers']) => {
|
||||
export function mergeHeaders(headersA: RequestInit['headers'] | undefined, headersB: RequestInit['headers']) {
|
||||
if (headersA == null) {
|
||||
return headersB;
|
||||
}
|
||||
@@ -116,9 +118,9 @@ export const mergeHeaders = (headersA: RequestInit['headers'] | undefined, heade
|
||||
|
||||
for (const key in headersB) {
|
||||
if (Object.hasOwn(headersB, key)) {
|
||||
result.set(key, (headersB as Record<string, string>)[key]);
|
||||
result.set(key, (headersB)[key]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user