@loaders.gl/xml 3.4.0-alpha.1 → 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
@@ -1,13 +1,15 @@
1
1
  // @ts-nocheck
2
2
  /* eslint-disable */
3
3
 
4
- // import ClarinetParser, {ClarinetParserOptions} from '../clarinet/clarinet';
5
4
  import {SAXParser, SAXParserOptions} from '../../sax-ts/sax';
6
5
  // import JSONPath from '../jsonpath/jsonpath';
7
6
 
8
- // XMLParser builds a JSON object using the events emitted by the Clarinet parser
7
+ export type StreamingXMLParserOptions = SAXParserOptions;
9
8
 
10
- export class XMLParser {
9
+ /**
10
+ * StreamingXMLParser builds a JSON object using the events emitted by the SAX parser
11
+ */
12
+ export class StreamingXMLParser {
11
13
  readonly parser: SAXParser;
12
14
  result = undefined;
13
15
  previousStates = [];
@@ -0,0 +1,31 @@
1
+ // loaders.gl, MIT license
2
+
3
+ /**
4
+ * Uncapitalize first letter of a string
5
+ * @param str
6
+ * @returns
7
+ */
8
+ export function uncapitalize(str: string): string {
9
+ return typeof str === 'string' ? str.charAt(0).toLowerCase() + str.slice(1) : str;
10
+ }
11
+
12
+ /**
13
+ * Recursively uncapitalize all keys in a nested object
14
+ * @param object
15
+ * @returns
16
+ */
17
+ export function uncapitalizeKeys(object: any): any {
18
+ if (Array.isArray(object)) {
19
+ return object.map((element) => uncapitalizeKeys(element));
20
+ }
21
+
22
+ if (object && typeof object === 'object') {
23
+ const newObject = {};
24
+ for (const [key, value] of Object.entries(object)) {
25
+ newObject[uncapitalize(key)] = uncapitalizeKeys(value);
26
+ }
27
+ return newObject;
28
+ }
29
+
30
+ return object;
31
+ }
@@ -0,0 +1,27 @@
1
+ // TODO - these utilities could be moved to the XML parser.
2
+ // uncapitalizeKeys could be an XMLLoader option
3
+
4
+ /**
5
+ * Extracts a value or array and always return an array
6
+ * Useful since XML parses to object instead of array when only a single value is provided
7
+ */
8
+ export function convertXMLValueToArray(xmlValue: unknown): unknown[] {
9
+ if (Array.isArray(xmlValue)) {
10
+ return xmlValue;
11
+ }
12
+ if (xmlValue && typeof xmlValue === 'object' && xmlValue['0']) {
13
+ // Error this is an objectified array
14
+ }
15
+ if (xmlValue) {
16
+ return [xmlValue];
17
+ }
18
+ return [];
19
+ }
20
+
21
+ /**
22
+ * Mutates a field in place, converting it to array
23
+ * Useful since XML parses to object instead of array when only a single value is provided
24
+ */
25
+ export function convertXMLFieldToArrayInPlace(xml: any, key: string): void {
26
+ xml[key] = convertXMLValueToArray(xml[key]);
27
+ }
package/src/xml-loader.ts CHANGED
@@ -1,17 +1,30 @@
1
1
  import type {LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';
2
2
  import type {SAXParserOptions} from './sax-ts/sax';
3
- import {parseXML} from './lib/parse-xml';
3
+ import {fastParseXML, FastXMLParserOptions} from './lib/parsers/parse-xml';
4
+ import {uncapitalizeKeys} from './lib/xml-utils/uncapitalize';
4
5
 
5
6
  // __VERSION__ is injected by babel-plugin-version-inline
6
7
  // @ts-ignore TS2304: Cannot find name '__VERSION__'.
7
8
  const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
8
9
 
9
10
  export type XMLLoaderOptions = LoaderOptions & {
10
- xml?: SAXParserOptions;
11
+ xml?: {
12
+ // TODO - type this harder
13
+ parser?: 'fast-xml-parser' | string;
14
+ /** XML is typically PascalCase, JavaScript prefects camelCase */
15
+ uncapitalizeKeys?: boolean;
16
+ removeNSPrefix?: boolean;
17
+ textNodeName?: string;
18
+ arrayPaths?: string[];
19
+ };
20
+ /** @deprecated Experimental, passes options to fast-xml-parser, IF it is being used */
21
+ _fastXML?: FastXMLParserOptions;
22
+ /** @deprecated Experimental, passes options to the SAX XML parser, IF it is being used. */
23
+ _sax?: SAXParserOptions;
11
24
  };
12
25
 
13
26
  /**
14
- * Worker loader for the OBJ geometry format
27
+ * Loader for XML files
15
28
  */
16
29
  export const XMLLoader = {
17
30
  name: 'XML',
@@ -23,11 +36,17 @@ export const XMLLoader = {
23
36
  mimeTypes: ['application/xml', 'text/xml'],
24
37
  testText: testXMLFile,
25
38
  options: {
26
- xml: {}
39
+ xml: {
40
+ parser: 'fast-xml-parser',
41
+ uncapitalizeKeys: false,
42
+ removeNSPrefix: false,
43
+ textNodeName: 'value',
44
+ arrayPaths: []
45
+ }
27
46
  },
28
47
  parse: async (arrayBuffer: ArrayBuffer, options?: XMLLoaderOptions) =>
29
- parseXML(new TextDecoder().decode(arrayBuffer), options),
30
- parseTextSync: (text: string, options?: XMLLoaderOptions) => parseXML(text, options)
48
+ parseTextSync(new TextDecoder().decode(arrayBuffer), options),
49
+ parseTextSync: (text: string, options?: XMLLoaderOptions) => parseTextSync(text, options)
31
50
  };
32
51
 
33
52
  function testXMLFile(text: string): boolean {
@@ -35,4 +54,42 @@ function testXMLFile(text: string): boolean {
35
54
  return text.startsWith('<?xml');
36
55
  }
37
56
 
57
+ function parseTextSync(text: string, options?: XMLLoaderOptions): any {
58
+ const xmlOptions: Required<XMLLoaderOptions['xml']> = {...XMLLoader.options.xml, ...options?.xml};
59
+ switch (xmlOptions.parser) {
60
+ case 'fast-xml-parser':
61
+ const fastXMLOptions: FastXMLParserOptions = {
62
+ // Default FastXML options
63
+ // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#allowbooleanattributes
64
+ allowBooleanAttributes: true,
65
+ // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#ignoredeclaration
66
+ ignoreDeclaration: true,
67
+
68
+ // XMLLoader Options: Map to FastXMLOptions
69
+
70
+ // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#removensprefix
71
+ removeNSPrefix: xmlOptions.removeNSPrefix,
72
+
73
+ // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#textnodename
74
+ textNodeName: xmlOptions.textNodeName,
75
+
76
+ isArray: (name: string, jpath: string, isLeafNode: boolean, isAttribute: boolean) => {
77
+ const array = Boolean(xmlOptions?.arrayPaths?.some((path) => jpath === path));
78
+ return array;
79
+ },
80
+
81
+ // Application overrides
82
+ ...options?._fastXML
83
+ };
84
+
85
+ const xml = fastParseXML(text, fastXMLOptions);
86
+
87
+ // Note - could be done with FastXML tag processing
88
+ return xmlOptions.uncapitalizeKeys ? uncapitalizeKeys(xml) : xml;
89
+
90
+ default:
91
+ throw new Error(options?.xml?.parser);
92
+ }
93
+ }
94
+
38
95
  export const _typecheckXMLLoader: LoaderWithParser = XMLLoader;
@@ -1 +0,0 @@
1
- {"version":3,"file":"parse-xml.js","names":["parseXML","text","options","parser","FastXMLParser","ignoreAttributes","attributeNamePrefix","xml","parsedXML","parse","parseXMLInBatches","XMLParser","strict","write","close","result"],"sources":["../../../src/lib/parse-xml.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport {XMLParser} from '../lib/parser/xml-parser';\nimport {XMLParser as FastXMLParser} from 'fast-xml-parser';\n\nexport function parseXML(text: string, options): any {\n const parser = new FastXMLParser({\n ignoreAttributes: false,\n attributeNamePrefix: '',\n // parseAttributeValue: true,\n ...options?.xml\n });\n\n const parsedXML = parser.parse(text);\n\n return parsedXML;\n}\n\n/**\n * @todo Build a streaming XML parser based on sax-js\n * @param text\n * @param options\n * @returns\n */\nexport function parseXMLInBatches(text: string, options): any {\n const parser = new XMLParser({\n ...options,\n strict: true\n });\n\n parser.write(text);\n parser.close();\n\n return parser.result;\n}\n"],"mappings":";;;;;;;;;AAEA;AACA;AAA2D;AAAA;AAEpD,SAASA,QAAQ,CAACC,IAAY,EAAEC,OAAO,EAAO;EACnD,IAAMC,MAAM,GAAG,IAAIC,wBAAa;IAC9BC,gBAAgB,EAAE,KAAK;IACvBC,mBAAmB,EAAE;EAAE,GAEpBJ,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEK,GAAG,EACf;EAEF,IAAMC,SAAS,GAAGL,MAAM,CAACM,KAAK,CAACR,IAAI,CAAC;EAEpC,OAAOO,SAAS;AAClB;;AAQO,SAASE,iBAAiB,CAACT,IAAY,EAAEC,OAAO,EAAO;EAC5D,IAAMC,MAAM,GAAG,IAAIQ,oBAAS,iCACvBT,OAAO;IACVU,MAAM,EAAE;EAAI,GACZ;EAEFT,MAAM,CAACU,KAAK,CAACZ,IAAI,CAAC;EAClBE,MAAM,CAACW,KAAK,EAAE;EAEd,OAAOX,MAAM,CAACY,MAAM;AACtB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"xml-parser.js","names":["XMLParser","options","undefined","Object","freeze","container","key","reset","parser","SAXParser","onready","previousStates","length","currentState","onopentag","name","attributes","isSelfClosing","_openObject","emit","onkey","onclosetag","_closeObject","onopenarray","_openArray","onclosearray","_closeArray","ontext","value","_pushOrSet","onerror","error","onend","result","pop","chunk","write","close","Array","isArray","push","newContainer"],"sources":["../../../../src/lib/parser/xml-parser.ts"],"sourcesContent":["// @ts-nocheck\n/* eslint-disable */\n\n// import ClarinetParser, {ClarinetParserOptions} from '../clarinet/clarinet';\nimport {SAXParser, SAXParserOptions} from '../../sax-ts/sax';\n// import JSONPath from '../jsonpath/jsonpath';\n\n// XMLParser builds a JSON object using the events emitted by the Clarinet parser\n\nexport class XMLParser {\n readonly parser: SAXParser;\n result = undefined;\n previousStates = [];\n currentState = Object.freeze({container: [], key: null});\n // jsonpath: JSONPath = new JSONPath();\n\n constructor(options: SAXParserOptions) {\n this.reset();\n this.parser = new SAXParser({\n onready: () => {\n this.previousStates.length = 0;\n this.currentState.container.length = 0;\n },\n\n onopentag: ({name, attributes, isSelfClosing}) => {\n this._openObject({});\n if (typeof name !== 'undefined') {\n this.parser.emit('onkey', name);\n }\n },\n\n onkey: (name) => {\n this.currentState.key = name;\n },\n\n onclosetag: () => {\n this._closeObject();\n },\n\n onopenarray: () => {\n this._openArray();\n },\n\n onclosearray: () => {\n this._closeArray();\n },\n\n ontext: (value) => {\n this._pushOrSet(value);\n },\n\n onerror: (error) => {\n throw error;\n },\n\n onend: () => {\n this.result = this.currentState.container.pop();\n },\n\n ...options\n });\n }\n\n reset(): void {\n this.result = undefined;\n this.previousStates = [];\n this.currentState = Object.freeze({container: [], key: null});\n }\n\n write(chunk): void {\n this.parser.write(chunk);\n }\n\n close(): void {\n this.parser.close();\n }\n\n // PRIVATE METHODS\n\n _pushOrSet(value): void {\n const {container, key} = this.currentState;\n if (key !== null) {\n container[key] = value;\n this.currentState.key = null;\n } else if (Array.isArray(container)) {\n container.push(value);\n } else if (container) {\n // debugger\n }\n }\n\n _openArray(newContainer = []): void {\n // this.jsonpath.push(null);\n this._pushOrSet(newContainer);\n this.previousStates.push(this.currentState);\n this.currentState = {container: newContainer, isArray: true, key: null};\n }\n\n _closeArray(): void {\n // this.jsonpath.pop();\n this.currentState = this.previousStates.pop();\n }\n\n _openObject(newContainer = {}): void {\n // this.jsonpath.push(null);\n this._pushOrSet(newContainer);\n this.previousStates.push(this.currentState);\n this.currentState = {container: newContainer, isArray: false, key: null};\n }\n\n _closeObject(): void {\n // this.jsonpath.pop();\n this.currentState = this.previousStates.pop();\n }\n}\n"],"mappings":";;;;;;;;;;AAIA;AAA6D;AAAA;AAAA,IAKhDA,SAAS;;EAOpB,mBAAYC,OAAyB,EAAE;IAAA;IAAA;IAAA;IAAA,8CAL9BC,SAAS;IAAA,sDACD,EAAE;IAAA,oDACJC,MAAM,CAACC,MAAM,CAAC;MAACC,SAAS,EAAE,EAAE;MAAEC,GAAG,EAAE;IAAI,CAAC,CAAC;IAItD,IAAI,CAACC,KAAK,EAAE;IACZ,IAAI,CAACC,MAAM,GAAG,IAAIC,cAAS;MACzBC,OAAO,EAAE,mBAAM;QACb,KAAI,CAACC,cAAc,CAACC,MAAM,GAAG,CAAC;QAC9B,KAAI,CAACC,YAAY,CAACR,SAAS,CAACO,MAAM,GAAG,CAAC;MACxC,CAAC;MAEDE,SAAS,EAAE,yBAAuC;QAAA,IAArCC,IAAI,QAAJA,IAAI;UAAEC,UAAU,QAAVA,UAAU;UAAEC,aAAa,QAAbA,aAAa;QAC1C,KAAI,CAACC,WAAW,CAAC,CAAC,CAAC,CAAC;QAC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0 @@
1
- {"version":3,"file":"parse-xml.js","names":["XMLParser","FastXMLParser","parseXML","text","options","parser","ignoreAttributes","attributeNamePrefix","xml","parsedXML","parse","parseXMLInBatches","strict","write","close","result"],"sources":["../../../src/lib/parse-xml.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport {XMLParser} from '../lib/parser/xml-parser';\nimport {XMLParser as FastXMLParser} from 'fast-xml-parser';\n\nexport function parseXML(text: string, options): any {\n const parser = new FastXMLParser({\n ignoreAttributes: false,\n attributeNamePrefix: '',\n // parseAttributeValue: true,\n ...options?.xml\n });\n\n const parsedXML = parser.parse(text);\n\n return parsedXML;\n}\n\n/**\n * @todo Build a streaming XML parser based on sax-js\n * @param text\n * @param options\n * @returns\n */\nexport function parseXMLInBatches(text: string, options): any {\n const parser = new XMLParser({\n ...options,\n strict: true\n });\n\n parser.write(text);\n parser.close();\n\n return parser.result;\n}\n"],"mappings":";;AAEA,SAAQA,SAAS,QAAO,0BAA0B;AAClD,SAAQA,SAAS,IAAIC,aAAa,QAAO,iBAAiB;AAE1D,OAAO,SAASC,QAAQ,CAACC,IAAY,EAAEC,OAAO,EAAO;EACnD,MAAMC,MAAM,GAAG,IAAIJ,aAAa,CAAC;IAC/BK,gBAAgB,EAAE,KAAK;IACvBC,mBAAmB,EAAE,EAAE;IAEvB,IAAGH,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEI,GAAG;EACjB,CAAC,CAAC;EAEF,MAAMC,SAAS,GAAGJ,MAAM,CAACK,KAAK,CAACP,IAAI,CAAC;EAEpC,OAAOM,SAAS;AAClB;;AAQA,OAAO,SAASE,iBAAiB,CAACR,IAAY,EAAEC,OAAO,EAAO;EAC5D,MAAMC,MAAM,GAAG,IAAIL,SAAS,CAAC;IAC3B,GAAGI,OAAO;IACVQ,MAAM,EAAE;EACV,CAAC,CAAC;EAEFP,MAAM,CAACQ,KAAK,CAACV,IAAI,CAAC;EAClBE,MAAM,CAACS,KAAK,EAAE;EAEd,OAAOT,MAAM,CAACU,MAAM;AACtB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"xml-parser.js","names":["SAXParser","XMLParser","constructor","options","undefined","Object","freeze","container","key","reset","parser","onready","previousStates","length","currentState","onopentag","name","attributes","isSelfClosing","_openObject","emit","onkey","onclosetag","_closeObject","onopenarray","_openArray","onclosearray","_closeArray","ontext","value","_pushOrSet","onerror","error","onend","result","pop","write","chunk","close","Array","isArray","push","newContainer"],"sources":["../../../../src/lib/parser/xml-parser.ts"],"sourcesContent":["// @ts-nocheck\n/* eslint-disable */\n\n// import ClarinetParser, {ClarinetParserOptions} from '../clarinet/clarinet';\nimport {SAXParser, SAXParserOptions} from '../../sax-ts/sax';\n// import JSONPath from '../jsonpath/jsonpath';\n\n// XMLParser builds a JSON object using the events emitted by the Clarinet parser\n\nexport class XMLParser {\n readonly parser: SAXParser;\n result = undefined;\n previousStates = [];\n currentState = Object.freeze({container: [], key: null});\n // jsonpath: JSONPath = new JSONPath();\n\n constructor(options: SAXParserOptions) {\n this.reset();\n this.parser = new SAXParser({\n onready: () => {\n this.previousStates.length = 0;\n this.currentState.container.length = 0;\n },\n\n onopentag: ({name, attributes, isSelfClosing}) => {\n this._openObject({});\n if (typeof name !== 'undefined') {\n this.parser.emit('onkey', name);\n }\n },\n\n onkey: (name) => {\n this.currentState.key = name;\n },\n\n onclosetag: () => {\n this._closeObject();\n },\n\n onopenarray: () => {\n this._openArray();\n },\n\n onclosearray: () => {\n this._closeArray();\n },\n\n ontext: (value) => {\n this._pushOrSet(value);\n },\n\n onerror: (error) => {\n throw error;\n },\n\n onend: () => {\n this.result = this.currentState.container.pop();\n },\n\n ...options\n });\n }\n\n reset(): void {\n this.result = undefined;\n this.previousStates = [];\n this.currentState = Object.freeze({container: [], key: null});\n }\n\n write(chunk): void {\n this.parser.write(chunk);\n }\n\n close(): void {\n this.parser.close();\n }\n\n // PRIVATE METHODS\n\n _pushOrSet(value): void {\n const {container, key} = this.currentState;\n if (key !== null) {\n container[key] = value;\n this.currentState.key = null;\n } else if (Array.isArray(container)) {\n container.push(value);\n } else if (container) {\n // debugger\n }\n }\n\n _openArray(newContainer = []): void {\n // this.jsonpath.push(null);\n this._pushOrSet(newContainer);\n this.previousStates.push(this.currentState);\n this.currentState = {container: newContainer, isArray: true, key: null};\n }\n\n _closeArray(): void {\n // this.jsonpath.pop();\n this.currentState = this.previousStates.pop();\n }\n\n _openObject(newContainer = {}): void {\n // this.jsonpath.push(null);\n this._pushOrSet(newContainer);\n this.previousStates.push(this.currentState);\n this.currentState = {container: newContainer, isArray: false, key: null};\n }\n\n _closeObject(): void {\n // this.jsonpath.pop();\n this.currentState = this.previousStates.pop();\n }\n}\n"],"mappings":";;AAIA,SAAQA,SAAS,QAAyB,kBAAkB;;AAK5D,OAAO,MAAMC,SAAS,CAAC;;EAOrBC,WAAW,CAACC,OAAyB,EAAE;IAAA;IAAA,gCAL9BC,SAAS;IAAA,wCACD,EAAE;IAAA,sCACJC,MAAM,CAACC,MAAM,CAAC;MAACC,SAAS,EAAE,EAAE;MAAEC,GAAG,EAAE;IAAI,CAAC,CAAC;IAItD,IAAI,CAACC,KAAK,EAAE;IACZ,IAAI,CAACC,MAAM,GAAG,IAAIV,SAAS,CAAC;MAC1BW,OAAO,EAAE,MAAM;QACb,IAAI,CAACC,cAAc,CAACC,MAAM,GAAG,CAAC;QAC9B,IAAI,CAACC,YAAY,CAACP,SAAS,CAACM,MAAM,GAAG,CAAC;MACxC,CAAC;MAEDE,SAAS,EAAE,QAAuC;QAAA,IAAtC;UAACC,IAAI;UAAEC,UAAU;UAAEC;QAAa,CAAC;QAC3C,IAAI,CAACC,WAAW,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,OAAOH,IAAI,KAAK,WAAW,EAAE;UAC/B,IAAI,CAACN,MAAM,CAACU,IAAI,CAAC,OAAO,EAAEJ,IAAI,CAAC;QACjC;MACF,CAAC;MAEDK,KAAK,EAAGL,IAAI,IAAK;QACf,IAAI,CAACF,YAAY,CAACN,GAA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;MACnCA,SAAS,CAACkC,IAAI,CAACZ,KAAK,CAAC;IACvB,CAAC,MAAM,IAAItB,SAAS,EAAE;IAEtB;EACF;EAEAkB,UAAU,GAA0B;IAAA,IAAzBiB,YAAY,uEAAG,EAAE;IAE1B,IAAI,CAACZ,UAAU,CAACY,YAAY,CAAC;IAC7B,IAAI,CAAC9B,cAAc,CAAC6B,IAAI,CAAC,IAAI,CAAC3B,YAAY,CAAC;IAC3C,IAAI,CAACA,YAAY,GAAG;MAACP,SAAS,EAAEmC,YAAY;MAAEF,OAAO,EAAE,IAAI;MAAEhC,GAAG,EAAE;IAAI,CAAC;EACzE;EAEAmB,WAAW,GAAS;IAElB,IAAI,CAACb,YAAY,GAAG,IAAI,CAACF,cAAc,CAACuB,GAAG,EAAE;EAC/C;EAEAhB,WAAW,GAA0B;IAAA,IAAzBuB,YAAY,uEAAG,CAAC,CAAC;IAE3B,IAAI,CAACZ,UAAU,CAACY,YAAY,CAAC;IAC7B,IAAI,CAAC9B,cAAc,CAAC6B,IAAI,CAAC,IAAI,CAAC3B,YAAY,CAAC;IAC3C,IAAI,CAACA,YAAY,GAAG;MAACP,SAAS,EAAEmC,YAAY;MAAEF,OAAO,EAAE,KAAK;MAAEhC,GAAG,EAAE;IAAI,CAAC;EAC1E;EAEAe,YAAY,GAAS;IAEnB,IAAI,CAACT,YAAY,GAAG,IAAI,CAACF,cAAc,CAACuB,GAAG,EAAE;EAC/C;AACF"}
@@ -1,9 +0,0 @@
1
- export declare function parseXML(text: string, options: any): any;
2
- /**
3
- * @todo Build a streaming XML parser based on sax-js
4
- * @param text
5
- * @param options
6
- * @returns
7
- */
8
- export declare function parseXMLInBatches(text: string, options: any): any;
9
- //# sourceMappingURL=parse-xml.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parse-xml.d.ts","sourceRoot":"","sources":["../../src/lib/parse-xml.ts"],"names":[],"mappings":"AAKA,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,KAAA,GAAG,GAAG,CAWnD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,KAAA,GAAG,GAAG,CAU5D"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"xml-parser.d.ts","sourceRoot":"","sources":["../../../src/lib/parser/xml-parser.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,SAAS,EAAE,gBAAgB,EAAC,MAAM,kBAAkB,CAAC;AAK7D,qBAAa,SAAS;IACpB,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,MAAM,YAAa;IACnB,cAAc,UAAM;IACpB,YAAY;;;OAA6C;gBAG7C,OAAO,EAAE,gBAAgB;IA+CrC,KAAK,IAAI,IAAI;IAMb,KAAK,CAAC,KAAK,KAAA,GAAG,IAAI;IAIlB,KAAK,IAAI,IAAI;IAMb,UAAU,CAAC,KAAK,KAAA,GAAG,IAAI;IAYvB,UAAU,CAAC,YAAY,UAAK,GAAG,IAAI;IAOnC,WAAW,IAAI,IAAI;IAKnB,WAAW,CAAC,YAAY,KAAK,GAAG,IAAI;IAOpC,YAAY,IAAI,IAAI;CAIrB"}