@push.rocks/smartfile
Version:
Provides comprehensive tools for efficient file management in Node.js using TypeScript, including handling streams, virtual directories, and various file operations.
178 lines (177 loc) • 6.66 kB
TypeScript
import * as plugins from './plugins.js';
import { SmartFile } from './classes.smartfile.js';
import type { StreamFile } from './classes.streamfile.js';
/**
*
* @param filePath
* @returns {boolean}
*/
export declare const fileExistsSync: (filePath: any) => boolean;
/**
*
* @param filePath
* @returns {any}
*/
export declare const fileExists: (filePath: any) => Promise<boolean>;
/**
* Checks if given path points to an existing directory
*/
export declare const isDirectory: (pathArg: string) => boolean;
/**
* Checks if given path points to an existing directory
*/
export declare const isDirectorySync: (pathArg: string) => boolean;
/**
* Checks if a given path points to an existing file
*/
export declare const isFile: (pathArg: any) => boolean;
/**
* copies a file or directory from A to B on the local disk
*/
export declare const copy: (fromArg: string, toArg: string, optionsArg?: plugins.fsExtra.CopyOptions & {
replaceTargetDir?: boolean;
}) => Promise<void>;
/**
* copies a file or directory SYNCHRONOUSLY from A to B on the local disk
*/
export declare const copySync: (fromArg: string, toArg: string, optionsArg?: plugins.fsExtra.CopyOptionsSync & {
replaceTargetDir?: boolean;
}) => void;
/**
* ensures that a directory is in place
*/
export declare const ensureDir: (dirPathArg: string) => Promise<void>;
/**
* ensures that a directory is in place
*/
export declare const ensureDirSync: (dirPathArg: string) => void;
/**
* ensure an empty directory
* @executes ASYNC
*/
export declare const ensureEmptyDir: (dirPathArg: string) => Promise<void>;
/**
* ensure an empty directory
* @executes SYNC
*/
export declare const ensureEmptyDirSync: (dirPathArg: string) => void;
/**
* ensures that a file is on disk
* @param filePath the filePath to ensureDir
* @param the fileContent to place into a new file in case it doesn't exist yet
* @returns Promise<void>
* @exec ASYNC
*/
export declare const ensureFile: (filePathArg: any, initFileStringArg: any) => Promise<void>;
/**
* ensures that a file is on disk
* @param filePath the filePath to ensureDir
* @param the fileContent to place into a new file in case it doesn't exist yet
* @returns Promise<void>
* @exec SYNC
*/
export declare const ensureFileSync: (filePathArg: string, initFileStringArg: string) => void;
/**
* removes a file or folder from local disk
*/
export declare const remove: (pathArg: string) => Promise<void>;
/**
* removes a file SYNCHRONOUSLY from local disk
*/
export declare const removeSync: (pathArg: string) => void;
/**
* removes an array of filePaths from disk
*/
export declare const removeMany: (filePathArrayArg: string[]) => Promise<void>;
/**
* like removeFilePathArray but SYNCHRONOUSLY
*/
export declare const removeManySync: (filePathArrayArg: string[]) => void;
/**
* reads a file content to an object
* good for JSON, YAML, TOML, etc.
* @param filePathArg
* @param fileTypeArg
* @returns {any}
*/
export declare const toObjectSync: (filePathArg: any, fileTypeArg?: any) => any;
/**
* reads a file content to a String
*/
export declare const toStringSync: (filePath: string) => string;
export declare const toBuffer: (filePath: string) => Promise<Buffer>;
export declare const toBufferSync: (filePath: string) => Buffer;
/**
* Creates a Readable Stream from a file path.
* @param filePath The path to the file.
* @returns {fs.ReadStream}
*/
export declare const toReadStream: (filePath: string) => plugins.fs.ReadStream;
export declare const fileTreeToHash: (dirPathArg: string, miniMatchFilter: string) => Promise<string>;
/**
* creates a smartfile array from a directory
* @param dirPathArg the directory to start from
* @param miniMatchFilter a minimatch filter of what files to include
*/
export declare const fileTreeToObject: (dirPathArg: string, miniMatchFilter: string) => Promise<SmartFile[]>;
/**
* lists Folders in a directory on local disk
* @returns Promise with an array that contains the folder names
*/
export declare const listFolders: (pathArg: string, regexFilter?: RegExp) => Promise<string[]>;
/**
* lists Folders SYNCHRONOUSLY in a directory on local disk
* @returns an array with the folder names as strings
*/
export declare const listFoldersSync: (pathArg: string, regexFilter?: RegExp) => string[];
/**
* lists Files in a directory on local disk
* @returns Promise
*/
export declare const listFiles: (pathArg: string, regexFilter?: RegExp) => Promise<string[]>;
/**
* lists Files SYNCHRONOUSLY in a directory on local disk
* @returns an array with the folder names as strings
*/
export declare const listFilesSync: (pathArg: string, regexFilter?: RegExp) => string[];
/**
* lists all items (folders AND files) in a directory on local disk
* @returns Promise<string[]>
*/
export declare const listAllItems: (pathArg: string, regexFilter?: RegExp) => Promise<string[]>;
/**
* lists all items (folders AND files) in a directory on local disk
* @returns an array with the folder names as strings
* @executes SYNC
*/
export declare const listAllItemsSync: (pathArg: string, regexFilter?: RegExp) => string[];
/**
* lists a file tree using a miniMatch filter
* note: if the miniMatch Filter is an absolute path, the cwdArg will be omitted
* @returns Promise<string[]> string array with the absolute paths of all matching files
*/
export declare const listFileTree: (dirPathArg: string, miniMatchFilter: string, absolutePathsBool?: boolean) => Promise<string[]>;
/**
* Watches for file stability before resolving the promise.
* Ensures that the directory/file exists before setting up the watcher.
*
* **New behavior**: If the given path is a directory, this function will:
* 1. Wait for that directory to exist (creating a timeout if needed).
* 2. Watch the directory until at least one file appears.
* 3. Then wait for the first file in the directory to stabilize before resolving.
*
* @param fileOrDirPathArg The path of the file or directory to monitor.
* @param timeoutMs The maximum time to wait for the file to stabilize (in milliseconds). Default is 60 seconds.
* @returns A promise that resolves when the target is stable or rejects on timeout/error.
*/
export declare const waitForFileToBeReady: (fileOrDirPathArg: string, timeoutMs?: number) => Promise<void>;
/**
* writes string or Smartfile to disk.
* @param fileArg
* @param fileNameArg
* @param fileBaseArg
*/
export declare let toFs: (fileContentArg: string | Buffer | SmartFile | StreamFile, filePathArg: string, optionsArg?: {
respectRelative?: boolean;
}) => Promise<unknown>;
export declare const stat: (filePathArg: string) => Promise<plugins.fs.Stats>;