index.d.ts 807 B

123456789101112131415161718192021222324252627282930313233343536
  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;