1 | // From https://github.com/sindresorhus/type-fest
|
2 | export type JsonValue = string | number | boolean | null | {[Key in string]?: JsonValue} | JsonValue[];
|
3 |
|
4 | export type Reviver = (this: unknown, key: string, value: unknown) => unknown;
|
5 | export type BeforeParse = (data: string) => string;
|
6 |
|
7 | export interface Options {
|
8 | /**
|
9 | Applies a function to the JSON string before parsing.
|
10 | */
|
11 | readonly beforeParse?: BeforeParse;
|
12 |
|
13 | /**
|
14 | Prescribes how the value originally produced by parsing is transformed, before being returned.
|
15 | See the [`JSON.parse` docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Using_the_reviver_parameter) for more.
|
16 | */
|
17 | readonly reviver?: Reviver;
|
18 | }
|
19 |
|
20 | /**
|
21 | Read and parse a JSON file.
|
22 |
|
23 | It also strips UTF-8 BOM.
|
24 |
|
25 | @example
|
26 | ```
|
27 | import {loadJsonFile} from 'load-json-file';
|
28 |
|
29 | const json = await loadJsonFile('foo.json');
|
30 | //=> {foo: true}
|
31 | ```
|
32 | */
|
33 | export function loadJsonFile<ReturnValueType = JsonValue>(filePath: string, options?: Options): Promise<ReturnValueType>;
|
34 |
|
35 | /**
|
36 | Read and parse a JSON file.
|
37 |
|
38 | It also strips UTF-8 BOM.
|
39 |
|
40 | @example
|
41 | ```
|
42 | import {loadJsonFileSync} from 'load-json-file';
|
43 |
|
44 | const json = loadJsonFileSync('foo.json');
|
45 | //=> {foo: true}
|
46 | ```
|
47 | */
|
48 | export function loadJsonFileSync<ReturnValueType = JsonValue>(filePath: string, options?: Options): ReturnValueType;
|