UNPKG

mjdapi

Version:
102 lines (101 loc) 3.04 kB
export interface ExistsOptions { /** * When `true`, will check if the path is readable by the user as well. * @default {false} */ isReadable?: boolean; /** * When `true`, will check if the path is a directory as well. * Directory symlinks are included. * @default {false} */ isDirectory?: boolean; /** * When `true`, will check if the path is a file as well. * File symlinks are included. * @default {false} */ isFile?: boolean; } /** * Test whether or not the given path exists by checking with the file system. Please consider to check if the path is readable and either a file or a directory by providing additional `options`: * * ```ts * import { exists } from "https://deno.land/std@$STD_VERSION/fs/mod.ts"; * const isReadableDir = await exists("./foo", { * isReadable: true, * isDirectory: true * }); * const isReadableFile = await exists("./bar", { * isReadable: true, * isFile: true * }); * ``` * * Note: Do not use this function if performing a check before another operation on that file. Doing so creates a race condition. Instead, perform the actual file operation directly. * * Bad: * ```ts * import { exists } from "https://deno.land/std@$STD_VERSION/fs/mod.ts"; * * if (await exists("./foo")) { * await Deno.remove("./foo"); * } * ``` * * Good: * ```ts * // Notice no use of exists * try { * await Deno.remove("./foo", { recursive: true }); * } catch (error) { * if (!(error instanceof Deno.errors.NotFound)) { * throw error; * } * // Do nothing... * } * ``` * @see https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use */ export declare function exists(path: string | URL, options?: ExistsOptions): Promise<boolean>; /** * Test whether or not the given path exists by checking with the file system. Please consider to check if the path is readable and either a file or a directory by providing additional `options`: * * ```ts * import { existsSync } from "https://deno.land/std@$STD_VERSION/fs/mod.ts"; * const isReadableDir = existsSync("./foo", { * isReadable: true, * isDirectory: true * }); * const isReadableFile = existsSync("./bar", { * isReadable: true, * isFile: true * }); * ``` * * Note: do not use this function if performing a check before another operation on that file. Doing so creates a race condition. Instead, perform the actual file operation directly. * * Bad: * ```ts * import { existsSync } from "https://deno.land/std@$STD_VERSION/fs/mod.ts"; * * if (existsSync("./foo")) { * Deno.removeSync("./foo"); * } * ``` * * Good: * ```ts * // Notice no use of existsSync * try { * Deno.removeSync("./foo", { recursive: true }); * } catch (error) { * if (!(error instanceof Deno.errors.NotFound)) { * throw error; * } * // Do nothing... * } * ``` * @see https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use */ export declare function existsSync(path: string | URL, options?: ExistsOptions): boolean;