///
import * as fs from "fs";
type AppendData = string | Buffer;
type AppendOptions = {
mode?: string | number;
};
type OverwriteFunction = (
srcInspectData: InspectResult,
destInspectData: InspectResult
) => boolean | Promise;
type CopyOptions = {
overwrite?: boolean | OverwriteFunction;
matching?: string | string[];
};
type DirCriteria = {
empty?: boolean;
mode?: string | number;
};
export type ExistsResult = false | "dir" | "file" | "other";
type FileOptions = {
content?: WritableData;
jsonIndent?: number;
mode?: string | number;
};
type FindOptions = {
matching?: string | string[];
files?: boolean;
directories?: boolean;
recursive?: boolean;
};
export type Checksum = "md5" | "sha1" | "sha256" | "sha512";
type InspectOptions = {
checksum?: Checksum;
mode?: boolean;
times?: boolean;
absolutePath?: boolean;
symlinks?: "report" | "follow";
};
export interface InspectResult {
name: string;
type: "file" | "dir" | "symlink";
size: number;
absolutePath?: string;
md5?: string;
sha1?: string;
sha256?: string;
sha512?: string;
mode?: number;
accessTime?: Date;
modifyTime?: Date;
changeTime?: Date;
}
type InspectTreeOptions = {
checksum?: Checksum;
relativePath?: boolean;
symlinks?: "report" | "follow";
};
export interface InspectTreeResult extends InspectResult {
relativePath: string;
children: InspectTreeResult[];
}
type WritableData = string | object | Array | Buffer;
type WriteOptions = {
atomic?: boolean;
jsonIndent?: number;
};
export interface FSJetpack {
cwd: {
(): string;
(...pathParts: string[]): FSJetpack;
};
path(...pathParts: string[]): string;
append(path: string, data: AppendData, options?: AppendOptions): void;
appendAsync(
path: string,
data: AppendData,
options?: AppendOptions
): Promise;
copy(from: string, to: string, options?: CopyOptions): void;
copyAsync(from: string, to: string, options?: CopyOptions): Promise;
createWriteStream: typeof fs.createWriteStream;
createReadStream: typeof fs.createReadStream;
dir(path: string, criteria?: DirCriteria): FSJetpack;
dirAsync(path: string, criteria?: DirCriteria): Promise;
exists(path: string): ExistsResult;
existsAsync(path: string): Promise;
file(path: string, criteria?: FileOptions): FSJetpack;
fileAsync(path: string, criteria?: FileOptions): Promise;
find(options?: FindOptions): string[];
find(startPath: string, options?: FindOptions): string[];
findAsync(options?: FindOptions): Promise;
findAsync(startPath: string, options?: FindOptions): Promise;
inspect(path: string, options?: InspectOptions): InspectResult | undefined;
inspectAsync(
path: string,
options?: InspectOptions
): Promise;
inspectTree(
path: string,
options?: InspectTreeOptions
): InspectTreeResult | undefined;
inspectTreeAsync(
path: string,
options?: InspectTreeOptions
): Promise;
list(path?: string): string[] | undefined;
listAsync(path?: string): Promise;
move(from: string, to: string): void;
moveAsync(from: string, to: string): Promise;
read(path: string): string | undefined;
read(path: string, returnAs: "utf8"): string | undefined;
read(path: string, returnAs: "buffer"): Buffer | undefined;
read(path: string, returnAs: "json" | "jsonWithDates"): any | undefined;
readAsync(path: string): Promise;
readAsync(path: string, returnAs: "utf8"): Promise;
readAsync(path: string, returnAs: "buffer"): Promise;
readAsync(
path: string,
returnAs: "json" | "jsonWithDates"
): Promise;
remove(path?: string): void;
removeAsync(path?: string): Promise;
rename(path: string, newName: string): void;
renameAsync(path: string, newName: string): Promise;
symlink(symlinkValue: string, path: string): void;
symlinkAsync(symlinkValue: string, path: string): Promise;
write(path: string, data: WritableData, options?: WriteOptions): void;
writeAsync(
path: string,
data: WritableData,
options?: WriteOptions
): Promise;
}