mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Use foxts more & Improve writing
This commit is contained in:
@@ -2,6 +2,7 @@ import { dirname } from 'node:path';
|
||||
import fs from 'node:fs';
|
||||
import type { PathLike } from 'node:fs';
|
||||
import fsp from 'node:fs/promises';
|
||||
import { appendArrayInPlace } from 'foxts/append-array-in-place';
|
||||
|
||||
export type MaybePromise<T> = T | Promise<T>;
|
||||
|
||||
@@ -49,19 +50,23 @@ export const writeFile: Write = async (destination: string, input, dir = dirname
|
||||
return fsp.writeFile(destination, input, { encoding: 'utf-8' });
|
||||
};
|
||||
|
||||
export const removeFiles = async (files: string[]) => Promise.all(files.map((file) => fsp.rm(file, { force: true })));
|
||||
|
||||
export function withBannerArray(title: string, description: string[] | readonly string[], date: Date, content: string[]) {
|
||||
return [
|
||||
const result: string[] = [
|
||||
'#########################################',
|
||||
`# ${title}`,
|
||||
`# Last Updated: ${date.toISOString()}`,
|
||||
`# Size: ${content.length}`,
|
||||
...description.map(line => (line ? `# ${line}` : '#')),
|
||||
'#########################################',
|
||||
...content,
|
||||
'################## EOF ##################'
|
||||
`# Size: ${content.length}`
|
||||
];
|
||||
|
||||
appendArrayInPlace(result, description.map(line => (line ? `# ${line}` : '#')));
|
||||
|
||||
result.push('#########################################');
|
||||
|
||||
appendArrayInPlace(result, content);
|
||||
|
||||
result.push('################## EOF ##################', '');
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
export function notSupported(name: string) {
|
||||
@@ -84,7 +89,3 @@ export function isDirectoryEmptySync(path: PathLike) {
|
||||
directoryHandle.closeSync();
|
||||
}
|
||||
}
|
||||
|
||||
export function fastIpVersion(ip: string) {
|
||||
return ip.includes(':') ? 6 : (ip.includes('.') ? 4 : 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user