import * as JSONC from 'jsonc-parser'; import type { AbsolutePath } from '@-xun/fs'; import type { EmptyObject, JsonValue } from 'type-fest'; export { JSONC }; /** * @see {@link readJsonc} */ export type ReadJsoncOptions = { /** * If `true`, so long as the `parse` function does not throw, this function * will return the result. Note that this could result in an incomplete or * corrupted (but syntactically sound) object. * * @default false */ ignoreNonExceptionErrors?: boolean; /** * 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; /** * @see {@link JSONC.parse} */ parseOptions?: Parameters[2]; /** * 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 JSONC 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 readJsonc(path: AbsolutePath, options: ReadJsoncOptions & { try?: false; }): Promise; export declare function readJsonc(path: AbsolutePath, options: ReadJsoncOptions): Promise; export declare namespace readJsonc { /** * Synchronously read in and parse the contents of an arbitrary JSONC 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 readJsoncSync(path: AbsolutePath, options: ReadJsoncOptions & { try?: false; }): T; function readJsoncSync(path: AbsolutePath, options: ReadJsoncOptions): T | EmptyObject; export const sync: typeof readJsoncSync; export {}; }