stringify.d.ts 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. declare type StringifyOptions = {
  2. /**
  3. * A function that alters the behavior of the stringification process, or an
  4. * array of String and Number objects that serve as a allowlist for
  5. * selecting/filtering the properties of the value object to be included in
  6. * the JSON5 string. If this value is null or not provided, all properties
  7. * of the object are included in the resulting JSON5 string.
  8. */
  9. replacer?:
  10. | ((this: any, key: string, value: any) => any)
  11. | (string | number)[]
  12. | null
  13. /**
  14. * A String or Number object that's used to insert white space into the
  15. * output JSON5 string for readability purposes. If this is a Number, it
  16. * indicates the number of space characters to use as white space; this
  17. * number is capped at 10 (if it is greater, the value is just 10). Values
  18. * less than 1 indicate that no space should be used. If this is a String,
  19. * the string (or the first 10 characters of the string, if it's longer than
  20. * that) is used as white space. If this parameter is not provided (or is
  21. * null), no white space is used. If white space is used, trailing commas
  22. * will be used in objects and arrays.
  23. */
  24. space?: string | number | null
  25. /**
  26. * A String representing the quote character to use when serializing
  27. * strings.
  28. */
  29. quote?: string | null
  30. }
  31. /**
  32. * Converts a JavaScript value to a JSON5 string.
  33. * @param value The value to convert to a JSON5 string.
  34. * @param replacer A function that alters the behavior of the stringification
  35. * process. If this value is null or not provided, all properties of the object
  36. * are included in the resulting JSON5 string.
  37. * @param space A String or Number object that's used to insert white space into
  38. * the output JSON5 string for readability purposes. If this is a Number, it
  39. * indicates the number of space characters to use as white space; this number
  40. * is capped at 10 (if it is greater, the value is just 10). Values less than 1
  41. * indicate that no space should be used. If this is a String, the string (or
  42. * the first 10 characters of the string, if it's longer than that) is used as
  43. * white space. If this parameter is not provided (or is null), no white space
  44. * is used. If white space is used, trailing commas will be used in objects and
  45. * arrays.
  46. * @returns The JSON5 string converted from the JavaScript value.
  47. */
  48. declare function stringify(
  49. value: any,
  50. replacer?: ((this: any, key: string, value: any) => any) | null,
  51. space?: string | number | null,
  52. ): string
  53. /**
  54. * Converts a JavaScript value to a JSON5 string.
  55. * @param value The value to convert to a JSON5 string.
  56. * @param replacer An array of String and Number objects that serve as a
  57. * allowlist for selecting/filtering the properties of the value object to be
  58. * included in the JSON5 string. If this value is null or not provided, all
  59. * properties of the object are included in the resulting JSON5 string.
  60. * @param space A String or Number object that's used to insert white space into
  61. * the output JSON5 string for readability purposes. If this is a Number, it
  62. * indicates the number of space characters to use as white space; this number
  63. * is capped at 10 (if it is greater, the value is just 10). Values less than 1
  64. * indicate that no space should be used. If this is a String, the string (or
  65. * the first 10 characters of the string, if it's longer than that) is used as
  66. * white space. If this parameter is not provided (or is null), no white space
  67. * is used. If white space is used, trailing commas will be used in objects and
  68. * arrays.
  69. * @returns The JSON5 string converted from the JavaScript value.
  70. */
  71. declare function stringify(
  72. value: any,
  73. replacer: (string | number)[],
  74. space?: string | number | null,
  75. ): string
  76. /**
  77. * Converts a JavaScript value to a JSON5 string.
  78. * @param value The value to convert to a JSON5 string.
  79. * @param options An object specifying options.
  80. * @returns The JSON5 string converted from the JavaScript value.
  81. */
  82. declare function stringify(value: any, options: StringifyOptions): string
  83. export = stringify