@naturalcycles/nodejs-lib
Version:
Standard library for Node.js
82 lines (81 loc) • 3.34 kB
TypeScript
import type { RmOptions } from 'node:fs';
import fs from 'node:fs';
import fsp from 'node:fs/promises';
/**
* fs2 conveniently groups filesystem functions together.
* Supposed to be almost a drop-in replacement for these things together:
*
* 1. node:fs
* 2. node:fs/promises
* 3. fs-extra
*/
declare class FS2 {
/**
* Convenience wrapper that defaults to utf-8 string output.
*/
readText(filePath: string): string;
/**
* Convenience wrapper that defaults to utf-8 string output.
*/
readTextAsync(filePath: string): Promise<string>;
readBuffer(filePath: string): Buffer;
readBufferAsync(filePath: string): Promise<Buffer>;
readJson<T = unknown>(filePath: string): T;
readJsonAsync<T = unknown>(filePath: string): Promise<T>;
writeFile(filePath: string, data: string | Buffer): void;
writeFileAsync(filePath: string, data: string | Buffer): Promise<void>;
writeJson(filePath: string, data: any, opt?: JsonOptions): void;
writeJsonAsync(filePath: string, data: any, opt?: JsonOptions): Promise<void>;
appendFile(filePath: string, data: string | Buffer): void;
appendFileAsync(filePath: string, data: string | Buffer): Promise<void>;
outputJson(filePath: string, data: any, opt?: JsonOptions): void;
outputJsonAsync(filePath: string, data: any, opt?: JsonOptions): Promise<void>;
outputFile(filePath: string, data: string | Buffer): void;
outputFileAsync(filePath: string, data: string | Buffer): Promise<void>;
pathExists(filePath: string): boolean;
pathExistsAsync(filePath: string): Promise<boolean>;
requireFileToExist(filePath: string): void;
ensureDir(dirPath: string): void;
ensureDirAsync(dirPath: string): Promise<void>;
ensureFile(filePath: string): void;
ensureFileAsync(filePath: string): Promise<void>;
removePath(fileOrDirPath: string, opt?: RmOptions): void;
removePathAsync(fileOrDirPath: string, opt?: RmOptions): Promise<void>;
emptyDir(dirPath: string): void;
emptyDirAsync(dirPath: string): Promise<void>;
/**
* Cautious, underlying Node function is currently Experimental.
*/
copyPath(src: string, dest: string, opt?: fs.CopySyncOptions): void;
/**
* Cautious, underlying Node function is currently Experimental.
*/
copyPathAsync(src: string, dest: string, opt?: fs.CopyOptions): Promise<void>;
renamePath(src: string, dest: string): void;
renamePathAsync(src: string, dest: string): Promise<void>;
movePath(src: string, dest: string, opt?: fs.CopySyncOptions): void;
movePathAsync(src: string, dest: string, opt?: fs.CopyOptions): Promise<void>;
/**
* Returns true if the path is a directory.
* Otherwise returns false.
* Doesn't throw, returns false instead.
*/
isDirectory(filePath: string): boolean;
fs: typeof fs;
fsp: typeof fsp;
lstat: fs.StatSyncFn;
lstatAsync: typeof fsp.lstat;
stat: fs.StatSyncFn;
statAsync: typeof fsp.stat;
mkdir: typeof fs.mkdirSync;
mkdirAsync: typeof fsp.mkdir;
readdir: typeof fs.readdirSync;
readdirAsync: typeof fsp.readdir;
createWriteStream: typeof fs.createWriteStream;
createReadStream: typeof fs.createReadStream;
}
export declare const fs2: FS2;
export interface JsonOptions {
spaces?: number;
}
export {};