jsonc.d.mts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { F as FormatOptions } from './shared/confbox.B202Uz6F.mjs';
  2. /**
  3. *
  4. * Converts a [JSONC](https://github.com/microsoft/node-jsonc-parser) string into an object.
  5. *
  6. * @NOTE On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
  7. *
  8. * @NOTE Comments and trailing commas are not preserved after parsing.
  9. *
  10. * @template T The type of the return value.
  11. * @param text The string to parse as JSONC.
  12. * @param options Parsing options.
  13. * @returns The JavaScript value converted from the JSONC string.
  14. */
  15. declare function parseJSONC<T = unknown>(text: string, options?: JSONCParseOptions): T;
  16. /**
  17. * Converts a JavaScript value to a [JSONC](https://github.com/microsoft/node-jsonc-parser) string.
  18. *
  19. * @NOTE Comments and trailing commas are not preserved in the output.
  20. *
  21. * @param value
  22. * @param options
  23. * @returns The JSON string converted from the JavaScript value.
  24. */
  25. declare function stringifyJSONC(value: any, options?: JSONCStringifyOptions): string;
  26. interface JSONCParseOptions extends FormatOptions {
  27. disallowComments?: boolean;
  28. allowTrailingComma?: boolean;
  29. allowEmptyContent?: boolean;
  30. errors?: JSONCParseError[];
  31. }
  32. interface JSONCStringifyOptions extends FormatOptions {
  33. }
  34. interface JSONCParseError {
  35. error: number;
  36. offset: number;
  37. length: number;
  38. }
  39. export { parseJSONC, stringifyJSONC };
  40. export type { JSONCParseError, JSONCParseOptions, JSONCStringifyOptions };