fxb.d.cts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // const { Expression } = require('path-expression-matcher');
  2. type Matcher = unknown;
  3. type Expression = unknown;
  4. type XmlBuilderOptions = {
  5. /**
  6. * Give a prefix to the attribute name in the resulting JS object
  7. *
  8. * Defaults to '@_'
  9. */
  10. attributeNamePrefix?: string;
  11. /**
  12. * A name to group all attributes of a tag under, or `false` to disable
  13. *
  14. * Defaults to `false`
  15. */
  16. attributesGroupName?: false | string;
  17. /**
  18. * The name of the next node in the resulting JS
  19. *
  20. * Defaults to `#text`
  21. */
  22. textNodeName?: string;
  23. /**
  24. * Whether to ignore attributes when building
  25. *
  26. * When `true` - ignores all the attributes
  27. *
  28. * When `false` - builds all the attributes
  29. *
  30. * When `Array<string | RegExp>` - filters out attributes that match provided patterns
  31. *
  32. * When `Function` - calls the function for each attribute and filters out those for which the function returned `true`
  33. *
  34. * Defaults to `true`
  35. */
  36. ignoreAttributes?: boolean | (string | RegExp)[] | ((attrName: string, jPath: string) => boolean);
  37. /**
  38. * Give a property name to set CDATA values to instead of merging to tag's text value
  39. *
  40. * Defaults to `false`
  41. */
  42. cdataPropName?: false | string;
  43. /**
  44. * If set, parse comments and set as this property
  45. *
  46. * Defaults to `false`
  47. */
  48. commentPropName?: false | string;
  49. /**
  50. * Whether to make output pretty instead of single line
  51. *
  52. * Defaults to `false`
  53. */
  54. format?: boolean;
  55. /**
  56. * If `format` is set to `true`, sets the indent string
  57. *
  58. * Defaults to ` `
  59. */
  60. indentBy?: string;
  61. /**
  62. * Give a name to a top-level array
  63. *
  64. * Defaults to `undefined`
  65. */
  66. arrayNodeName?: string;
  67. /**
  68. * Create empty tags for tags with no text value
  69. *
  70. * Defaults to `false`
  71. */
  72. suppressEmptyNode?: boolean;
  73. /**
  74. * Suppress an unpaired tag
  75. *
  76. * Defaults to `true`
  77. */
  78. suppressUnpairedNode?: boolean;
  79. /**
  80. * Don't put a value for boolean attributes
  81. *
  82. * Defaults to `true`
  83. */
  84. suppressBooleanAttributes?: boolean;
  85. /**
  86. * Preserve the order of tags in resulting JS object
  87. *
  88. * Defaults to `false`
  89. */
  90. preserveOrder?: boolean;
  91. /**
  92. * List of tags without closing tags
  93. *
  94. * Defaults to `[]`
  95. */
  96. unpairedTags?: string[];
  97. /**
  98. * Nodes to stop parsing at
  99. *
  100. * Accepts string patterns or Expression objects from path-expression-matcher
  101. *
  102. * String patterns starting with "*." are automatically converted to ".." for backward compatibility
  103. *
  104. * Defaults to `[]`
  105. */
  106. stopNodes?: (string | Expression)[];
  107. /**
  108. * Control how tag value should be parsed. Called only if tag value is not empty
  109. *
  110. * @returns {undefined|null} `undefined` or `null` to set original value.
  111. * @returns {unknown}
  112. *
  113. * 1. Different value or value with different data type to set new value.
  114. * 2. Same value to set parsed value if `parseTagValue: true`.
  115. *
  116. * Defaults to `(tagName, val, jPath, hasAttributes, isLeafNode) => val`
  117. */
  118. tagValueProcessor?: (name: string, value: unknown) => unknown;
  119. /**
  120. * Control how attribute value should be parsed
  121. *
  122. * @param attrName
  123. * @param attrValue
  124. * @param jPath
  125. * @returns {undefined|null} `undefined` or `null` to set original value
  126. * @returns {unknown}
  127. *
  128. * Defaults to `(attrName, val, jPath) => val`
  129. */
  130. attributeValueProcessor?: (name: string, value: unknown) => unknown;
  131. /**
  132. * Whether to process default and DOCTYPE entities
  133. *
  134. * Defaults to `true`
  135. */
  136. processEntities?: boolean;
  137. oneListGroup?: boolean;
  138. /**
  139. * Maximum number of nested tags
  140. *
  141. * Defaults to `100`
  142. */
  143. maxNestedTags?: number;
  144. };
  145. interface XMLBuilder {
  146. build(jObj: any): string;
  147. }
  148. interface XMLBuilderConstructor {
  149. new(options?: XmlBuilderOptions): XMLBuilder;
  150. (options?: XmlBuilderOptions): XMLBuilder;
  151. }
  152. declare const Builder: XMLBuilderConstructor;
  153. export = Builder;