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 parentPath = folder.getParentPath();
// parentPath: string
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 | URL
): FolderInterfacetypescript
function isFolderInterface(
input: unknown
): input is FolderInterfaceInterface FolderInterface
typescript
interface FolderInterface {
name: string;
path: string;
getParentPath(): string;
rename(newName: string): Promise<FileSystemLeft | E.Success<FolderInterface>>;
exist(): Promise<FileSystemLeft | E.Ok>;
relocate(parentPath: string | URL): Promise<FileSystemLeft | E.Success<FolderInterface>>;
remove(): Promise<FileSystemLeft | E.Ok>;
getChildren(): Promise<FileSystemLeft | E.Success<string[]>>;
stat(): Promise<FileSystemLeft | E.Success<StatInfo>>;
walk(): Promise<FileSystemLeft | E.Success<Generator<FolderInterface | FileInterface | UnknownInterface>>>;
}Parameters
path: path of the directory.
Return value
FolderInterface: interface with utility methods (rename(newName),exist(),relocate(parentPath),remove(),getChildren(),stat(),walk(),getParentPath()).
See also
fileInterface- Creates a file interface.
