UNPKG

781 BTypeScriptView Raw
1export 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/**
11Strip comments from JSON. Lets you use comments in your JSON files!
12
13It 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```
20import stripJsonComments from 'strip-json-comments';
21
22const json = `{
23 // Rainbows
24 "unicorn": "cake"
25}`;
26
27JSON.parse(stripJsonComments(json));
28//=> {unicorn: 'cake'}
29```
30*/
31export default function stripJsonComments(
32 jsonString: string,
33 options?: Options
34): string;