1 | export interface Options {
|
2 | /**
|
3 | Replace comments with whitespace instead of stripping them entirely.
|
4 |
|
5 | @default true
|
6 | */
|
7 | readonly whitespace?: boolean;
|
8 | }
|
9 |
|
10 | /**
|
11 | Strip comments from JSON. Lets you use comments in your JSON files!
|
12 |
|
13 | It will replace single-line comments `//` and multi-line comments `/**\/` with whitespace. This allows JSON error positions to remain as close as possible to the original source.
|
14 |
|
15 | @param jsonString - Accepts a string with JSON.
|
16 | @returns A JSON string without comments.
|
17 |
|
18 | @example
|
19 | ```
|
20 | import stripJsonComments from 'strip-json-comments';
|
21 |
|
22 | const json = `{
|
23 | // Rainbows
|
24 | "unicorn": "cake"
|
25 | }`;
|
26 |
|
27 | JSON.parse(stripJsonComments(json));
|
28 | //=> {unicorn: 'cake'}
|
29 | ```
|
30 | */
|
31 | export default function stripJsonComments(
|
32 | jsonString: string,
|
33 | options?: Options
|
34 | ): string;
|