1 | export type Options = {
|
2 | /**
|
3 | Strip trailing commas in addition to comments.
|
4 |
|
5 | @default false
|
6 | */
|
7 | readonly trailingCommas?: boolean;
|
8 |
|
9 | /**
|
10 | Replace comments and trailing commas with whitespace instead of stripping them entirely.
|
11 |
|
12 | @default true
|
13 | */
|
14 | readonly whitespace?: boolean;
|
15 | };
|
16 |
|
17 | /**
|
18 | Strip comments from JSON. Lets you use comments in your JSON files!
|
19 |
|
20 | 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.
|
21 |
|
22 | @param jsonString - Accepts a string with JSON.
|
23 | @returns A JSON string without comments.
|
24 |
|
25 | @example
|
26 | ```
|
27 | import stripJsonComments from 'strip-json-comments';
|
28 |
|
29 | const json = `{
|
30 | // Rainbows
|
31 | "unicorn": "cake"
|
32 | }`;
|
33 |
|
34 | JSON.parse(stripJsonComments(json));
|
35 | //=> {unicorn: 'cake'}
|
36 | ```
|
37 | */
|
38 | export default function stripJsonComments(
|
39 | jsonString: string,
|
40 | options?: Options
|
41 | ): string;
|