folderInterface
Interface dossier avec des méthodes utilitaires.
WARNING
L'objet FolderInterface ne garantit pas l'existence réelle du dossier. C'est uniquement un helper pour representer une ressource et faciliter les opérations.
Exemple
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();
}Syntaxe
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>>>;
}Paramètres
path: chemin du dossier.
Valeur de retour
FolderInterface: interface avec des méthodes utilitaires (rename(newName),exist(),relocate(parentPath),remove(),getChildren(),stat(),walk(),getParentPath()).
Voir aussi
fileInterface- Crée une interface fichier.
