@loaders.gl/xml 3.3.2 → 3.4.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/dist.min.js +365 -183
  2. package/dist/es5/html-loader.js +59 -0
  3. package/dist/es5/html-loader.js.map +1 -0
  4. package/dist/es5/index.js +33 -0
  5. package/dist/es5/index.js.map +1 -1
  6. package/dist/es5/lib/{parse-xml.js → parsers/parse-xml.js} +7 -6
  7. package/dist/es5/lib/parsers/parse-xml.js.map +1 -0
  8. package/dist/es5/lib/{parser/xml-parser.js → parsers/streaming-xml-parser.js} +8 -8
  9. package/dist/es5/lib/parsers/streaming-xml-parser.js.map +1 -0
  10. package/dist/es5/lib/xml-utils/uncapitalize.js +34 -0
  11. package/dist/es5/lib/xml-utils/uncapitalize.js.map +1 -0
  12. package/dist/es5/lib/xml-utils/xml-utils.js +26 -0
  13. package/dist/es5/lib/xml-utils/xml-utils.js.map +1 -0
  14. package/dist/es5/xml-loader.js +41 -5
  15. package/dist/es5/xml-loader.js.map +1 -1
  16. package/dist/esm/html-loader.js +29 -0
  17. package/dist/esm/html-loader.js.map +1 -0
  18. package/dist/esm/index.js +6 -0
  19. package/dist/esm/index.js.map +1 -1
  20. package/dist/esm/lib/{parse-xml.js → parsers/parse-xml.js} +6 -5
  21. package/dist/esm/lib/parsers/parse-xml.js.map +1 -0
  22. package/dist/esm/lib/{parser/xml-parser.js → parsers/streaming-xml-parser.js} +2 -2
  23. package/dist/esm/lib/parsers/streaming-xml-parser.js.map +1 -0
  24. package/dist/esm/lib/xml-utils/uncapitalize.js +20 -0
  25. package/dist/esm/lib/xml-utils/uncapitalize.js.map +1 -0
  26. package/dist/esm/lib/xml-utils/xml-utils.js +18 -0
  27. package/dist/esm/lib/xml-utils/xml-utils.js.map +1 -0
  28. package/dist/esm/xml-loader.js +40 -5
  29. package/dist/esm/xml-loader.js.map +1 -1
  30. package/dist/html-loader.d.ts +11 -0
  31. package/dist/html-loader.d.ts.map +1 -0
  32. package/dist/html-loader.js +40 -0
  33. package/dist/index.d.ts +4 -0
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +11 -1
  36. package/dist/lib/parsers/parse-xml.d.ts +12 -0
  37. package/dist/lib/parsers/parse-xml.d.ts.map +1 -0
  38. package/dist/lib/{parse-xml.js → parsers/parse-xml.js} +7 -8
  39. package/dist/lib/{parser/xml-parser.d.ts → parsers/streaming-xml-parser.d.ts} +6 -2
  40. package/dist/lib/parsers/streaming-xml-parser.d.ts.map +1 -0
  41. package/dist/lib/{parser/xml-parser.js → parsers/streaming-xml-parser.js} +6 -6
  42. package/dist/lib/xml-utils/uncapitalize.d.ts +13 -0
  43. package/dist/lib/xml-utils/uncapitalize.d.ts.map +1 -0
  44. package/dist/lib/xml-utils/uncapitalize.js +32 -0
  45. package/dist/lib/xml-utils/xml-utils.d.ts +11 -0
  46. package/dist/lib/xml-utils/xml-utils.d.ts.map +1 -0
  47. package/dist/lib/xml-utils/xml-utils.js +30 -0
  48. package/dist/xml-loader.d.ts +21 -3
  49. package/dist/xml-loader.d.ts.map +1 -1
  50. package/dist/xml-loader.js +41 -5
  51. package/package.json +5 -5
  52. package/src/html-loader.ts +46 -0
  53. package/src/index.ts +16 -0
  54. package/src/lib/{parse-xml.ts → parsers/parse-xml.ts} +9 -6
  55. package/src/lib/{parser/xml-parser.ts → parsers/streaming-xml-parser.ts} +5 -3
  56. package/src/lib/xml-utils/uncapitalize.ts +31 -0
  57. package/src/lib/xml-utils/xml-utils.ts +27 -0
  58. package/src/xml-loader.ts +63 -6
  59. package/dist/es5/lib/parse-xml.js.map +0 -1
  60. package/dist/es5/lib/parser/xml-parser.js.map +0 -1
  61. package/dist/esm/lib/parse-xml.js.map +0 -1
  62. package/dist/esm/lib/parser/xml-parser.js.map +0 -1
  63. package/dist/lib/parse-xml.d.ts +0 -9
  64. package/dist/lib/parse-xml.d.ts.map +0 -1
  65. package/dist/lib/parser/xml-parser.d.ts.map +0 -1
package/dist/dist.min.js CHANGED
@@ -1740,13 +1740,14 @@ Actual: ${this.attribValue}`);
1740
1740
  cdataPropName: false,
1741
1741
  numberParseOptions: {
1742
1742
  hex: true,
1743
- leadingZeros: true
1743
+ leadingZeros: true,
1744
+ eNotation: true
1744
1745
  },
1745
- tagValueProcessor: function(tagName, val) {
1746
- return val;
1746
+ tagValueProcessor: function(tagName, val2) {
1747
+ return val2;
1747
1748
  },
1748
- attributeValueProcessor: function(attrName, val) {
1749
- return val;
1749
+ attributeValueProcessor: function(attrName, val2) {
1750
+ return val2;
1750
1751
  },
1751
1752
  stopNodes: [],
1752
1753
  alwaysCreateTextNode: false,
@@ -1757,7 +1758,8 @@ Actual: ${this.attribValue}`);
1757
1758
  htmlEntities: false,
1758
1759
  ignoreDeclaration: false,
1759
1760
  ignorePiTags: false,
1760
- transformTagName: false
1761
+ transformTagName: false,
1762
+ transformAttributeName: false
1761
1763
  };
