|
1 |
| -export type Reviver = (this: unknown, key: string, value: unknown) => unknown; |
2 |
| -export type BeforeParse = (data: string) => string; |
| 1 | +import {JsonValue} from 'type-fest'; |
3 | 2 |
|
4 |
| -export interface Options { |
| 3 | +declare namespace loadJsonFile { |
| 4 | + type Reviver = (this: unknown, key: string, value: any) => unknown; |
| 5 | + type BeforeParse = (data: string) => string; |
| 6 | + |
| 7 | + 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 | +declare const loadJsonFile: { |
5 | 22 | /**
|
6 |
| - * Applies a function to the JSON string before parsing. |
7 |
| - */ |
8 |
| - readonly beforeParse?: BeforeParse; |
| 23 | + Read and parse a JSON file. |
| 24 | +
|
| 25 | + Strips UTF-8 BOM, uses graceful-fs, and throws more helpful JSON errors. |
| 26 | +
|
| 27 | + @example |
| 28 | + ``` |
| 29 | + import loadJsonFile = require('load-json-file'); |
| 30 | +
|
| 31 | + (async () => { |
| 32 | + const json = await loadJsonFile('foo.json'); |
| 33 | + //=> {foo: true} |
| 34 | + })(); |
| 35 | + ``` |
| 36 | + */ |
| 37 | + <T = JsonValue>(filePath: string, options?: loadJsonFile.Options): Promise<T>; |
9 | 38 |
|
10 | 39 | /**
|
11 |
| - * Prescribes how the value originally produced by parsing is transformed, before being returned. |
12 |
| - * 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. |
13 |
| - */ |
14 |
| - readonly reviver?: Reviver; |
15 |
| -} |
| 40 | + Read and parse a JSON file. |
| 41 | +
|
| 42 | + Strips UTF-8 BOM, uses graceful-fs, and throws more helpful JSON errors. |
| 43 | +
|
| 44 | + @example |
| 45 | + ``` |
| 46 | + import loadJsonFile = require('load-json-file'); |
| 47 | +
|
| 48 | + const json = loadJsonFile.sync('foo.json'); |
| 49 | + //=> {foo: true} |
| 50 | + ``` |
| 51 | + */ |
| 52 | + sync<T = JsonValue>(filePath: string, options?: loadJsonFile.Options): T; |
| 53 | + |
| 54 | + // TODO: Remove this for the next major release |
| 55 | + default: typeof loadJsonFile; |
| 56 | +}; |
16 | 57 |
|
17 |
| -/** |
18 |
| - * Read and parse a JSON file. |
19 |
| - * |
20 |
| - * Strips UTF-8 BOM, uses graceful-fs, and throws more helpful JSON errors. |
21 |
| - * |
22 |
| - * @example |
23 |
| - * |
24 |
| - * import loadJsonFile from 'load-json-file'; |
25 |
| - * |
26 |
| - * (async () => { |
27 |
| - * const json = await loadJsonFile('foo.json'); |
28 |
| - * //=> {foo: true} |
29 |
| - * })(); |
30 |
| - */ |
31 |
| -export default function loadJsonFile<T = unknown>(filePath: string, options?: Options): Promise<T>; |
32 |
| - |
33 |
| -/** |
34 |
| - * Read and parse a JSON file. |
35 |
| - * |
36 |
| - * Strips UTF-8 BOM, uses graceful-fs, and throws more helpful JSON errors. |
37 |
| - * |
38 |
| - * @example |
39 |
| - * |
40 |
| - * import * as loadJsonFile from 'load-json-file'; |
41 |
| - * |
42 |
| - * const json = loadJsonFile.sync('foo.json'); |
43 |
| - * //=> {foo: true} |
44 |
| - */ |
45 |
| -export function sync<T = unknown>(filePath: string, options?: Options): T; |
| 58 | +export = loadJsonFile; |
0 commit comments