@loaders.gl/xml 4.0.0-alpha.23 → 4.0.0-alpha.25
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/dist.min.js +1 -1
- package/dist/es5/xml-loader.js +1 -1
- package/dist/esm/xml-loader.js +1 -1
- package/package.json +4 -4
- package/dist/bundle.js +0 -5
- package/dist/html-loader.js +0 -40
- package/dist/index.js +0 -18
- package/dist/lib/parsers/parse-xml.js +0 -60
- package/dist/lib/parsers/streaming-xml-parser.js +0 -98
- package/dist/lib/xml-utils/uncapitalize.js +0 -32
- package/dist/lib/xml-utils/xml-utils.js +0 -30
- package/dist/sax-ts/sax.js +0 -1440
- package/dist/xml-loader.js +0 -38
package/dist/dist.min.js
CHANGED
|
@@ -3096,7 +3096,7 @@ Actual: ${this.attribValue}`);
|
|
|
3096
3096
|
function mergeOptionsRecursively(baseOptions, newOptions) {
|
|
3097
3097
|
const options = { ...baseOptions };
|
|
3098
3098
|
for (const [key, newValue] of Object.entries(newOptions)) {
|
|
3099
|
-
if (newValue && typeof newValue === "object") {
|
|
3099
|
+
if (newValue && typeof newValue === "object" && !Array.isArray(newValue)) {
|
|
3100
3100
|
options[key] = mergeOptionsRecursively(options[key] || {}, newOptions[key]);
|
|
3101
3101
|
} else {
|
|
3102
3102
|
options[key] = newOptions[key];
|
package/dist/es5/xml-loader.js
CHANGED
|
@@ -11,7 +11,7 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
|
|
|
11
11
|
var _parseXml = require("./lib/parsers/parse-xml");
|
|
12
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
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
|
-
var VERSION = typeof "4.0.0-alpha.
|
|
14
|
+
var VERSION = typeof "4.0.0-alpha.25" !== 'undefined' ? "4.0.0-alpha.25" : 'latest';
|
|
15
15
|
var XMLLoader = {
|
|
16
16
|
name: 'XML',
|
|
17
17
|
id: 'xml',
|
package/dist/esm/xml-loader.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseXMLSync } from './lib/parsers/parse-xml';
|
|
2
|
-
const VERSION = typeof "4.0.0-alpha.
|
|
2
|
+
const VERSION = typeof "4.0.0-alpha.25" !== 'undefined' ? "4.0.0-alpha.25" : 'latest';
|
|
3
3
|
export const XMLLoader = {
|
|
4
4
|
name: 'XML',
|
|
5
5
|
id: 'xml',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/xml",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.25",
|
|
4
4
|
"description": "Framework-independent loaders for the XML (eXtensible Markup Language) format",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@babel/runtime": "^7.3.1",
|
|
36
|
-
"@loaders.gl/loader-utils": "4.0.0-alpha.
|
|
37
|
-
"@loaders.gl/schema": "4.0.0-alpha.
|
|
36
|
+
"@loaders.gl/loader-utils": "4.0.0-alpha.25",
|
|
37
|
+
"@loaders.gl/schema": "4.0.0-alpha.25",
|
|
38
38
|
"fast-xml-parser": "^4.2.5"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "40135f391b869388dbbcd615bbe51178d0c370be"
|
|
41
41
|
}
|
package/dist/bundle.js
DELETED
package/dist/html-loader.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.HTMLLoader = void 0;
|
|
5
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
6
|
-
const xml_loader_1 = require("./xml-loader");
|
|
7
|
-
/**
|
|
8
|
-
* Loader for HTML files
|
|
9
|
-
* Essentially a copy of the XMLLoader with different mime types, file extensions and content tests.
|
|
10
|
-
* This split enables applications can control whether they want HTML responses to be parsed by the XML loader or not.
|
|
11
|
-
* This loader does not have any additional understanding of the structure of HTML or the document.
|
|
12
|
-
*/
|
|
13
|
-
exports.HTMLLoader = {
|
|
14
|
-
...xml_loader_1.XMLLoader,
|
|
15
|
-
name: 'HTML',
|
|
16
|
-
id: 'html',
|
|
17
|
-
extensions: ['html', 'htm'],
|
|
18
|
-
mimeTypes: ['text/html'],
|
|
19
|
-
testText: testHTMLFile,
|
|
20
|
-
parse: async (arrayBuffer, options) => parseTextSync(new TextDecoder().decode(arrayBuffer), options),
|
|
21
|
-
parseTextSync: (text, options) => parseTextSync(text, options)
|
|
22
|
-
};
|
|
23
|
-
function testHTMLFile(text) {
|
|
24
|
-
// TODO - There could be space first.
|
|
25
|
-
return text.startsWith('<html');
|
|
26
|
-
}
|
|
27
|
-
function parseTextSync(text, options) {
|
|
28
|
-
// fast-xml-parser can recognize HTML entities
|
|
29
|
-
// https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#htmlentities
|
|
30
|
-
// https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/5.Entities.md
|
|
31
|
-
options = (0, loader_utils_1.mergeLoaderOptions)(options, {
|
|
32
|
-
xml: {
|
|
33
|
-
_parser: 'fast-xml-parser',
|
|
34
|
-
_fastXML: {
|
|
35
|
-
htmlEntities: true
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
return xml_loader_1.XMLLoader.parseTextSync?.(text, options);
|
|
40
|
-
}
|
package/dist/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports._uncapitalizeKeys = exports._uncapitalize = exports.convertXMLFieldToArrayInPlace = exports.convertXMLValueToArray = exports.SAXParser = exports.HTMLLoader = exports.XMLLoader = void 0;
|
|
5
|
-
var xml_loader_1 = require("./xml-loader");
|
|
6
|
-
Object.defineProperty(exports, "XMLLoader", { enumerable: true, get: function () { return xml_loader_1.XMLLoader; } });
|
|
7
|
-
var html_loader_1 = require("./html-loader");
|
|
8
|
-
Object.defineProperty(exports, "HTMLLoader", { enumerable: true, get: function () { return html_loader_1.HTMLLoader; } });
|
|
9
|
-
var sax_1 = require("./sax-ts/sax");
|
|
10
|
-
Object.defineProperty(exports, "SAXParser", { enumerable: true, get: function () { return sax_1.SAXParser; } });
|
|
11
|
-
// Utilities
|
|
12
|
-
var xml_utils_1 = require("./lib/xml-utils/xml-utils");
|
|
13
|
-
Object.defineProperty(exports, "convertXMLValueToArray", { enumerable: true, get: function () { return xml_utils_1.convertXMLValueToArray; } });
|
|
14
|
-
Object.defineProperty(exports, "convertXMLFieldToArrayInPlace", { enumerable: true, get: function () { return xml_utils_1.convertXMLFieldToArrayInPlace; } });
|
|
15
|
-
// Experimental
|
|
16
|
-
var uncapitalize_1 = require("./lib/xml-utils/uncapitalize");
|
|
17
|
-
Object.defineProperty(exports, "_uncapitalize", { enumerable: true, get: function () { return uncapitalize_1.uncapitalize; } });
|
|
18
|
-
Object.defineProperty(exports, "_uncapitalizeKeys", { enumerable: true, get: function () { return uncapitalize_1.uncapitalizeKeys; } });
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.parseXMLInBatches = exports.fastParseXML = exports.parseXMLSync = void 0;
|
|
5
|
-
const streaming_xml_parser_1 = require("./streaming-xml-parser");
|
|
6
|
-
const uncapitalize_1 = require("../xml-utils/uncapitalize");
|
|
7
|
-
const fast_xml_parser_1 = require("fast-xml-parser");
|
|
8
|
-
function parseXMLSync(text, options) {
|
|
9
|
-
if (options?._parser && options._parser !== 'fast-xml-parser') {
|
|
10
|
-
throw new Error(options?._parser);
|
|
11
|
-
}
|
|
12
|
-
const fastXMLOptions = {
|
|
13
|
-
// Default FastXML options
|
|
14
|
-
// https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#allowbooleanattributes
|
|
15
|
-
allowBooleanAttributes: true,
|
|
16
|
-
// https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#ignoredeclaration
|
|
17
|
-
ignoreDeclaration: true,
|
|
18
|
-
// https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#removensprefix
|
|
19
|
-
removeNSPrefix: options?.removeNSPrefix,
|
|
20
|
-
// https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#textnodename
|
|
21
|
-
textNodeName: options?.textNodeName,
|
|
22
|
-
// Let's application specify keys that are always arrays
|
|
23
|
-
isArray: (name, jpath, isLeafNode, isAttribute) => {
|
|
24
|
-
const array = Boolean(options?.arrayPaths?.some((path) => jpath === path));
|
|
25
|
-
return array;
|
|
26
|
-
},
|
|
27
|
-
// Application overrides
|
|
28
|
-
...options?._fastXML
|
|
29
|
-
};
|
|
30
|
-
const xml = fastParseXML(text, fastXMLOptions);
|
|
31
|
-
// Note - could be done with FastXML tag processing
|
|
32
|
-
return options?.uncapitalizeKeys ? (0, uncapitalize_1.uncapitalizeKeys)(xml) : xml;
|
|
33
|
-
}
|
|
34
|
-
exports.parseXMLSync = parseXMLSync;
|
|
35
|
-
function fastParseXML(text, options) {
|
|
36
|
-
const parser = new fast_xml_parser_1.XMLParser({
|
|
37
|
-
ignoreAttributes: false,
|
|
38
|
-
attributeNamePrefix: '',
|
|
39
|
-
...options
|
|
40
|
-
});
|
|
41
|
-
const parsedXML = parser.parse(text);
|
|
42
|
-
return parsedXML;
|
|
43
|
-
}
|
|
44
|
-
exports.fastParseXML = fastParseXML;
|
|
45
|
-
/**
|
|
46
|
-
* @todo Build a streaming XML parser based on sax-js
|
|
47
|
-
* @param text
|
|
48
|
-
* @param options
|
|
49
|
-
* @returns
|
|
50
|
-
*/
|
|
51
|
-
function parseXMLInBatches(text, options = {}) {
|
|
52
|
-
const parser = new streaming_xml_parser_1.StreamingXMLParser({
|
|
53
|
-
...options,
|
|
54
|
-
strict: true
|
|
55
|
-
});
|
|
56
|
-
parser.write(text);
|
|
57
|
-
parser.close();
|
|
58
|
-
return parser.result;
|
|
59
|
-
}
|
|
60
|
-
exports.parseXMLInBatches = parseXMLInBatches;
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// @ts-nocheck
|
|
3
|
-
/* eslint-disable */
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.StreamingXMLParser = void 0;
|
|
6
|
-
const sax_1 = require("../../sax-ts/sax");
|
|
7
|
-
/**
|
|
8
|
-
* StreamingXMLParser builds a JSON object using the events emitted by the SAX parser
|
|
9
|
-
*/
|
|
10
|
-
class StreamingXMLParser {
|
|
11
|
-
// jsonpath: JSONPath = new JSONPath();
|
|
12
|
-
constructor(options) {
|
|
13
|
-
this.result = undefined;
|
|
14
|
-
this.previousStates = [];
|
|
15
|
-
this.currentState = Object.freeze({ container: [], key: null });
|
|
16
|
-
this.reset();
|
|
17
|
-
this.parser = new sax_1.SAXParser({
|
|
18
|
-
onready: () => {
|
|
19
|
-
this.previousStates.length = 0;
|
|
20
|
-
this.currentState.container.length = 0;
|
|
21
|
-
},
|
|
22
|
-
onopentag: ({ name, attributes, isSelfClosing }) => {
|
|
23
|
-
this._openObject({});
|
|
24
|
-
if (typeof name !== 'undefined') {
|
|
25
|
-
this.parser.emit('onkey', name);
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
onkey: (name) => {
|
|
29
|
-
this.currentState.key = name;
|
|
30
|
-
},
|
|
31
|
-
onclosetag: () => {
|
|
32
|
-
this._closeObject();
|
|
33
|
-
},
|
|
34
|
-
onopenarray: () => {
|
|
35
|
-
this._openArray();
|
|
36
|
-
},
|
|
37
|
-
onclosearray: () => {
|
|
38
|
-
this._closeArray();
|
|
39
|
-
},
|
|
40
|
-
ontext: (value) => {
|
|
41
|
-
this._pushOrSet(value);
|
|
42
|
-
},
|
|
43
|
-
onerror: (error) => {
|
|
44
|
-
throw error;
|
|
45
|
-
},
|
|
46
|
-
onend: () => {
|
|
47
|
-
this.result = this.currentState.container.pop();
|
|
48
|
-
},
|
|
49
|
-
...options
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
reset() {
|
|
53
|
-
this.result = undefined;
|
|
54
|
-
this.previousStates = [];
|
|
55
|
-
this.currentState = Object.freeze({ container: [], key: null });
|
|
56
|
-
}
|
|
57
|
-
write(chunk) {
|
|
58
|
-
this.parser.write(chunk);
|
|
59
|
-
}
|
|
60
|
-
close() {
|
|
61
|
-
this.parser.close();
|
|
62
|
-
}
|
|
63
|
-
// PRIVATE METHODS
|
|
64
|
-
_pushOrSet(value) {
|
|
65
|
-
const { container, key } = this.currentState;
|
|
66
|
-
if (key !== null) {
|
|
67
|
-
container[key] = value;
|
|
68
|
-
this.currentState.key = null;
|
|
69
|
-
}
|
|
70
|
-
else if (Array.isArray(container)) {
|
|
71
|
-
container.push(value);
|
|
72
|
-
}
|
|
73
|
-
else if (container) {
|
|
74
|
-
// debugger
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
_openArray(newContainer = []) {
|
|
78
|
-
// this.jsonpath.push(null);
|
|
79
|
-
this._pushOrSet(newContainer);
|
|
80
|
-
this.previousStates.push(this.currentState);
|
|
81
|
-
this.currentState = { container: newContainer, isArray: true, key: null };
|
|
82
|
-
}
|
|
83
|
-
_closeArray() {
|
|
84
|
-
// this.jsonpath.pop();
|
|
85
|
-
this.currentState = this.previousStates.pop();
|
|
86
|
-
}
|
|
87
|
-
_openObject(newContainer = {}) {
|
|
88
|
-
// this.jsonpath.push(null);
|
|
89
|
-
this._pushOrSet(newContainer);
|
|
90
|
-
this.previousStates.push(this.currentState);
|
|
91
|
-
this.currentState = { container: newContainer, isArray: false, key: null };
|
|
92
|
-
}
|
|
93
|
-
_closeObject() {
|
|
94
|
-
// this.jsonpath.pop();
|
|
95
|
-
this.currentState = this.previousStates.pop();
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
exports.StreamingXMLParser = StreamingXMLParser;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.uncapitalizeKeys = exports.uncapitalize = void 0;
|
|
5
|
-
/**
|
|
6
|
-
* Uncapitalize first letter of a string
|
|
7
|
-
* @param str
|
|
8
|
-
* @returns
|
|
9
|
-
*/
|
|
10
|
-
function uncapitalize(str) {
|
|
11
|
-
return typeof str === 'string' ? str.charAt(0).toLowerCase() + str.slice(1) : str;
|
|
12
|
-
}
|
|
13
|
-
exports.uncapitalize = uncapitalize;
|
|
14
|
-
/**
|
|
15
|
-
* Recursively uncapitalize all keys in a nested object
|
|
16
|
-
* @param object
|
|
17
|
-
* @returns
|
|
18
|
-
*/
|
|
19
|
-
function uncapitalizeKeys(object) {
|
|
20
|
-
if (Array.isArray(object)) {
|
|
21
|
-
return object.map((element) => uncapitalizeKeys(element));
|
|
22
|
-
}
|
|
23
|
-
if (object && typeof object === 'object') {
|
|
24
|
-
const newObject = {};
|
|
25
|
-
for (const [key, value] of Object.entries(object)) {
|
|
26
|
-
newObject[uncapitalize(key)] = uncapitalizeKeys(value);
|
|
27
|
-
}
|
|
28
|
-
return newObject;
|
|
29
|
-
}
|
|
30
|
-
return object;
|
|
31
|
-
}
|
|
32
|
-
exports.uncapitalizeKeys = uncapitalizeKeys;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// TODO - these utilities could be moved to the XML parser.
|
|
3
|
-
// uncapitalizeKeys could be an XMLLoader option
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.convertXMLFieldToArrayInPlace = exports.convertXMLValueToArray = void 0;
|
|
6
|
-
/**
|
|
7
|
-
* Extracts a value or array and always return an array
|
|
8
|
-
* Useful since XML parses to object instead of array when only a single value is provided
|
|
9
|
-
*/
|
|
10
|
-
function convertXMLValueToArray(xmlValue) {
|
|
11
|
-
if (Array.isArray(xmlValue)) {
|
|
12
|
-
return xmlValue;
|
|
13
|
-
}
|
|
14
|
-
if (xmlValue && typeof xmlValue === 'object' && xmlValue['0']) {
|
|
15
|
-
// Error this is an objectified array
|
|
16
|
-
}
|
|
17
|
-
if (xmlValue) {
|
|
18
|
-
return [xmlValue];
|
|
19
|
-
}
|
|
20
|
-
return [];
|
|
21
|
-
}
|
|
22
|
-
exports.convertXMLValueToArray = convertXMLValueToArray;
|
|
23
|
-
/**
|
|
24
|
-
* Mutates a field in place, converting it to array
|
|
25
|
-
* Useful since XML parses to object instead of array when only a single value is provided
|
|
26
|
-
*/
|
|
27
|
-
function convertXMLFieldToArrayInPlace(xml, key) {
|
|
28
|
-
xml[key] = convertXMLValueToArray(xml[key]);
|
|
29
|
-
}
|
|
30
|
-
exports.convertXMLFieldToArrayInPlace = convertXMLFieldToArrayInPlace;
|