Skip to content

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
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
();
}

Syntaxe ​

typescript
function createFolderInterface(
  path: string
): FolderInterface
typescript
function isFolderInterface(
  input: unknown
): input is FolderInterface

Interface 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>>>;
}

Paramètres ​

  • path : chemin du dossier.

Valeur de retour ​

  • FolderInterface : interface avec des getters (getName, getParentPath) et des méthodes utilitaires (rename(newName), exists(), relocate(parentPath), move(newPath), remove(), getChildren(), stat(), walk()).

Voir aussi ​

Diffusé sous licence MIT.