1762
1764
  var buildOptions = function(options) {
1763
1765
  return Object.assign({}, defaultOptions, options);
@@ -1777,10 +1779,14 @@ Actual: ${this.attribValue}`);
1777
1779
  this.child = [];
1778
1780
  this[":@"] = {};
1779
1781
  }
1780
- add(key, val) {
1781
- this.child.push({ [key]: val });
1782
+ add(key, val2) {
1783
+ if (key === "__proto__")
1784
+ key = "#__proto__";
1785
+ this.child.push({ [key]: val2 });
1782
1786
  }
1783
1787
  addChild(node) {
1788
+ if (node.tagname === "__proto__")
1789
+ node.tagname = "#__proto__";
1784
1790
  if (node[":@"] && Object.keys(node[":@"]).length > 0) {
1785
1791
  this.child.push({ [node.tagname]: node.child, [":@"]: node[":@"] });
1786
1792
  } else {
@@ -1800,38 +1806,39 @@ Actual: ${this.attribValue}`);
1800
1806
  if (xmlData[i + 3] === "O" && xmlData[i + 4] === "C" && xmlData[i + 5] === "T" && xmlData[i + 6] === "Y" && xmlData[i + 7] === "P" && xmlData[i + 8] === "E") {
1801
1807
  i = i + 9;
1802
1808
  let angleBracketsCount = 1;
1803
- let hasBody = false, entity = false, comment = false;
1809
+ let hasBody = false, comment = false;
1804
1810
  let exp = "";
1805
1811
  for (; i < xmlData.length; i++) {
1806
- if (xmlData[i] === "<") {
1807
- if (hasBody && xmlData[i + 1] === "!" && xmlData[i + 2] === "E" && xmlData[i + 3] === "N" && xmlData[i + 4] === "T" && xmlData[i + 5] === "I" && xmlData[i + 6] === "T" && xmlData[i + 7] === "Y") {
1812
+ if (xmlData[i] === "<" && !comment) {
1813
+ if (hasBody && isEntity(xmlData, i)) {
1808
1814
  i += 7;
1809
- entity = true;
1810
- } else if (hasBody && xmlData[i + 1] === "!" && xmlData[i + 2] === "E" && xmlData[i + 3] === "L" && xmlData[i + 4] === "E" && xmlData[i + 5] === "M" && xmlData[i + 6] === "E" && xmlData[i + 7] === "N" && xmlData[i + 8] === "T") {
1815
+ [entityName, val, i] = readEntityExp(xmlData, i + 1);
1816
+ if (val.indexOf("&") === -1)
1817
+ entities[entityName] = {
1818
+ regx: RegExp(`&${entityName};`, "g"),
1819
+ val
1820
+ };
1821
+ } else if (hasBody && isElement(xmlData, i))
1811
1822
  i += 8;
1812
- } else if (hasBody && xmlData[i + 1] === "!" && xmlData[i + 2] === "A" && xmlData[i + 3] === "T" && xmlData[i + 4] === "T" && xmlData[i + 5] === "L" && xmlData[i + 6] === "I" && xmlData[i + 7] === "S" && xmlData[i + 8] === "T") {
1823
+ else if (hasBody && isAttlist(xmlData, i))
1813
1824
  i += 8;
1814
- } else if (hasBody && xmlData[i + 1] === "!" && xmlData[i + 2] === "N" && xmlData[i + 3] === "O" && xmlData[i + 4] === "T" && xmlData[i + 5] === "A" && xmlData[i + 6] === "T" && xmlData[i + 7] === "I" && xmlData[i + 8] === "O" && xmlData[i + 9] === "N") {
1825
+ else if (hasBody && isNotation(xmlData, i))
1815
1826
  i += 9;
1816
- } else if (xmlData[i + 1] === "!" && xmlData[i + 2] === "-" && xmlData[i + 3] === "-") {
1827
+ else if (isComment)
1817
1828
  comment = true;
1818
- } else {
1829
+ else
1819
1830
  throw new Error("Invalid DOCTYPE");
1820
- }
1821
1831
  angleBracketsCount++;
1822
1832
  exp = "";
1823
1833
  } else if (xmlData[i] === ">") {
1824
1834
  if (comment) {
1825
1835
  if (xmlData[i - 1] === "-" && xmlData[i - 2] === "-") {
1826
1836
  comment = false;
1827
- } else {
1828
- throw new Error(`Invalid XML comment in DOCTYPE`);
1837
+ angleBracketsCount--;
1829
1838
  }
1830
- } else if (entity) {
1831
- parseEntityExp(exp, entities);
1832
- entity = false;
1839
+ } else {
1840
+ angleBracketsCount--;
1833
1841
  }
1834
- angleBracketsCount--;
1835
1842
  if (angleBracketsCount === 0) {
1836
1843
  break;
1837
1844
  }
@@ -1849,15 +1856,45 @@ Actual: ${this.attribValue}`);
1849
1856
  }
1850
1857
  return { entities, i };
1851
1858
  }
1852
- var entityRegex = RegExp(`^\\s([a-zA-z0-0]+)[ ](['"])([^&]+)\\2`);
1853
- function parseEntityExp(exp, entities) {
1854
- const match = entityRegex.exec(exp);
1855
- if (match) {
1856
- entities[match[1]] = {
1857
- regx: RegExp(`&${match[1]};`, "g"),
1858
- val: match[3]
1859
- };
1860
- }
1859
+ function readEntityExp(xmlData, i) {
1860
+ let entityName2 = "";
1861
+ for (; i < xmlData.length && (xmlData[i] !== "'" && xmlData[i] !== '"'); i++) {
1862
+ entityName2 += xmlData[i];
1863
+ }
1864
+ entityName2 = entityName2.trim();
1865
+ if (entityName2.indexOf(" ") !== -1)
1866
+ throw new Error("External entites are not supported");
1867
+ const startChar = xmlData[i++];
1868
+ let val2 = "";
1869
+ for (; i < xmlData.length && xmlData[i] !== startChar; i++) {
1870
+ val2 += xmlData[i];
1871
+ }
1872
+ return [entityName2, val2, i];
1873
+ }
1874
+ function isComment(xmlData, i) {
1875
+ if (xmlData[i + 1] === "!" && xmlData[i + 2] === "-" && xmlData[i + 3] === "-")
1876
+ return true;
1877
+ return false;
1878
+ }
1879
+ function isEntity(xmlData, i) {
1880
+ if (xmlData[i + 1] === "!" && xmlData[i + 2] === "E" && xmlData[i + 3] === "N" && xmlData[i + 4] === "T" && xmlData[i + 5] === "I" && xmlData[i + 6] === "T" && xmlData[i + 7] === "Y")
1881
+ return true;
1882
+ return false;
1883
+ }
1884
+ function isElement(xmlData, i) {
1885
+ if (xmlData[i + 1] === "!" && xmlData[i + 2] === "E" && xmlData[i + 3] === "L" && xmlData[i + 4] === "E" && xmlData[i + 5] === "M" && xmlData[i + 6] === "E" && xmlData[i + 7] === "N" && xmlData[i + 8] === "T")
1886
+ return true;
1887
+ return false;
1888
+ }
1889
+ function isAttlist(xmlData, i) {
1890
+ if (xmlData[i + 1] === "!" && xmlData[i + 2] === "A" && xmlData[i + 3] === "T" && xmlData[i + 4] === "T" && xmlData[i + 5] === "L" && xmlData[i + 6] === "I" && xmlData[i + 7] === "S" && xmlData[i + 8] === "T")
1891
+ return true;
1892
+ return false;
1893
+ }
1894
+ function isNotation(xmlData, i) {
1895
+ if (xmlData[i + 1] === "!" && xmlData[i + 2] === "N" && xmlData[i + 3] === "O" && xmlData[i + 4] === "T" && xmlData[i + 5] === "A" && xmlData[i + 6] === "T" && xmlData[i + 7] === "I" && xmlData[i + 8] === "O" && xmlData[i + 9] === "N")
1896
+ return true;
1897
+ return false;
1861
1898
  }
1862
1899
  module.exports = readDocType;
1863
1900
  }
@@ -2012,27 +2049,27 @@ Actual: ${this.attribValue}`);
2012
2049
  };
2013
2050
  }
2014
2051
  }
2015
- function parseTextData(val, tagName, jPath, dontTrim, hasAttributes, isLeafNode, escapeEntities) {
2016
- if (val !== void 0) {
2052
+ function parseTextData(val2, tagName, jPath, dontTrim, hasAttributes, isLeafNode, escapeEntities) {
2053
+ if (val2 !== void 0) {
2017
2054
  if (this.options.trimValues && !dontTrim) {
2018
- val = val.trim();
2055
+ val2 = val2.trim();
2019
2056
  }
2020
- if (val.length > 0) {
2057
+ if (val2.length > 0) {
2021
2058
  if (!escapeEntities)
2022
- val = this.replaceEntitiesValue(val);
2023
- const newval = this.options.tagValueProcessor(tagName, val, jPath, hasAttributes, isLeafNode);
2059
+ val2 = this.replaceEntitiesValue(val2);
2060
+ const newval = this.options.tagValueProcessor(tagName, val2, jPath, hasAttributes, isLeafNode);
2024
2061
  if (newval === null || newval === void 0) {
2025
- return val;
2026
- } else if (typeof newval !== typeof val || newval !== val) {
2062
+ return val2;
2063
+ } else if (typeof newval !== typeof val2 || newval !== val2) {
2027
2064
  return newval;
2028
2065
  } else if (this.options.trimValues) {
2029
- return parseValue(val, this.options.parseTagValue, this.options.numberParseOptions);
2066
+ return parseValue(val2, this.options.parseTagValue, this.options.numberParseOptions);
2030
2067
  } else {
2031
- const trimmedVal = val.trim();
2032
- if (trimmedVal === val) {
2033
- return parseValue(val, this.options.parseTagValue, this.options.numberParseOptions);
2068
+ const trimmedVal = val2.trim();
2069
+ if (trimmedVal === val2) {
2070
+ return parseValue(val2, this.options.parseTagValue, this.options.numberParseOptions);
2034
2071
  } else {
2035
- return val;
2072
+ return val2;
2036
2073
  }
2037
2074
  }
2038
2075
  }
@@ -2060,8 +2097,13 @@ Actual: ${this.attribValue}`);
2060
2097
  for (let i = 0; i < len; i++) {
2061
2098
  const attrName = this.resolveNameSpace(matches[i][1]);
2062
2099
  let oldVal = matches[i][4];
2063
- const aName = this.options.attributeNamePrefix + attrName;
2100
+ let aName = this.options.attributeNamePrefix + attrName;
2064
2101
  if (attrName.length) {
2102
+ if (this.options.transformAttributeName) {
2103
+ aName = this.options.transformAttributeName(aName);
2104
+ }
2105
+ if (aName === "__proto__")
2106
+ aName = "#__proto__";
2065
2107
  if (oldVal !== void 0) {
2066
2108
  if (this.options.trimValues) {
2067
2109
  oldVal = oldVal.trim();
@@ -2153,10 +2195,10 @@ Actual: ${this.attribValue}`);
2153
2195
  if (this.options.cdataPropName) {
2154
2196
  currentNode.add(this.options.cdataPropName, [{ [this.options.textNodeName]: tagExp }]);
2155
2197
  } else {
2156
- let val = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true);
2157
- if (val == void 0)
2158
- val = "";
2159
- currentNode.add(this.options.textNodeName, val);
2198
+ let val2 = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true);
2199
+ if (val2 == void 0)
2200
+ val2 = "";
2201
+ currentNode.add(this.options.textNodeName, val2);
2160
2202
  }
2161
2203
  i = closeIndex + 2;
2162
2204
  } else {
@@ -2239,25 +2281,25 @@ Actual: ${this.attribValue}`);
2239
2281
  }
2240
2282
  return xmlObj.child;
2241
2283
  };
2242
- var replaceEntitiesValue = function(val) {
2284
+ var replaceEntitiesValue = function(val2) {
2243
2285
  if (this.options.processEntities) {
2244
- for (let entityName in this.docTypeEntities) {
2245
- const entity = this.docTypeEntities[entityName];
2246
- val = val.replace(entity.regx, entity.val);
2286
+ for (let entityName2 in this.docTypeEntities) {
2287
+ const entity = this.docTypeEntities[entityName2];
2288
+ val2 = val2.replace(entity.regx, entity.val);
2247
2289
  }
2248
- for (let entityName in this.lastEntities) {
2249
- const entity = this.lastEntities[entityName];
2250
- val = val.replace(entity.regex, entity.val);
2290
+ for (let entityName2 in this.lastEntities) {
2291
+ const entity = this.lastEntities[entityName2];
2292
+ val2 = val2.replace(entity.regex, entity.val);
2251
2293
  }
2252
2294
  if (this.options.htmlEntities) {
2253
- for (let entityName in this.htmlEntities) {
2254
- const entity = this.htmlEntities[entityName];
2255
- val = val.replace(entity.regex, entity.val);
2295
+ for (let entityName2 in this.htmlEntities) {
2296
+ const entity = this.htmlEntities[entityName2];
2297
+ val2 = val2.replace(entity.regex, entity.val);
2256
2298
  }
2257
2299
  }
2258
- val = val.replace(this.ampEntity.regex, this.ampEntity.val);
2300
+ val2 = val2.replace(this.ampEntity.regex, this.ampEntity.val);
2259
2301
  }
2260
- return val;
2302
+ return val2;
2261
2303
  };
2262
2304
  function saveTextToParentTag(textData, currentNode, jPath, isLeafNode) {
2263
2305
  if (textData) {
@@ -2384,18 +2426,18 @@ Actual: ${this.attribValue}`);
2384
2426
  }
2385
2427
  }
2386
2428
  }
2387
- function parseValue(val, shouldParse, options) {
2388
- if (shouldParse && typeof val === "string") {
2389
- const newval = val.trim();
2429
+ function parseValue(val2, shouldParse, options) {
2430
+ if (shouldParse && typeof val2 === "string") {
2431
+ const newval = val2.trim();
2390
2432
  if (newval === "true")
2391
2433
  return true;
2392
2434
  else if (newval === "false")
2393
2435
  return false;
2394
2436
  else
2395
- return toNumber(val, options);
2437
+ return toNumber(val2, options);
2396
2438
  } else {
2397
- if (util.isExist(val)) {
2398
- return val;
2439
+ if (util.isExist(val2)) {
2440
+ return val2;
2399
2441
  } else {
2400
2442
  return "";
2401
2443
  }
@@ -2431,28 +2473,28 @@ Actual: ${this.attribValue}`);
2431
2473
  } else if (property === void 0) {
2432
2474
  continue;
2433
2475
  } else if (tagObj[property]) {
2434
- let val = compress(tagObj[property], options, newJpath);
2435
- const isLeaf = isLeafTag(val, options);
2476
+ let val2 = compress(tagObj[property], options, newJpath);
2477
+ const isLeaf = isLeafTag(val2, options);
2436
2478
  if (tagObj[":@"]) {
2437
- assignAttributes(val, tagObj[":@"], newJpath, options);
2438
- } else if (Object.keys(val).length === 1 && val[options.textNodeName] !== void 0 && !options.alwaysCreateTextNode) {
2439
- val = val[options.textNodeName];
2440
- } else if (Object.keys(val).length === 0) {
2479
+ assignAttributes(val2, tagObj[":@"], newJpath, options);
2480
+ } else if (Object.keys(val2).length === 1 && val2[options.textNodeName] !== void 0 && !options.alwaysCreateTextNode) {
2481
+ val2 = val2[options.textNodeName];
2482
+ } else if (Object.keys(val2).length === 0) {
2441
2483
  if (options.alwaysCreateTextNode)
2442
- val[options.textNodeName] = "";
2484
+ val2[options.textNodeName] = "";
2443
2485
  else
2444
- val = "";
2486
+ val2 = "";
2445
2487
  }
2446
2488
  if (compressedObj[property] !== void 0 && compressedObj.hasOwnProperty(property)) {
2447
2489
  if (!Array.isArray(compressedObj[property])) {
2448
2490
  compressedObj[property] = [compressedObj[property]];
2449
2491
  }
2450
- compressedObj[property].push(val);
2492
+ compressedObj[property].push(val2);
2451
2493
  } else {
2452
2494
  if (options.isArray(property, newJpath, isLeaf)) {
2453
- compressedObj[property] = [val];
2495
+ compressedObj[property] = [val2];
2454
2496
  } else {
2455
- compressedObj[property] = val;
2497
+ compressedObj[property] = val2;
2456
2498
  }
2457
2499
  }
2458
2500
  }
@@ -2552,14 +2594,15 @@ Actual: ${this.attribValue}`);
2552
2594
  "node_modules/fast-xml-parser/src/xmlbuilder/orderedJs2Xml.js"(exports, module) {
2553
2595
  var EOL = "\n";
2554
2596
  function toXml(jArray, options) {
2555
- return arrToStr(jArray, options, "", 0);
2556
- }
2557
- function arrToStr(arr, options, jPath, level) {
2558
- let xmlStr = "";
2559
2597
  let indentation = "";
2560
2598
  if (options.format && options.indentBy.length > 0) {
2561
- indentation = EOL + "" + options.indentBy.repeat(level);
2599
+ indentation = EOL;
2562
2600
  }
2601
+ return arrToStr(jArray, options, "", indentation);
2602
+ }
2603
+ function arrToStr(arr, options, jPath, indentation) {
2604
+ let xmlStr = "";
2605
+ let isPreviousElementTag = false;
2563
2606
  for (let i = 0; i < arr.length; i++) {
2564
2607
  const tagObj = arr[i];
2565
2608
  const tagName = propName(tagObj);
@@ -2574,13 +2617,22 @@ Actual: ${this.attribValue}`);
2574
2617
  tagText = options.tagValueProcessor(tagName, tagText);
2575
2618
  tagText = replaceEntitiesValue(tagText, options);
2576
2619
  }
2577
- xmlStr += indentation + tagText;
2620
+ if (isPreviousElementTag) {
2621
+ xmlStr += indentation;
2622
+ }
2623
+ xmlStr += tagText;
2624
+ isPreviousElementTag = false;
2578
2625
  continue;
2579
2626
  } else if (tagName === options.cdataPropName) {
2580
- xmlStr += indentation + `<![CDATA[${tagObj[tagName][0][options.textNodeName]}]]>`;
2627
+ if (isPreviousElementTag) {
2628
+ xmlStr += indentation;
2629
+ }
2630
+ xmlStr += `<![CDATA[${tagObj[tagName][0][options.textNodeName]}]]>`;
2631
+ isPreviousElementTag = false;
2581
2632
  continue;
2582
2633
  } else if (tagName === options.commentPropName) {
2583
2634
  xmlStr += indentation + `<!--${tagObj[tagName][0][options.textNodeName]}-->`;
2635
+ isPreviousElementTag = true;
2584
2636
  continue;
2585
2637
  } else if (tagName[0] === "?") {
2586
2638
  const attStr2 = attr_to_str(tagObj[":@"], options);
@@ -2588,11 +2640,16 @@ Actual: ${this.attribValue}`);
2588
2640
  let piTextNodeName = tagObj[tagName][0][options.textNodeName];
2589
2641
  piTextNodeName = piTextNodeName.length !== 0 ? " " + piTextNodeName : "";
2590
2642
  xmlStr += tempInd + `<${tagName}${piTextNodeName}${attStr2}?>`;
2643
+ isPreviousElementTag = true;
2591
2644
  continue;
2592
2645
  }
2646
+ let newIdentation = indentation;
2647
+ if (newIdentation !== "") {
2648
+ newIdentation += options.indentBy;
2649
+ }
2593
2650
  const attStr = attr_to_str(tagObj[":@"], options);
2594
- let tagStart = indentation + `<${tagName}${attStr}`;
2595
- let tagValue = arrToStr(tagObj[tagName], options, newJPath, level + 1);
2651
+ const tagStart = indentation + `<${tagName}${attStr}`;
2652
+ const tagValue = arrToStr(tagObj[tagName], options, newJPath, newIdentation);
2596
2653
  if (options.unpairedTags.indexOf(tagName) !== -1) {
2597
2654
  if (options.suppressUnpairedNode)
2598
2655
  xmlStr += tagStart + ">";
@@ -2600,9 +2657,18 @@ Actual: ${this.attribValue}`);
2600
2657
  xmlStr += tagStart + "/>";
2601
2658
  } else if ((!tagValue || tagValue.length === 0) && options.suppressEmptyNode) {
2602
2659
  xmlStr += tagStart + "/>";
2603
- } else {
2660
+ } else if (tagValue && tagValue.endsWith(">")) {
2604
2661
  xmlStr += tagStart + `>${tagValue}${indentation}</${tagName}>`;
2662
+ } else {
2663
+ xmlStr += tagStart + ">";
2664
+ if (tagValue && indentation !== "" && (tagValue.includes("/>") || tagValue.includes("</"))) {
2665
+ xmlStr += indentation + options.indentBy + tagValue + indentation;
2666
+ } else {
2667
+ xmlStr += tagValue;
2668
+ }
2669
+ xmlStr += `</${tagName}>`;
2605
2670
  }
2671
+ isPreviousElementTag = true;
2606
2672
  }
2607
2673
  return xmlStr;
2608
2674
  }
@@ -2684,8 +2750,7 @@ Actual: ${this.attribValue}`);
2684
2750
  { regex: new RegExp('"', "g"), val: "&quot;" }
2685
2751
  ],
2686
2752
  processEntities: true,
2687
- stopNodes: [],
2688
- transformTagName: false
2753
+ stopNodes: []
2689
2754
  };
2690
2755
  function Builder(options) {
2691
2756
  this.options = Object.assign({}, defaultOptions, options);
@@ -2709,17 +2774,6 @@ Actual: ${this.attribValue}`);
2709
2774
  this.tagEndChar = ">";
2710
2775
  this.newLine = "";
2711
2776
  }
2712
- if (this.options.suppressEmptyNode) {
2713
- this.buildTextNode = buildEmptyTextNode;
2714
- this.buildObjNode = buildEmptyObjNode;
2715
- } else {
2716
- this.buildTextNode = buildTextValNode;
2717
- this.buildObjNode = buildObjectNode;
2718
- }
2719
- this.buildTextValNode = buildTextValNode;
2720
- this.buildObjectNode = buildObjectNode;
2721
- this.replaceEntitiesValue = replaceEntitiesValue;
2722
- this.buildAttrPairStr = buildAttrPairStr;
2723
2777
  }
2724
2778
  Builder.prototype.build = function(jObj) {
2725
2779
  if (this.options.preserveOrder) {
@@ -2735,16 +2789,16 @@ Actual: ${this.attribValue}`);
2735
2789
  };
2736
2790
  Builder.prototype.j2x = function(jObj, level) {
2737
2791
  let attrStr = "";
2738
- let val = "";
2792
+ let val2 = "";
2739
2793
  for (let key in jObj) {
2740
2794
  if (typeof jObj[key] === "undefined") {
2741
2795
  } else if (jObj[key] === null) {
2742
2796
  if (key[0] === "?")
2743
- val += this.indentate(level) + "<" + key + "?" + this.tagEndChar;
2797
+ val2 += this.indentate(level) + "<" + key + "?" + this.tagEndChar;
2744
2798
  else
2745
- val += this.indentate(level) + "<" + key + "/" + this.tagEndChar;
2799
+ val2 += this.indentate(level) + "<" + key + "/" + this.tagEndChar;
2746
2800
  } else if (jObj[key] instanceof Date) {
2747
- val += this.buildTextNode(jObj[key], key, "", level);
2801
+ val2 += this.buildTextValNode(jObj[key], key, "", level);
2748
2802
  } else if (typeof jObj[key] !== "object") {
2749
2803
  const attr = this.isAttribute(key);
2750
2804
  if (attr) {
@@ -2752,9 +2806,9 @@ Actual: ${this.attribValue}`);
2752
2806
  } else {
2753
2807
  if (key === this.options.textNodeName) {
2754
2808
  let newval = this.options.tagValueProcessor(key, "" + jObj[key]);
2755
- val += this.replaceEntitiesValue(newval);
2809
+ val2 += this.replaceEntitiesValue(newval);
2756
2810
  } else {
2757
- val += this.buildTextNode(jObj[key], key, "", level);
2811
+ val2 += this.buildTextValNode(jObj[key], key, "", level);
2758
2812
  }
2759
2813
  }
2760
2814
  } else if (Array.isArray(jObj[key])) {
@@ -2764,13 +2818,13 @@ Actual: ${this.attribValue}`);
2764
2818
  if (typeof item === "undefined") {
2765
2819
  } else if (item === null) {
2766
2820
  if (key[0] === "?")
2767
- val += this.indentate(level) + "<" + key + "?" + this.tagEndChar;
2821
+ val2 += this.indentate(level) + "<" + key + "?" + this.tagEndChar;
2768
2822
  else
2769
- val += this.indentate(level) + "<" + key + "/" + this.tagEndChar;
2823
+ val2 += this.indentate(level) + "<" + key + "/" + this.tagEndChar;
2770
2824
  } else if (typeof item === "object") {
2771
- val += this.processTextOrObjNode(item, key, level);
2825
+ val2 += this.processTextOrObjNode(item, key, level);
2772
2826
  } else {
2773
- val += this.buildTextNode(item, key, "", level);
2827
+ val2 += this.buildTextValNode(item, key, "", level);
2774
2828
  }
2775
2829
  }
2776
2830
  } else {
@@ -2781,73 +2835,81 @@ Actual: ${this.attribValue}`);
2781
2835
  attrStr += this.buildAttrPairStr(Ks[j], "" + jObj[key][Ks[j]]);
