UNPKG

@nasriya/atomix

Version:

Composable helper functions for building reliable systems

41 lines (40 loc) 1.73 kB
import { AccessOptions } from './docs'; declare class FileSystemUtils { /** * Provides async promises for file system operations. * * @returns The fsPromises instance. * @since v1.0.0 */ get promises(): { loadJSON(filePath: string): Promise<Record<string, any> | Array<any>>; canAccess(filePath: string, options?: AccessOptions): Promise<boolean>; }; /** * Loads a JSON file from the given path, returning its contents as a Record or Array. * * @param filePath - The path to the JSON file to load. * @returns The contents of the JSON file as a Record or Array. * @throws Error if the file does not exist, is not a valid JSON file, or if the user does not have enough permissions to access the file. * @since v1.0.0 * @example * const configFile = loadJSON('config.json'); * // configFile is the contents of the file as a Record or Array */ loadJSONSync(filePath: string): Record<string, any> | Array<any>; /** * Checks if the given file path is accessible by the current user. * * @param filePath - The path to the file to check. * @param options - An object containing the property "throwError". * @param options.throwError - If true, throws an error if the file is not accessible. If false, returns false. * @returns True if the file is accessible, false otherwise. * @since v1.0.0 * @example * const canAccess = canAccessSync('path/to/file.txt'); * // canAccess is true if the file is accessible, false otherwise */ canAccessSync(filePath: string, options?: AccessOptions): boolean; } declare const fileSystem: FileSystemUtils; export default fileSystem;