UNPKG

@visulima/fs

Version:

Human friendly file system utilities for Node.js

125 lines (110 loc) 4.67 kB
import { Dirent, PathLike } from 'node:fs'; import { DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions } from 'yaml'; declare const F_OK = 0; declare const R_OK = 4; declare const W_OK = 2; declare const X_OK = 1; declare const FIND_UP_STOP: unique symbol; type ColorizeMethod = (value: string) => string; interface WalkOptions { extensions?: string[]; followSymlinks?: boolean; includeDirs?: boolean; includeFiles?: boolean; includeSymlinks?: boolean; match?: (RegExp | string)[]; maxDepth?: number; skip?: (RegExp | string)[]; } interface WalkEntry extends Pick<Dirent, "isDirectory" | "isFile" | "isSymbolicLink" | "name"> { path: string; } type ReadFileEncoding = "ascii" | "base64" | "base64url" | "hex" | "latin1" | "ucs-2" | "ucs2" | "utf-8" | "utf-16le" | "utf8" | "utf16le"; type ReadFileOptions<C> = { buffer?: boolean; compression?: C; encoding?: ReadFileEncoding | undefined; flag?: number | string | undefined; }; type ContentType<O = undefined> = O extends { buffer: true; } ? Buffer : string; type JsonReviver = Parameters<(typeof JSON)["parse"]>["1"]; type CodeFrameLocation = { column?: number; line: number; }; type CodeFrameOptions = { color?: { gutter?: ColorizeMethod; marker?: ColorizeMethod; message?: ColorizeMethod; }; }; type ReadJsonOptions = CodeFrameOptions & { beforeParse?: (source: string) => string; }; type WriteFileOptions = { chown?: { gid: number; uid: number; }; encoding?: BufferEncoding | null | undefined; flag?: string | undefined; mode?: number; overwrite?: boolean; recursive?: boolean; }; type JsonReplacer = (number | string)[] | ((this: unknown, key: string, value: unknown) => unknown) | null; type YamlReplacer = JsonReplacer; type WriteJsonOptions = WriteFileOptions & { detectIndent?: boolean; indent?: number | string | undefined; replacer?: JsonReplacer; stringify?: (data: unknown, replacer: JsonReplacer, space: number | string | undefined) => string; }; type FindUpOptions = { allowSymlinks?: boolean; cwd?: URL | string; stopAt?: URL | string; type?: "directory" | "file"; }; type FindUpNameFnResult = PathLike | Promise<PathLike | typeof FIND_UP_STOP> | typeof FIND_UP_STOP | undefined; type FindUpName = string[] | string | ((directory: string) => FindUpNameFnResult); type FindUpNameSyncFnResult = PathLike | typeof FIND_UP_STOP | undefined; type FindUpNameSync = string[] | string | ((directory: string) => FindUpNameSyncFnResult); type EmptyDirOptions = { maxRetries?: number | undefined; retryDelay?: number | undefined; }; type ReadYamlOptions<C> = DocumentOptions & ParseOptions & ReadFileOptions<C> & SchemaOptions & ToJSOptions; type YamlReviver = (key: unknown, value: unknown) => unknown; /** Matches a JSON object. This type can be useful to enforce some input to be JSON-compatible or as a super-type to be extended from. Don't use this as a direct return type as the user would have to double-cast it: `jsonObject as unknown as CustomResponse`. Instead, you could extend your CustomResponse type from it to ensure your type only uses JSON-compatible types: `interface CustomResponse extends JsonObject { … }`. @category JSON */ type JsonObject = {[Key in string]: JsonValue} & {[Key in string]?: JsonValue | undefined}; /** Matches a JSON array. @category JSON */ type JsonArray = JsonValue[] | readonly JsonValue[]; /** Matches any valid JSON primitive value. @category JSON */ type JsonPrimitive = string | number | boolean | null; /** Matches any valid JSON value. @see `Jsonify` if you need to transform a type to one that is assignable to `JsonValue`. @category JSON */ type JsonValue = JsonPrimitive | JsonObject | JsonArray; declare global { // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged. interface SymbolConstructor { readonly observable: symbol; } } export { type ContentType as C, type EmptyDirOptions as E, type FindUpName as F, type JsonValue as J, type ReadFileOptions as R, type WalkOptions as W, X_OK as X, type YamlReviver as Y, type FindUpOptions as a, type FindUpNameSync as b, type WalkEntry as c, type ReadJsonOptions as d, type JsonReviver as e, type ReadYamlOptions as f, type WriteFileOptions as g, type WriteJsonOptions as h, type YamlReplacer as i, F_OK as j, FIND_UP_STOP as k, R_OK as l, W_OK as m, type CodeFrameLocation as n, type FindUpNameFnResult as o, type FindUpNameSyncFnResult as p, type JsonReplacer as q, type ReadFileEncoding as r, type CodeFrameOptions as s };