@loaders.gl/xml 3.4.14 → 3.4.15
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.
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/html-loader.js +6 -29
- package/dist/es5/html-loader.js.map +1 -1
- package/dist/es5/index.js +7 -7
- package/dist/es5/lib/parsers/parse-xml.js +9 -11
- package/dist/es5/lib/parsers/parse-xml.js.map +1 -1
- package/dist/es5/lib/parsers/streaming-xml-parser.js +83 -103
- package/dist/es5/lib/parsers/streaming-xml-parser.js.map +1 -1
- package/dist/es5/lib/xml-utils/uncapitalize.js +4 -12
- package/dist/es5/lib/xml-utils/uncapitalize.js.map +1 -1
- package/dist/es5/lib/xml-utils/xml-utils.js +1 -3
- package/dist/es5/lib/xml-utils/xml-utils.js.map +1 -1
- package/dist/es5/sax-ts/sax.js +834 -904
- package/dist/es5/sax-ts/sax.js.map +1 -1
- package/dist/es5/xml-loader.js +17 -39
- package/dist/es5/xml-loader.js.map +1 -1
- package/dist/esm/xml-loader.js +1 -1
- package/package.json +4 -4
package/dist/es5/bundle.js
CHANGED
package/dist/es5/bundle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.js","names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"sources":["../../src/bundle.ts"],"sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.loaders = globalThis.loaders || {};\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"mappings":";;AACA,
|
|
1
|
+
{"version":3,"file":"bundle.js","names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"sources":["../../src/bundle.ts"],"sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.loaders = globalThis.loaders || {};\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"mappings":";;AACA,MAAMA,aAAa,GAAGC,OAAO,CAAC,SAAS,CAAC;AACxCC,UAAU,CAACC,OAAO,GAAGD,UAAU,CAACC,OAAO,IAAI,CAAC,CAAC;AAC7CC,MAAM,CAACC,OAAO,GAAGC,MAAM,CAACC,MAAM,CAACL,UAAU,CAACC,OAAO,EAAEH,aAAa,CAAC"}
|
package/dist/es5/html-loader.js
CHANGED
|
@@ -1,49 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.HTMLLoader = void 0;
|
|
8
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
7
|
var _loaderUtils = require("@loaders.gl/loader-utils");
|
|
12
8
|
var _xmlLoader = require("./xml-loader");
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var HTMLLoader = _objectSpread(_objectSpread({}, _xmlLoader.XMLLoader), {}, {
|
|
9
|
+
const HTMLLoader = {
|
|
10
|
+
..._xmlLoader.XMLLoader,
|
|
16
11
|
name: 'HTML',
|
|
17
12
|
id: 'html',
|
|
18
13
|
extensions: ['html', 'htm'],
|
|
19
14
|
mimeTypes: ['text/html'],
|
|
20
15
|
testText: testHTMLFile,
|
|
21
|
-
parse:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
while (1) switch (_context.prev = _context.next) {
|
|
25
|
-
case 0:
|
|
26
|
-
return _context.abrupt("return", _parseTextSync(new TextDecoder().decode(arrayBuffer), options));
|
|
27
|
-
case 1:
|
|
28
|
-
case "end":
|
|
29
|
-
return _context.stop();
|
|
30
|
-
}
|
|
31
|
-
}, _callee);
|
|
32
|
-
}));
|
|
33
|
-
function parse(_x, _x2) {
|
|
34
|
-
return _parse.apply(this, arguments);
|
|
35
|
-
}
|
|
36
|
-
return parse;
|
|
37
|
-
}(),
|
|
38
|
-
parseTextSync: function parseTextSync(text, options) {
|
|
39
|
-
return _parseTextSync(text, options);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
16
|
+
parse: async (arrayBuffer, options) => parseTextSync(new TextDecoder().decode(arrayBuffer), options),
|
|
17
|
+
parseTextSync: (text, options) => parseTextSync(text, options)
|
|
18
|
+
};
|
|
42
19
|
exports.HTMLLoader = HTMLLoader;
|
|
43
20
|
function testHTMLFile(text) {
|
|
44
21
|
return text.startsWith('<html');
|
|
45
22
|
}
|
|
46
|
-
function
|
|
23
|
+
function parseTextSync(text, options) {
|
|
47
24
|
options = (0, _loaderUtils.mergeLoaderOptions)(options, {
|
|
48
25
|
xml: {
|
|
49
26
|
parser: 'fast-xml-parser'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-loader.js","names":["_loaderUtils","require","_xmlLoader","
|
|
1
|
+
{"version":3,"file":"html-loader.js","names":["_loaderUtils","require","_xmlLoader","HTMLLoader","XMLLoader","name","id","extensions","mimeTypes","testText","testHTMLFile","parse","arrayBuffer","options","parseTextSync","TextDecoder","decode","text","exports","startsWith","mergeLoaderOptions","xml","parser","_fastXML","htmlEntities"],"sources":["../../src/html-loader.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport type {LoaderWithParser} from '@loaders.gl/loader-utils';\nimport {mergeLoaderOptions} from '@loaders.gl/loader-utils';\nimport {XMLLoader, XMLLoaderOptions} from './xml-loader';\n\nexport type HTMLLoaderOptions = XMLLoaderOptions;\n\n/**\n * Loader for HTML files\n * Essentially a copy of the XMLLoader with different mime types, file extensions and content tests.\n * This split enables applications can control whether they want HTML responses to be parsed by the XML loader or not.\n * This loader does not have any additional understanding of the structure of HTML or the document.\n */\nexport const HTMLLoader: LoaderWithParser = {\n ...XMLLoader,\n name: 'HTML',\n id: 'html',\n extensions: ['html', 'htm'],\n mimeTypes: ['text/html'],\n testText: testHTMLFile,\n parse: async (arrayBuffer: ArrayBuffer, options?: XMLLoaderOptions) =>\n parseTextSync(new TextDecoder().decode(arrayBuffer), options),\n parseTextSync: (text: string, options?: XMLLoaderOptions) => parseTextSync(text, options)\n};\n\nfunction testHTMLFile(text: string): boolean {\n // TODO - There could be space first.\n return text.startsWith('<html');\n}\n\nfunction parseTextSync(text: string, options?: XMLLoaderOptions): any {\n // fast-xml-parser can recognize HTML entities\n // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#htmlentities\n // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/5.Entities.md\n options = mergeLoaderOptions(options, {\n xml: {\n parser: 'fast-xml-parser'\n },\n _fastXML: {\n htmlEntities: true\n }\n });\n\n return XMLLoader.parseTextSync(text, options);\n}\n"],"mappings":";;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AAUO,MAAME,UAA4B,GAAG;EAC1C,GAAGC,oBAAS;EACZC,IAAI,EAAE,MAAM;EACZC,EAAE,EAAE,MAAM;EACVC,UAAU,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC;EAC3BC,SAAS,EAAE,CAAC,WAAW,CAAC;EACxBC,QAAQ,EAAEC,YAAY;EACtBC,KAAK,EAAE,MAAAA,CAAOC,WAAwB,EAAEC,OAA0B,KAChEC,aAAa,CAAC,IAAIC,WAAW,CAAC,CAAC,CAACC,MAAM,CAACJ,WAAW,CAAC,EAAEC,OAAO,CAAC;EAC/DC,aAAa,EAAEA,CAACG,IAAY,EAAEJ,OAA0B,KAAKC,aAAa,CAACG,IAAI,EAAEJ,OAAO;AAC1F,CAAC;AAACK,OAAA,CAAAf,UAAA,GAAAA,UAAA;AAEF,SAASO,YAAYA,CAACO,IAAY,EAAW;EAE3C,OAAOA,IAAI,CAACE,UAAU,CAAC,OAAO,CAAC;AACjC;AAEA,SAASL,aAAaA,CAACG,IAAY,EAAEJ,OAA0B,EAAO;EAIpEA,OAAO,GAAG,IAAAO,+BAAkB,EAACP,OAAO,EAAE;IACpCQ,GAAG,EAAE;MACHC,MAAM,EAAE;IACV,CAAC;IACDC,QAAQ,EAAE;MACRC,YAAY,EAAE;IAChB;EACF,CAAC,CAAC;EAEF,OAAOpB,oBAAS,CAACU,aAAa,CAACG,IAAI,EAAEJ,OAAO,CAAC;AAC/C"}
|
package/dist/es5/index.js
CHANGED
|
@@ -5,43 +5,43 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
Object.defineProperty(exports, "HTMLLoader", {
|
|
7
7
|
enumerable: true,
|
|
8
|
-
get: function
|
|
8
|
+
get: function () {
|
|
9
9
|
return _htmlLoader.HTMLLoader;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "SAXParser", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function
|
|
14
|
+
get: function () {
|
|
15
15
|
return _sax.SAXParser;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
Object.defineProperty(exports, "XMLLoader", {
|
|
19
19
|
enumerable: true,
|
|
20
|
-
get: function
|
|
20
|
+
get: function () {
|
|
21
21
|
return _xmlLoader.XMLLoader;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
24
|
Object.defineProperty(exports, "_uncapitalize", {
|
|
25
25
|
enumerable: true,
|
|
26
|
-
get: function
|
|
26
|
+
get: function () {
|
|
27
27
|
return _uncapitalize.uncapitalize;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
30
|
Object.defineProperty(exports, "_uncapitalizeKeys", {
|
|
31
31
|
enumerable: true,
|
|
32
|
-
get: function
|
|
32
|
+
get: function () {
|
|
33
33
|
return _uncapitalize.uncapitalizeKeys;
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
Object.defineProperty(exports, "convertXMLFieldToArrayInPlace", {
|
|
37
37
|
enumerable: true,
|
|
38
|
-
get: function
|
|
38
|
+
get: function () {
|
|
39
39
|
return _xmlUtils.convertXMLFieldToArrayInPlace;
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
Object.defineProperty(exports, "convertXMLValueToArray", {
|
|
43
43
|
enumerable: true,
|
|
44
|
-
get: function
|
|
44
|
+
get: function () {
|
|
45
45
|
return _xmlUtils.convertXMLValueToArray;
|
|
46
46
|
}
|
|
47
47
|
});
|
|
@@ -1,29 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.fastParseXML = fastParseXML;
|
|
8
7
|
exports.parseXMLInBatches = parseXMLInBatches;
|
|
9
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
8
|
var _streamingXmlParser = require("./streaming-xml-parser");
|
|
11
9
|
var _fastXmlParser = require("fast-xml-parser");
|
|
12
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
13
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
14
10
|
function fastParseXML(text, options) {
|
|
15
|
-
|
|
11
|
+
const parser = new _fastXmlParser.XMLParser({
|
|
16
12
|
ignoreAttributes: false,
|
|
17
|
-
attributeNamePrefix: ''
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
attributeNamePrefix: '',
|
|
14
|
+
...options
|
|
15
|
+
});
|
|
16
|
+
const parsedXML = parser.parse(text);
|
|
20
17
|
return parsedXML;
|
|
21
18
|
}
|
|
22
19
|
function parseXMLInBatches(text) {
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
21
|
+
const parser = new _streamingXmlParser.StreamingXMLParser({
|
|
22
|
+
...options,
|
|
25
23
|
strict: true
|
|
26
|
-
})
|
|
24
|
+
});
|
|
27
25
|
parser.write(text);
|
|
28
26
|
parser.close();
|
|
29
27
|
return parser.result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-xml.js","names":["_streamingXmlParser","require","_fastXmlParser","
|
|
1
|
+
{"version":3,"file":"parse-xml.js","names":["_streamingXmlParser","require","_fastXmlParser","fastParseXML","text","options","parser","FastXMLParser","ignoreAttributes","attributeNamePrefix","parsedXML","parse","parseXMLInBatches","arguments","length","undefined","StreamingXMLParser","strict","write","close","result"],"sources":["../../../../src/lib/parsers/parse-xml.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport {StreamingXMLParser} from './streaming-xml-parser';\nimport {XMLParser as FastXMLParser} from 'fast-xml-parser';\nimport type {X2jOptions} from 'fast-xml-parser';\n\n/** Type for passing through fast-xml-parser options */\nexport type FastXMLParserOptions = Partial<X2jOptions>;\n\nexport function fastParseXML(text: string, options: FastXMLParserOptions): any {\n const parser = new FastXMLParser({\n ignoreAttributes: false,\n attributeNamePrefix: '',\n ...options\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 StreamingXMLParser({\n ...options,\n strict: true\n });\n\n parser.write(text);\n parser.close();\n\n return parser.result;\n}\n"],"mappings":";;;;;;;AAEA,IAAAA,mBAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AAMO,SAASE,YAAYA,CAACC,IAAY,EAAEC,OAA6B,EAAO;EAC7E,MAAMC,MAAM,GAAG,IAAIC,wBAAa,CAAC;IAC/BC,gBAAgB,EAAE,KAAK;IACvBC,mBAAmB,EAAE,EAAE;IACvB,GAAGJ;EACL,CAAC,CAAC;EAEF,MAAMK,SAAS,GAAGJ,MAAM,CAACK,KAAK,CAACP,IAAI,CAAC;EAEpC,OAAOM,SAAS;AAClB;AAQO,SAASE,iBAAiBA,CAACR,IAAY,EAAqB;EAAA,IAAnBC,OAAO,GAAAQ,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAC1D,MAAMP,MAAM,GAAG,IAAIU,sCAAkB,CAAC;IACpC,GAAGX,OAAO;IACVY,MAAM,EAAE;EACV,CAAC,CAAC;EAEFX,MAAM,CAACY,KAAK,CAACd,IAAI,CAAC;EAClBE,MAAM,CAACa,KAAK,CAAC,CAAC;EAEd,OAAOb,MAAM,CAACc,MAAM;AACtB"}
|
|
@@ -5,16 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.StreamingXMLParser = void 0;
|
|
8
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
9
|
var _sax = require("../../sax-ts/sax");
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var StreamingXMLParser = function () {
|
|
15
|
-
function StreamingXMLParser(options) {
|
|
16
|
-
var _this = this;
|
|
17
|
-
(0, _classCallCheck2.default)(this, StreamingXMLParser);
|
|
10
|
+
class StreamingXMLParser {
|
|
11
|
+
constructor(options) {
|
|
18
12
|
(0, _defineProperty2.default)(this, "parser", void 0);
|
|
19
13
|
(0, _defineProperty2.default)(this, "result", undefined);
|
|
20
14
|
(0, _defineProperty2.default)(this, "previousStates", []);
|
|
@@ -23,112 +17,98 @@ var StreamingXMLParser = function () {
|
|
|
23
17
|
key: null
|
|
24
18
|
}));
|
|
25
19
|
this.reset();
|
|
26
|
-
this.parser = new _sax.SAXParser(
|
|
27
|
-
onready:
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
this.parser = new _sax.SAXParser({
|
|
21
|
+
onready: () => {
|
|
22
|
+
this.previousStates.length = 0;
|
|
23
|
+
this.currentState.container.length = 0;
|
|
30
24
|
},
|
|
31
|
-
onopentag:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
onopentag: _ref => {
|
|
26
|
+
let {
|
|
27
|
+
name,
|
|
28
|
+
attributes,
|
|
29
|
+
isSelfClosing
|
|
30
|
+
} = _ref;
|
|
31
|
+
this._openObject({});
|
|
36
32
|
if (typeof name !== 'undefined') {
|
|
37
|
-
|
|
33
|
+
this.parser.emit('onkey', name);
|
|
38
34
|
}
|
|
39
35
|
},
|
|
40
|
-
onkey:
|
|
41
|
-
|
|
36
|
+
onkey: name => {
|
|
37
|
+
this.currentState.key = name;
|
|
42
38
|
},
|
|
43
|
-
onclosetag:
|
|
44
|
-
|
|
39
|
+
onclosetag: () => {
|
|
40
|
+
this._closeObject();
|
|
45
41
|
},
|
|
46
|
-
onopenarray:
|
|
47
|
-
|
|
42
|
+
onopenarray: () => {
|
|
43
|
+
this._openArray();
|
|
48
44
|
},
|
|
49
|
-
onclosearray:
|
|
50
|
-
|
|
45
|
+
onclosearray: () => {
|
|
46
|
+
this._closeArray();
|
|
51
47
|
},
|
|
52
|
-
ontext:
|
|
53
|
-
|
|
48
|
+
ontext: value => {
|
|
49
|
+
this._pushOrSet(value);
|
|
54
50
|
},
|
|
55
|
-
onerror:
|
|
51
|
+
onerror: error => {
|
|
56
52
|
throw error;
|
|
57
53
|
},
|
|
58
|
-
onend:
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
54
|
+
onend: () => {
|
|
55
|
+
this.result = this.currentState.container.pop();
|
|
56
|
+
},
|
|
57
|
+
...options
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
reset() {
|
|
61
|
+
this.result = undefined;
|
|
62
|
+
this.previousStates = [];
|
|
63
|
+
this.currentState = Object.freeze({
|
|
64
|
+
container: [],
|
|
65
|
+
key: null
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
write(chunk) {
|
|
69
|
+
this.parser.write(chunk);
|
|
70
|
+
}
|
|
71
|
+
close() {
|
|
72
|
+
this.parser.close();
|
|
73
|
+
}
|
|
74
|
+
_pushOrSet(value) {
|
|
75
|
+
const {
|
|
76
|
+
container,
|
|
77
|
+
key
|
|
78
|
+
} = this.currentState;
|
|
79
|
+
if (key !== null) {
|
|
80
|
+
container[key] = value;
|
|
81
|
+
this.currentState.key = null;
|
|
82
|
+
} else if (Array.isArray(container)) {
|
|
83
|
+
container.push(value);
|
|
84
|
+
} else if (container) {}
|
|
85
|
+
}
|
|
86
|
+
_openArray() {
|
|
87
|
+
let newContainer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
88
|
+
this._pushOrSet(newContainer);
|
|
89
|
+
this.previousStates.push(this.currentState);
|
|
90
|
+
this.currentState = {
|
|
91
|
+
container: newContainer,
|
|
92
|
+
isArray: true,
|
|
93
|
+
key: null
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
_closeArray() {
|
|
97
|
+
this.currentState = this.previousStates.pop();
|
|
98
|
+
}
|
|
99
|
+
_openObject() {
|
|
100
|
+
let newContainer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
101
|
+
this._pushOrSet(newContainer);
|
|
102
|
+
this.previousStates.push(this.currentState);
|
|
103
|
+
this.currentState = {
|
|
104
|
+
container: newContainer,
|
|
105
|
+
isArray: false,
|
|
106
|
+
key: null
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
_closeObject() {
|
|
110
|
+
this.currentState = this.previousStates.pop();
|
|
62
111
|
}
|
|
63
|
-
|
|
64
|
-
key: "reset",
|
|
65
|
-
value: function reset() {
|
|
66
|
-
this.result = undefined;
|
|
67
|
-
this.previousStates = [];
|
|
68
|
-
this.currentState = Object.freeze({
|
|
69
|
-
container: [],
|
|
70
|
-
key: null
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}, {
|
|
74
|
-
key: "write",
|
|
75
|
-
value: function write(chunk) {
|
|
76
|
-
this.parser.write(chunk);
|
|
77
|
-
}
|
|
78
|
-
}, {
|
|
79
|
-
key: "close",
|
|
80
|
-
value: function close() {
|
|
81
|
-
this.parser.close();
|
|
82
|
-
}
|
|
83
|
-
}, {
|
|
84
|
-
key: "_pushOrSet",
|
|
85
|
-
value: function _pushOrSet(value) {
|
|
86
|
-
var _this$currentState = this.currentState,
|
|
87
|
-
container = _this$currentState.container,
|
|
88
|
-
key = _this$currentState.key;
|
|
89
|
-
if (key !== null) {
|
|
90
|
-
container[key] = value;
|
|
91
|
-
this.currentState.key = null;
|
|
92
|
-
} else if (Array.isArray(container)) {
|
|
93
|
-
container.push(value);
|
|
94
|
-
} else if (container) {}
|
|
95
|
-
}
|
|
96
|
-
}, {
|
|
97
|
-
key: "_openArray",
|
|
98
|
-
value: function _openArray() {
|
|
99
|
-
var newContainer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
100
|
-
this._pushOrSet(newContainer);
|
|
101
|
-
this.previousStates.push(this.currentState);
|
|
102
|
-
this.currentState = {
|
|
103
|
-
container: newContainer,
|
|
104
|
-
isArray: true,
|
|
105
|
-
key: null
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
}, {
|
|
109
|
-
key: "_closeArray",
|
|
110
|
-
value: function _closeArray() {
|
|
111
|
-
this.currentState = this.previousStates.pop();
|
|
112
|
-
}
|
|
113
|
-
}, {
|
|
114
|
-
key: "_openObject",
|
|
115
|
-
value: function _openObject() {
|
|
116
|
-
var newContainer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
117
|
-
this._pushOrSet(newContainer);
|
|
118
|
-
this.previousStates.push(this.currentState);
|
|
119
|
-
this.currentState = {
|
|
120
|
-
container: newContainer,
|
|
121
|
-
isArray: false,
|
|
122
|
-
key: null
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
}, {
|
|
126
|
-
key: "_closeObject",
|
|
127
|
-
value: function _closeObject() {
|
|
128
|
-
this.currentState = this.previousStates.pop();
|
|
129
|
-
}
|
|
130
|
-
}]);
|
|
131
|
-
return StreamingXMLParser;
|
|
132
|
-
}();
|
|
112
|
+
}
|
|
133
113
|
exports.StreamingXMLParser = StreamingXMLParser;
|
|
134
114
|
//# sourceMappingURL=streaming-xml-parser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streaming-xml-parser.js","names":["_sax","require","
|
|
1
|
+
{"version":3,"file":"streaming-xml-parser.js","names":["_sax","require","StreamingXMLParser","constructor","options","_defineProperty2","default","undefined","Object","freeze","container","key","reset","parser","SAXParser","onready","previousStates","length","currentState","onopentag","_ref","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","arguments","exports"],"sources":["../../../../src/lib/parsers/streaming-xml-parser.ts"],"sourcesContent":["// @ts-nocheck\n/* eslint-disable */\n\nimport {SAXParser, SAXParserOptions} from '../../sax-ts/sax';\n// import JSONPath from '../jsonpath/jsonpath';\n\nexport type StreamingXMLParserOptions = SAXParserOptions;\n\n/**\n * StreamingXMLParser builds a JSON object using the events emitted by the SAX parser\n */\nexport class StreamingXMLParser {\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":";;;;;;;;AAGA,IAAAA,IAAA,GAAAC,OAAA;AAQO,MAAMC,kBAAkB,CAAC;EAO9BC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I,CAAC/B,cAAc,CAAC8B,IAAI,CAAC,IAAI,CAAC5B,YAAY,CAAC;IAC3C,IAAI,CAACA,YAAY,GAAG;MAACR,SAAS,EAAEqC,YAAY;MAAEF,OAAO,EAAE,IAAI;MAAElC,GAAG,EAAE;IAAI,CAAC;EACzE;EAEAqB,WAAWA,CAAA,EAAS;IAElB,IAAI,CAACd,YAAY,GAAG,IAAI,CAACF,cAAc,CAACwB,GAAG,CAAC,CAAC;EAC/C;EAEAhB,WAAWA,CAAA,EAA0B;IAAA,IAAzBuB,YAAY,GAAAC,SAAA,CAAA/B,MAAA,QAAA+B,SAAA,QAAAzC,SAAA,GAAAyC,SAAA,MAAG,CAAC,CAAC;IAE3B,IAAI,CAACb,UAAU,CAACY,YAAY,CAAC;IAC7B,IAAI,CAAC/B,cAAc,CAAC8B,IAAI,CAAC,IAAI,CAAC5B,YAAY,CAAC;IAC3C,IAAI,CAACA,YAAY,GAAG;MAACR,SAAS,EAAEqC,YAAY;MAAEF,OAAO,EAAE,KAAK;MAAElC,GAAG,EAAE;IAAI,CAAC;EAC1E;EAEAiB,YAAYA,CAAA,EAAS;IAEnB,IAAI,CAACV,YAAY,GAAG,IAAI,CAACF,cAAc,CAACwB,GAAG,CAAC,CAAC;EAC/C;AACF;AAACS,OAAA,CAAA/C,kBAAA,GAAAA,kBAAA"}
|
|
@@ -1,28 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.uncapitalize = uncapitalize;
|
|
8
7
|
exports.uncapitalizeKeys = uncapitalizeKeys;
|
|
9
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
11
8
|
function uncapitalize(str) {
|
|
12
9
|
return typeof str === 'string' ? str.charAt(0).toLowerCase() + str.slice(1) : str;
|
|
13
10
|
}
|
|
14
11
|
function uncapitalizeKeys(object) {
|
|
15
12
|
if (Array.isArray(object)) {
|
|
16
|
-
return object.map(
|
|
17
|
-
return uncapitalizeKeys(element);
|
|
18
|
-
});
|
|
13
|
+
return object.map(element => uncapitalizeKeys(element));
|
|
19
14
|
}
|
|
20
|
-
if (object &&
|
|
21
|
-
|
|
22
|
-
for (
|
|
23
|
-
var _Object$entries$_i = (0, _slicedToArray2.default)(_Object$entries[_i], 2),
|
|
24
|
-
key = _Object$entries$_i[0],
|
|
25
|
-
value = _Object$entries$_i[1];
|
|
15
|
+
if (object && typeof object === 'object') {
|
|
16
|
+
const newObject = {};
|
|
17
|
+
for (const [key, value] of Object.entries(object)) {
|
|
26
18
|
newObject[uncapitalize(key)] = uncapitalizeKeys(value);
|
|
27
19
|
}
|
|
28
20
|
return newObject;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uncapitalize.js","names":["uncapitalize","str","charAt","toLowerCase","slice","uncapitalizeKeys","object","Array","isArray","map","element","
|
|
1
|
+
{"version":3,"file":"uncapitalize.js","names":["uncapitalize","str","charAt","toLowerCase","slice","uncapitalizeKeys","object","Array","isArray","map","element","newObject","key","value","Object","entries"],"sources":["../../../../src/lib/xml-utils/uncapitalize.ts"],"sourcesContent":["// loaders.gl, MIT license\n\n/**\n * Uncapitalize first letter of a string\n * @param str\n * @returns\n */\nexport function uncapitalize(str: string): string {\n return typeof str === 'string' ? str.charAt(0).toLowerCase() + str.slice(1) : str;\n}\n\n/**\n * Recursively uncapitalize all keys in a nested object\n * @param object\n * @returns\n */\nexport function uncapitalizeKeys(object: any): any {\n if (Array.isArray(object)) {\n return object.map((element) => uncapitalizeKeys(element));\n }\n\n if (object && typeof object === 'object') {\n const newObject = {};\n for (const [key, value] of Object.entries(object)) {\n newObject[uncapitalize(key)] = uncapitalizeKeys(value);\n }\n return newObject;\n }\n\n return object;\n}\n"],"mappings":";;;;;;;AAOO,SAASA,YAAYA,CAACC,GAAW,EAAU;EAChD,OAAO,OAAOA,GAAG,KAAK,QAAQ,GAAGA,GAAG,CAACC,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC,GAAGF,GAAG,CAACG,KAAK,CAAC,CAAC,CAAC,GAAGH,GAAG;AACnF;AAOO,SAASI,gBAAgBA,CAACC,MAAW,EAAO;EACjD,IAAIC,KAAK,CAACC,OAAO,CAACF,MAAM,CAAC,EAAE;IACzB,OAAOA,MAAM,CAACG,GAAG,CAAEC,OAAO,IAAKL,gBAAgB,CAACK,OAAO,CAAC,CAAC;EAC3D;EAEA,IAAIJ,MAAM,IAAI,OAAOA,MAAM,KAAK,QAAQ,EAAE;IACxC,MAAMK,SAAS,GAAG,CAAC,CAAC;IACpB,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACT,MAAM,CAAC,EAAE;MACjDK,SAAS,CAACX,YAAY,CAACY,GAAG,CAAC,CAAC,GAAGP,gBAAgB,CAACQ,KAAK,CAAC;IACxD;IACA,OAAOF,SAAS;EAClB;EAEA,OAAOL,MAAM;AACf"}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.convertXMLFieldToArrayInPlace = convertXMLFieldToArrayInPlace;
|
|
8
7
|
exports.convertXMLValueToArray = convertXMLValueToArray;
|
|
9
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
10
8
|
function convertXMLValueToArray(xmlValue) {
|
|
11
9
|
if (Array.isArray(xmlValue)) {
|
|
12
10
|
return xmlValue;
|
|
13
11
|
}
|
|
14
|
-
if (xmlValue &&
|
|
12
|
+
if (xmlValue && typeof xmlValue === 'object' && xmlValue['0']) {}
|
|
15
13
|
if (xmlValue) {
|
|
16
14
|
return [xmlValue];
|
|
17
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xml-utils.js","names":["convertXMLValueToArray","xmlValue","Array","isArray","
|
|
1
|
+
{"version":3,"file":"xml-utils.js","names":["convertXMLValueToArray","xmlValue","Array","isArray","convertXMLFieldToArrayInPlace","xml","key"],"sources":["../../../../src/lib/xml-utils/xml-utils.ts"],"sourcesContent":["// TODO - these utilities could be moved to the XML parser.\n// uncapitalizeKeys could be an XMLLoader option\n\n/**\n * Extracts a value or array and always return an array\n * Useful since XML parses to object instead of array when only a single value is provided\n */\nexport function convertXMLValueToArray(xmlValue: unknown): unknown[] {\n if (Array.isArray(xmlValue)) {\n return xmlValue;\n }\n if (xmlValue && typeof xmlValue === 'object' && xmlValue['0']) {\n // Error this is an objectified array\n }\n if (xmlValue) {\n return [xmlValue];\n }\n return [];\n}\n\n/**\n * Mutates a field in place, converting it to array\n * Useful since XML parses to object instead of array when only a single value is provided\n */\nexport function convertXMLFieldToArrayInPlace(xml: any, key: string): void {\n xml[key] = convertXMLValueToArray(xml[key]);\n}\n"],"mappings":";;;;;;;AAOO,SAASA,sBAAsBA,CAACC,QAAiB,EAAa;EACnE,IAAIC,KAAK,CAACC,OAAO,CAACF,QAAQ,CAAC,EAAE;IAC3B,OAAOA,QAAQ;EACjB;EACA,IAAIA,QAAQ,IAAI,OAAOA,QAAQ,KAAK,QAAQ,IAAIA,QAAQ,CAAC,GAAG,CAAC,EAAE,CAE/D;EACA,IAAIA,QAAQ,EAAE;IACZ,OAAO,CAACA,QAAQ,CAAC;EACnB;EACA,OAAO,EAAE;AACX;AAMO,SAASG,6BAA6BA,CAACC,GAAQ,EAAEC,GAAW,EAAQ;EACzED,GAAG,CAACC,GAAG,CAAC,GAAGN,sBAAsB,CAACK,GAAG,CAACC,GAAG,CAAC,CAAC;AAC7C"}
|