UNPKG

@thi.ng/file-io

Version:

Assorted file I/O utils (w/ logging support) for NodeJS/Bun

62 lines 1.9 kB
import type { Fn3, Maybe, Nullable, NumOrString } from "@thi.ng/api"; import type { ILogger } from "@thi.ng/logger"; /** * Reads given file as UTF-8 and parses result as JSON of type `T`. * * @param path * @param logger */ export declare const readJSON: <T = any>(path: string, logger?: ILogger) => T; /** * Async version of {@link readJSON}. * * @param path * @param logger */ export declare const readJSONAsync: <T = any>(path: string, logger?: ILogger) => Promise<T>; /** * Similar to {@link readJSON}, reads JSON file with comments. * * @remarks * **IMPORTANT:** Only `//` single line comments (with optional leading * whitespace) are supported! This is NOT a full JSONC parser. * * @param path * @param logger */ export declare const readJSONC: <T = any>(path: string, logger?: ILogger) => T; /** * Async version of {@link readJSONC}. * * @param path * @param logger */ export declare const readJSONCAsync: <T = any>(path: string, logger?: ILogger) => Promise<T>; /** * Serializes `obj` to JSON and writes result to UTF-8 file `path`. See * {@link writeText} for more details. * * @remarks * The `replacer` and `space` args are the same as supported by * `JSON.stringify()`. * * @param path * @param obj * @param replacer * @param space * @param logger * @param dryRun */ export declare const writeJSON: (path: string, obj: any, replacer?: Fn3<any, string, any, any> | Nullable<NumOrString[]>, space?: Maybe<NumOrString>, logger?: ILogger, dryRun?: boolean) => void; /** * Async version of {@link writeJSON}. * * @param path * @param obj * @param replacer * @param space * @param logger * @param dryRun */ export declare const writeJSONAsync: (path: string, obj: any, replacer?: Fn3<any, string, any, any> | Nullable<NumOrString[]>, space?: Maybe<NumOrString>, logger?: ILogger, dryRun?: boolean) => Promise<void>; //# sourceMappingURL=json.d.ts.map