2782
2836
  }
2783
2837
  } else {
2784
- val += this.processTextOrObjNode(jObj[key], key, level);
2838
+ val2 += this.processTextOrObjNode(jObj[key], key, level);
2785
2839
  }
2786
2840
  }
2787
2841
  }
2788
- return { attrStr, val };
2842
+ return { attrStr, val: val2 };
2789
2843
  };
2790
- function buildAttrPairStr(attrName, val) {
2791
- val = this.options.attributeValueProcessor(attrName, "" + val);
2792
- val = this.replaceEntitiesValue(val);
2793
- if (this.options.suppressBooleanAttributes && val === "true") {
2844
+ Builder.prototype.buildAttrPairStr = function(attrName, val2) {
2845
+ val2 = this.options.attributeValueProcessor(attrName, "" + val2);
2846
+ val2 = this.replaceEntitiesValue(val2);
2847
+ if (this.options.suppressBooleanAttributes && val2 === "true") {
2794
2848
  return " " + attrName;
2795
2849
  } else
2796
- return " " + attrName + '="' + val + '"';
2797
- }
2850
+ return " " + attrName + '="' + val2 + '"';
2851
+ };
2798
2852
  function processTextOrObjNode(object, key, level) {
2799
2853
  const result = this.j2x(object, level + 1);
2800
2854
  if (object[this.options.textNodeName] !== void 0 && Object.keys(object).length === 1) {
2801
- return this.buildTextNode(object[this.options.textNodeName], key, result.attrStr, level);
2855
+ return this.buildTextValNode(object[this.options.textNodeName], key, result.attrStr, level);
2802
2856
  } else {
2803
- return this.buildObjNode(result.val, key, result.attrStr, level);
2857
+ return this.buildObjectNode(result.val, key, result.attrStr, level);
2804
2858
  }
2805
2859
  }
2806
- function buildObjectNode(val, key, attrStr, level) {
2807
- let tagEndExp = "</" + key + this.tagEndChar;
2808
- let piClosingChar = "";
2809
- if (key[0] === "?") {
2810
- piClosingChar = "?";
2811
- tagEndExp = "";
2812
- }
2813
- if (attrStr && val.indexOf("<") === -1) {
2814
- return this.indentate(level) + "<" + key + attrStr + piClosingChar + ">" + val + tagEndExp;
2815
- } else if (this.options.commentPropName !== false && key === this.options.commentPropName && piClosingChar.length === 0) {
2816
- return this.indentate(level) + `<!--${val}-->` + this.newLine;
2860
+ Builder.prototype.buildObjectNode = function(val2, key, attrStr, level) {
2861
+ if (val2 === "") {
2862
+ if (key[0] === "?")
2863
+ return this.indentate(level) + "<" + key + attrStr + "?" + this.tagEndChar;
2864
+ else {
2865
+ return this.indentate(level) + "<" + key + attrStr + this.closeTag(key) + this.tagEndChar;
2866
+ }
2817
2867
  } else {
2818
- return this.indentate(level) + "<" + key + attrStr + piClosingChar + this.tagEndChar + val + this.indentate(level) + tagEndExp;
2868
+ let tagEndExp = "</" + key + this.tagEndChar;
2869
+ let piClosingChar = "";
2870
+ if (key[0] === "?") {
2871
+ piClosingChar = "?";
2872
+ tagEndExp = "";
2873
+ }
2874
+ if (attrStr && val2.indexOf("<") === -1) {
2875
+ return this.indentate(level) + "<" + key + attrStr + piClosingChar + ">" + val2 + tagEndExp;
2876
+ } else if (this.options.commentPropName !== false && key === this.options.commentPropName && piClosingChar.length === 0) {
2877
+ return this.indentate(level) + `<!--${val2}-->` + this.newLine;
2878
+ } else {
2879
+ return this.indentate(level) + "<" + key + attrStr + piClosingChar + this.tagEndChar + val2 + this.indentate(level) + tagEndExp;
2880
+ }
2819
2881
  }
2820
- }
2821
- function buildEmptyObjNode(val, key, attrStr, level) {
2822
- if (val !== "") {
2823
- return this.buildObjectNode(val, key, attrStr, level);
2882
+ };
2883
+ Builder.prototype.closeTag = function(key) {
2884
+ let closeTag = "";
2885
+ if (this.options.unpairedTags.indexOf(key) !== -1) {
2886
+ if (!this.options.suppressUnpairedNode)
2887
+ closeTag = "/";
2888
+ } else if (this.options.suppressEmptyNode) {
2889
+ closeTag = "/";
2824
2890
  } else {
2825
- if (key[0] === "?")
2826
- return this.indentate(level) + "<" + key + attrStr + "?" + this.tagEndChar;
2827
- else
2828
- return this.indentate(level) + "<" + key + attrStr + "/" + this.tagEndChar;
2891
+ closeTag = `></${key}`;
2829
2892
  }
2830
- }
2831
- function buildTextValNode(val, key, attrStr, level) {
2893
+ return closeTag;
2894
+ };
2895
+ Builder.prototype.buildTextValNode = function(val2, key, attrStr, level) {
2832
2896
  if (this.options.cdataPropName !== false && key === this.options.cdataPropName) {
2833
- return this.indentate(level) + `<![CDATA[${val}]]>` + this.newLine;
2897
+ return this.indentate(level) + `<![CDATA[${val2}]]>` + this.newLine;
2834
2898
  } else if (this.options.commentPropName !== false && key === this.options.commentPropName) {
2835
- return this.indentate(level) + `<!--${val}-->` + this.newLine;
2899
+ return this.indentate(level) + `<!--${val2}-->` + this.newLine;
2900
+ } else if (key[0] === "?") {
2901
+ return this.indentate(level) + "<" + key + attrStr + "?" + this.tagEndChar;
2836
2902
  } else {
2837
- let textValue = this.options.tagValueProcessor(key, val);
2903
+ let textValue = this.options.tagValueProcessor(key, val2);
2838
2904
  textValue = this.replaceEntitiesValue(textValue);
2839
- if (textValue === "" && this.options.unpairedTags.indexOf(key) !== -1) {
2840
- if (this.options.suppressUnpairedNode) {
2841
- return this.indentate(level) + "<" + key + this.tagEndChar;
2842
- } else {
2843
- return this.indentate(level) + "<" + key + "/" + this.tagEndChar;
2844
- }
2905
+ if (textValue === "") {
2906
+ return this.indentate(level) + "<" + key + attrStr + this.closeTag(key) + this.tagEndChar;
2845
2907
  } else {
2846
2908
  return this.indentate(level) + "<" + key + attrStr + ">" + textValue + "</" + key + this.tagEndChar;
2847
2909
  }
2848
2910
  }
2849
- }
2850
- function replaceEntitiesValue(textValue) {
2911
+ };
2912
+ Builder.prototype.replaceEntitiesValue = function(textValue) {
2851
2913
  if (textValue && textValue.length > 0 && this.options.processEntities) {
2852
2914
  for (let i = 0; i < this.options.entities.length; i++) {
2853
2915
  const entity = this.options.entities[i];
@@ -2855,23 +2917,7 @@ Actual: ${this.attribValue}`);
2855
2917
  }
2856
2918
  }
2857
2919
  return textValue;
2858
- }
2859
- function buildEmptyTextNode(val, key, attrStr, level) {
2860
- if (val === "" && this.options.unpairedTags.indexOf(key) !== -1) {
2861
- if (this.options.suppressUnpairedNode) {
2862
- return this.indentate(level) + "<" + key + this.tagEndChar;
2863
- } else {
2864
- return this.indentate(level) + "<" + key + "/" + this.tagEndChar;
2865
- }
2866
- } else if (val !== "") {
2867
- return this.buildTextValNode(val, key, attrStr, level);
2868
- } else {
2869
- if (key[0] === "?")
2870
- return this.indentate(level) + "<" + key + attrStr + "?" + this.tagEndChar;
2871
- else
2872
- return this.indentate(level) + "<" + key + attrStr + "/" + this.tagEndChar;
2873
- }
2874
- }
2920
+ };
2875
2921
  function indentate(level) {
2876
2922
  return this.options.indentBy.repeat(level);
2877
2923
  }
@@ -2901,31 +2947,75 @@ Actual: ${this.attribValue}`);
2901
2947
  }
2902
2948
  });
2903
2949
 
2904
- // src/lib/parse-xml.ts
2905
- function parseXML(text, options) {
2950
+ // src/lib/parsers/parse-xml.ts
2951
+ function fastParseXML(text, options) {
2906
2952
  const parser = new import_fast_xml_parser.XMLParser({
2907
2953
  ignoreAttributes: false,
2908
2954
  attributeNamePrefix: "",
2909
- ...options?.xml
2955
+ ...options
2910
2956
  });
2911
2957
  const parsedXML = parser.parse(text);
2912
2958
  return parsedXML;
2913
2959
  }
2914
2960
  var import_fast_xml_parser;
2915
2961
  var init_parse_xml = __esm({
2916
- "src/lib/parse-xml.ts"() {
2962
+ "src/lib/parsers/parse-xml.ts"() {
2917
2963
  import_fast_xml_parser = __toModule(require_fxp());
2918
2964
  }
2919
2965
  });
2920
2966
 
2967
+ // src/lib/xml-utils/uncapitalize.ts
2968
+ function uncapitalize(str) {
2969
+ return typeof str === "string" ? str.charAt(0).toLowerCase() + str.slice(1) : str;
2970
+ }
2971
+ function uncapitalizeKeys(object) {
2972
+ if (Array.isArray(object)) {
2973
+ return object.map((element) => uncapitalizeKeys(element));
2974
+ }
2975
+ if (object && typeof object === "object") {
2976
+ const newObject = {};
2977
+ for (const [key, value] of Object.entries(object)) {
2978
+ newObject[uncapitalize(key)] = uncapitalizeKeys(value);
2979
+ }
2980
+ return newObject;
2981
+ }
2982
+ return object;
2983
+ }
2984
+ var init_uncapitalize = __esm({
2985
+ "src/lib/xml-utils/uncapitalize.ts"() {
2986
+ }
2987
+ });
2988
+
2921
2989
  // src/xml-loader.ts
2922
2990
  function testXMLFile(text) {
2923
2991
  return text.startsWith("<?xml");
2924
2992
  }
2993
+ function parseTextSync(text, options) {
2994
+ const xmlOptions = { ...XMLLoader.options.xml, ...options?.xml };
2995
+ switch (xmlOptions.parser) {
2996
+ case "fast-xml-parser":
2997
+ const fastXMLOptions = {
2998
+ allowBooleanAttributes: true,
2999
+ ignoreDeclaration: true,
3000
+ removeNSPrefix: xmlOptions.removeNSPrefix,
3001
+ textNodeName: xmlOptions.textNodeName,
3002
+ isArray: (name, jpath, isLeafNode, isAttribute) => {
3003
+ const array = Boolean(xmlOptions?.arrayPaths?.some((path) => jpath === path));
3004
+ return array;
3005
+ },
3006
+ ...options?._fastXML
3007
+ };
3008
+ const xml = fastParseXML(text, fastXMLOptions);
3009
+ return xmlOptions.uncapitalizeKeys ? uncapitalizeKeys(xml) : xml;
3010
+ default:
3011
+ throw new Error(options?.xml?.parser);
3012
+ }
3013
+ }
2925
3014
  var VERSION, XMLLoader;
2926
3015
  var init_xml_loader = __esm({
2927
3016
  "src/xml-loader.ts"() {
2928
3017
  init_parse_xml();
3018
+ init_uncapitalize();
2929
3019
  VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
2930
3020
  XMLLoader = {
2931
3021
  name: "XML",
@@ -2937,31 +3027,123 @@ Actual: ${this.attribValue}`);
2937
3027
  mimeTypes: ["application/xml", "text/xml"],
2938
3028
  testText: testXMLFile,
2939
3029
  options: {
2940
- xml: {}
3030
+ xml: {
3031
+ parser: "fast-xml-parser",
3032
+ uncapitalizeKeys: false,
3033
+ removeNSPrefix: false,
3034
+ textNodeName: "value",
3035
+ arrayPaths: []
3036
+ }
2941
3037
  },
2942
- parse: async (arrayBuffer, options) => parseXML(new TextDecoder().decode(arrayBuffer), options),
2943
- parseTextSync: (text, options) => parseXML(text, options)
3038
+ parse: async (arrayBuffer, options) => parseTextSync(new TextDecoder().decode(arrayBuffer), options),
3039
+ parseTextSync: (text, options) => parseTextSync(text, options)
3040
+ };
3041
+ }
3042
+ });
3043
+
3044
+ // ../loader-utils/src/lib/option-utils/merge-loader-options.ts
3045
+ function mergeLoaderOptions(baseOptions, newOptions) {
3046
+ const options = { ...baseOptions };
3047
+ for (const [key, newValue] of Object.entries(newOptions)) {
3048
+ if (newValue && typeof newValue === "object") {
3049
+ options[key] = options[key] || {};
3050
+ Object.assign(options[key], newOptions[key]);
3051
+ } else {
3052
+ options[key] = newOptions[key];
3053
+ }
3054
+ }
3055
+ return options;
3056
+ }
3057
+ var init_merge_loader_options = __esm({
3058
+ "../loader-utils/src/lib/option-utils/merge-loader-options.ts"() {
3059
+ }
3060
+ });
3061
+
3062
+ // ../loader-utils/src/index.ts
3063
+ var init_src = __esm({
3064
+ "../loader-utils/src/index.ts"() {
3065
+ init_merge_loader_options();
3066
+ }
3067
+ });
3068
+
3069
+ // src/html-loader.ts
3070
+ function testHTMLFile(text) {
3071
+ return text.startsWith("<html");
3072
+ }
3073
+ function parseTextSync2(text, options) {
3074
+ options = mergeLoaderOptions(options, {
3075
+ xml: {
3076
+ parser: "fast-xml-parser"
3077
+ },
3078
+ _fastXML: {
3079
+ htmlEntities: true
3080
+ }
3081
+ });
3082
+ return XMLLoader.parseTextSync(text, options);
3083
+ }
3084
+ var HTMLLoader;
3085
+ var init_html_loader = __esm({
3086
+ "src/html-loader.ts"() {
3087
+ init_src();
3088
+ init_xml_loader();
3089
+ HTMLLoader = {
3090
+ ...XMLLoader,
3091
+ name: "HTML",
3092
+ id: "html",
3093
+ extensions: ["html", "htm"],
3094
+ mimeTypes: ["text/html"],
3095
+ testText: testHTMLFile,
3096
+ parse: async (arrayBuffer, options) => parseTextSync2(new TextDecoder().decode(arrayBuffer), options),
3097
+ parseTextSync: (text, options) => parseTextSync2(text, options)
2944
3098
  };
2945
3099
  }
2946
3100
  });
2947
3101
 
3102
+ // src/lib/xml-utils/xml-utils.ts
3103
+ function convertXMLValueToArray(xmlValue) {
3104
+ if (Array.isArray(xmlValue)) {
3105
+ return xmlValue;
3106
+ }
3107
+ if (xmlValue && typeof xmlValue === "object" && xmlValue["0"]) {
3108
+ }
3109
+ if (xmlValue) {
3110
+ return [xmlValue];
3111
+ }
3112
+ return [];
3113
+ }
3114
+ function convertXMLFieldToArrayInPlace(xml, key) {
3115
+ xml[key] = convertXMLValueToArray(xml[key]);
3116
+ }
3117
+ var init_xml_utils = __esm({
3118
+ "src/lib/xml-utils/xml-utils.ts"() {
3119
+ }
3120
+ });
3121
+
2948
3122
  // src/index.ts
2949
3123
  var src_exports = {};
2950
3124
  __export(src_exports, {
3125
+ HTMLLoader: () => HTMLLoader,
2951
3126
  SAXParser: () => SAXParser,
2952
- XMLLoader: () => XMLLoader
3127
+ XMLLoader: () => XMLLoader,
3128
+ _uncapitalize: () => uncapitalize,
3129
+ _uncapitalizeKeys: () => uncapitalizeKeys,
3130
+ convertXMLFieldToArrayInPlace: () => convertXMLFieldToArrayInPlace,
3131
+ convertXMLValueToArray: () => convertXMLValueToArray
2953
3132
  });
2954
- var init_src = __esm({
3133
+ var init_src2 = __esm({
2955
3134
  "src/index.ts"() {
2956
3135
  init_xml_loader();
3136
+ init_html_loader();
2957
3137
  init_sax();
3138
+ init_xml_utils();
3139
+ init_uncapitalize();
2958
3140
  }
2959
3141
  });
2960
3142
 
2961
3143
  // src/bundle.ts
2962
3144
  var require_bundle = __commonJS({
2963
3145
  "src/bundle.ts"(exports, module) {
2964
- var moduleExports = (init_src(), src_exports);
3146
+ var moduleExports = (init_src2(), src_exports);
2965
3147
  globalThis.loaders = globalThis.loaders || {};
2966
3148
  module.exports = Object.assign(globalThis.loaders, moduleExports);
2967
3149
  }