types.d.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. interface Flatted {
  2. /**
  3. * Converts a JavaScript Object Notation (using Flatted encoding) string into an object.
  4. * @param text A valid Flatted string.
  5. * @param reviver A function that transforms the results. This function is called for each member of the object.
  6. * If a member contains nested objects, the nested objects are transformed before the parent object is.
  7. */
  8. parse(
  9. text: string,
  10. reviver?: (this: any, key: string, value: any) => any
  11. ): any;
  12. /**
  13. * Converts a JavaScript value to a JavaScript Object Notation (using Flatted encoding) string.
  14. * @param value A JavaScript value, usually an object or array, to be converted.
  15. * @param replacer A function that transforms the results.
  16. * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
  17. */
  18. stringify(
  19. value: any,
  20. replacer?: (this: any, key: string, value: any) => any,
  21. space?: string | number
  22. ): string;
  23. /**
  24. * Converts a JavaScript value to a JavaScript Object Notation (using Flatted encoding) string.
  25. * @param value A JavaScript value, usually an object or array, to be converted.
  26. * @param replacer An array of strings and numbers that acts as an approved list for selecting the object properties that will be stringified.
  27. * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
  28. */
  29. stringify(
  30. value: any,
  31. replacer?: (number | string)[] | null,
  32. space?: string | number
  33. ): string;
  34. }
  35. /**
  36. * Fast and minimal circular JSON parser.
  37. * logic example
  38. ```js
  39. var a = [{one: 1}, {two: '2'}];
  40. a[0].a = a;
  41. // a is the main object, will be at index '0'
  42. // {one: 1} is the second object, index '1'
  43. // {two: '2'} the third, in '2', and it has a string
  44. // which will be found at index '3'
  45. Flatted.stringify(a);
  46. // [["1","2"],{"one":1,"a":"0"},{"two":"3"},"2"]
  47. // a[one,two] {one: 1, a} {two: '2'} '2'
  48. ```
  49. */
  50. declare const Flatted: Flatted;
  51. export = Flatted;