obsidian-dev-utils
Version:
This is the collection of useful functions that you can use for your Obsidian plugin development
76 lines (75 loc) • 2.87 kB
text/typescript
/**
* @packageDocumentation
*
* Contains utility functions for file system operations.
*/
import type { Dirent, ObjectEncodingOptions, PathLike } from './NodeModules.cjs';
/**
* Options for controlling the format of the result when returning buffers.
*
* `directory` is used instead of `folder` to preserve compatibility with `node:fs` module.
*/
export type BufferResultOptions = 'buffer' | {
/**
* Should be set to "buffer" to return buffers.
*/
encoding: 'buffer';
/**
* Whether to include subdirectories when reading the directory. If not provided, defaults to `false`.
*/
recursive?: boolean;
/**
* Should be set to `false` to return buffers.
*/
withFileTypes?: false;
};
/**
* Options for controlling the format of the result when returning Dirent objects.
*/
export type DirentResultOptions = {
/**
* Whether to include subdirectories when reading the directory. If not provided, defaults to `false`.
*/
recursive?: boolean;
/**
* Should be set to `true` to return Dirent objects.
*/
withFileTypes: true;
} & ObjectEncodingOptions;
/**
* Options for controlling the format of the result when returning strings.
*/
export type StringResultOptions = {
/**
* Whether to include subdirectories when reading the directory. If not provided, defaults to `false`.
*/
recursive?: boolean;
/**
* Should be set to `false` to return strings.
*/
withFileTypes?: false;
} & ObjectEncodingOptions | undefined;
/**
* Reads the contents of a directory and returns an array of strings with POSIX paths.
*
* @param path - The path to the directory.
* @param options - Options to control the format of the result. If not provided, returns strings.
* @returns A {@link Promise} that resolves with an array of POSIX-formatted file paths.
*/
export declare function readdirPosix(path: PathLike, options?: StringResultOptions): Promise<string[]>;
/**
* Reads the contents of a directory and returns an array of buffers with POSIX paths.
*
* @param path - The path to the directory.
* @param options - Options to control the format of the result. Specify "buffer" to return buffers.
* @returns A {@link Promise} that resolves with an array of POSIX-formatted buffers.
*/
export declare function readdirPosix(path: PathLike, options: BufferResultOptions): Promise<Buffer[]>;
/**
* Reads the contents of a directory and returns an array of Dirent objects with POSIX paths.
*
* @param path - The path to the directory.
* @param options - Options to control the format of the result. Specify `withFileTypes: true` to return Dirent objects.
* @returns A {@link Promise} that resolves with an array of POSIX-formatted Dirent objects.
*/
export declare function readdirPosix(path: PathLike, options: DirentResultOptions): Promise<Dirent[]>;