folderInterface
Directory interface with utility methods.
WARNING
The FolderInterface object does not guarantee that the directory actually exists. It is only a helper to represent a resource and make operations easier.
Example
ts
import { SF } from "@duplojs/server-utils";
import { E, type ExpectType, G, unwrap } from "@duplojs/utils";
const folder = SF.createFolderInterface("/tmp/project");
const name = folder.getName();
// name: string | null
const parentPath = folder.getParentPath();
// parentPath: string | null
const result = await folder.getChildren();
if (E.isRight(result)) {
const childrens = unwrap(result);
}
const result2 = await folder.walk();
if (E.isRight(result2)) {
G.map(
unwrap(result2),
(element) => {
type check = ExpectType<
typeof element,
SF.FolderInterface | SF.FileInterface | SF.UnknownInterface,
"strict"
>;
},
);
}
if (SF.isFolderInterface(folder)) {
// folder: SF.FolderInterface
await folder.getChildren();
}Syntax
typescript
function createFolderInterface(
path: string
): FolderInterfacetypescript
function isFolderInterface(
input: unknown
): input is FolderInterfaceInterface FolderInterface
typescript
interface FolderInterface {
path: string;
getName(): string | null;
getParentPath(): string | null;
rename(newName: string): Promise<FileSystemLeft<"rename"> | E.Success<FolderInterface>>;
relocate(parentPath: string): Promise<FileSystemLeft<"relocate"> | E.Success<FolderInterface>>;
move(newPath: string): Promise<FileSystemLeft<"move"> | E.Success<FolderInterface>>;
exists(): Promise<FileSystemLeft<"exists"> | E.Ok>;
remove(): Promise<FileSystemLeft<"remove"> | E.Ok>;
getChildren(): Promise<FileSystemLeft<"read-directory"> | E.Success<string[]>>;
stat(): Promise<FileSystemLeft<"stat"> | E.Success<StatInfo>>;
walk(): Promise<FileSystemLeft<"walk-directory"> | E.Success<Generator<FolderInterface | FileInterface | UnknownInterface>>>;
}Parameters
path: path of the directory.
Return value
FolderInterface: interface with getters (getName,getParentPath) and helper methods (rename(newName),exists(),relocate(parentPath),move(newPath),remove(),getChildren(),stat(),walk()).
See also
fileInterface- Creates a file interface.
