index.d.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import './style.less';
  2. export interface JSONFormatterConfiguration {
  3. hoverPreviewEnabled?: boolean;
  4. hoverPreviewArrayCount?: number;
  5. hoverPreviewFieldCount?: number;
  6. animateOpen?: boolean;
  7. animateClose?: boolean;
  8. theme?: string;
  9. }
  10. /**
  11. * @class JSONFormatter
  12. *
  13. * JSONFormatter allows you to render JSON objects in HTML with a
  14. * **collapsible** navigation.
  15. */
  16. export default class JSONFormatter {
  17. json: any;
  18. private open;
  19. private config;
  20. private key;
  21. private _isOpen;
  22. private element;
  23. /**
  24. * @param {object} json The JSON object you want to render. It has to be an
  25. * object or array. Do NOT pass raw JSON string.
  26. *
  27. * @param {number} [open=1] his number indicates up to how many levels the
  28. * rendered tree should expand. Set it to `0` to make the whole tree collapsed
  29. * or set it to `Infinity` to expand the tree deeply
  30. *
  31. * @param {object} [config=defaultConfig] -
  32. * defaultConfig = {
  33. * hoverPreviewEnabled: false,
  34. * hoverPreviewArrayCount: 100,
  35. * hoverPreviewFieldCount: 5
  36. * }
  37. *
  38. * Available configurations:
  39. * #####Hover Preview
  40. * * `hoverPreviewEnabled`: enable preview on hover
  41. * * `hoverPreviewArrayCount`: number of array items to show in preview Any
  42. * array larger than this number will be shown as `Array[XXX]` where `XXX`
  43. * is length of the array.
  44. * * `hoverPreviewFieldCount`: number of object properties to show for object
  45. * preview. Any object with more properties that thin number will be
  46. * truncated.
  47. *
  48. * @param {string} [key=undefined] The key that this object in it's parent
  49. * context
  50. */
  51. constructor(json: any, open?: number, config?: JSONFormatterConfiguration, key?: string);
  52. private isOpen;
  53. private readonly isDate;
  54. private readonly isUrl;
  55. private readonly isArray;
  56. private readonly isObject;
  57. private readonly isEmptyObject;
  58. private readonly isEmpty;
  59. private readonly hasKey;
  60. private readonly constructorName;
  61. private readonly type;
  62. private readonly keys;
  63. /**
  64. * Toggles `isOpen` state
  65. *
  66. */
  67. toggleOpen(): void;
  68. /**
  69. * Open all children up to a certain depth.
  70. * Allows actions such as expand all/collapse all
  71. *
  72. */
  73. openAtDepth(depth?: number): void;
  74. /**
  75. * Generates inline preview
  76. *
  77. * @returns {string}
  78. */
  79. getInlinepreview(): string;
  80. /**
  81. * Renders an HTML element and installs event listeners
  82. *
  83. * @returns {HTMLDivElement}
  84. */
  85. render(): HTMLDivElement;
  86. /**
  87. * Appends all the children to children element
  88. * Animated option is used when user triggers this via a click
  89. */
  90. appendChildren(animated?: boolean): void;
  91. /**
  92. * Removes all the children from children element
  93. * Animated option is used when user triggers this via a click
  94. */
  95. removeChildren(animated?: boolean): void;
  96. }