import type { AbsolutePath } from '@-xun/fs'; import type { EmptyObject, JsonValue } from 'type-fest'; /** * @see {@link readJson} */ export type ReadJsonOptions = { /** * Use the internal cached result from a previous run, if available. * * Unless `useCached` is `false`, the results returned by this function will * always strictly equal (`===`) each other with respect to call signature. * * @see {@link cache} */ useCached: boolean; /** * If `true`, an attempt will be made to read in and parse the JSON file. If * it fails (i.e. an error is thrown), `{}` is returned and no error is * thrown. * * Note that, currently, fail results (where `{}` is returned) are not cached. * * @default false */ try?: boolean; }; /** * Asynchronously read in and parse the contents of an arbitrary JSON file. * * Use the template variable (`T`) to bring your own types. Otherwise, it * defaults to {@link JsonValue}. * * **NOTE: the result of this function is memoized! This does NOT _necessarily_ * mean results will strictly equal each other. See `useCached` in this specific * function's options for details.** To fetch fresh results, set the `useCached` * option to `false` or clear the internal cache with {@link cache.clear}. */ export declare function readJson(path: AbsolutePath, options: ReadJsonOptions & { try?: false; }): Promise; export declare function readJson(path: AbsolutePath, options: ReadJsonOptions): Promise; export declare namespace readJson { /** * Synchronously read in and parse the contents of an arbitrary JSON file. * * Use the template variable (`T`) to bring your own types. Otherwise, it * defaults to {@link JsonValue}. * * **NOTE: the result of this function is memoized! This does NOT * _necessarily_ mean results will strictly equal each other. See `useCached` * in this specific function's options for details.** To fetch fresh results, * set the `useCached` option to `false` or clear the internal cache with * {@link cache.clear}. */ function readJsonSync(path: AbsolutePath, options: ReadJsonOptions & { try?: false; }): T; function readJsonSync(path: AbsolutePath, options: ReadJsonOptions): T | EmptyObject; export const sync: typeof readJsonSync; export {}; }