Refactor: make ESLint happy

This commit is contained in:
SukkaW
2024-07-24 23:14:23 +08:00
parent 46ae8e8cd8
commit 6877195279
10 changed files with 24 additions and 53 deletions

View File

@@ -1,3 +1,7 @@
import { dirname } from 'path';
import fs from 'fs';
import fsp from 'fs/promises';
export const isTruthy = <T>(i: T | 0 | '' | false | null | undefined): i is T => !!i;
export const fastStringArrayJoin = (arr: string[], sep: string) => {
@@ -11,8 +15,16 @@ export const fastStringArrayJoin = (arr: string[], sep: string) => {
return result;
};
export const fastStringArrayJoin2 = (arr: string[], sep: string) => {
return arr.reduce((acc, cur, index) => {
return index === 0 ? cur : acc + sep + cur;
}, '');
interface Write {
(
destination: string,
input: NodeJS.TypedArray | string,
): Promise<unknown>
}
export const writeFile: Write = async (destination: string, input, dir = dirname(destination)) => {
if (!fs.existsSync(dir)) {
await fsp.mkdir(dir, { recursive: true });
}
return fsp.writeFile(destination, input, { encoding: 'utf-8' });
};