You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 rivejä
807 B

3 vuotta sitten
  1. declare namespace stripJsonComments {
  2. interface Options {
  3. /**
  4. Replace comments with whitespace instead of stripping them entirely.
  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. 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.
  13. @param jsonString - Accepts a string with JSON.
  14. @returns A JSON string without comments.
  15. @example
  16. ```
  17. const json = `{
  18. // Rainbows
  19. "unicorn": "cake"
  20. }`;
  21. JSON.parse(stripJsonComments(json));
  22. //=> {unicorn: 'cake'}
  23. ```
  24. */
  25. declare function stripJsonComments(
  26. jsonString: string,
  27. options?: stripJsonComments.Options
  28. ): string;
  29. export = stripJsonComments;