@loaders.gl/xml 3.4.0-alpha.3 → 4.0.0-alpha.6

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.
@@ -1 +1 @@
1
- {"version":3,"file":"parse-xml.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-xml.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAEhD,uDAAuD;AACvD,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEvD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,GAAG,GAAG,CAU7E;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,KAAK,GAAG,GAAG,CAUjE"}
1
+ {"version":3,"file":"parse-xml.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-xml.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,kBAAkB,CAAC;AAIvD,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAEhD,MAAM,MAAM,eAAe,GAAG;IAC5B,iEAAiE;IACjE,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IAGtB,OAAO,CAAC,EAAE,iBAAiB,GAAG,KAAK,CAAC;IACpC,uFAAuF;IACvF,QAAQ,CAAC,EAAE,oBAAoB,CAAC;IAChC,2FAA2F;IAC3F,IAAI,CAAC,EAAE,gBAAgB,CAAC;CACzB,CAAC;AAEF,uDAAuD;AACvD,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEvD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,GAAG,CAgCzE;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,GAAG,GAAG,CAU7E;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,KAAK,GAAG,GAAG,CAUjE"}
@@ -1,9 +1,37 @@
1
1
  "use strict";
2
2
  // loaders.gl, MIT license
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.parseXMLInBatches = exports.fastParseXML = void 0;
4
+ exports.parseXMLInBatches = exports.fastParseXML = exports.parseXMLSync = void 0;
5
5
  const streaming_xml_parser_1 = require("./streaming-xml-parser");
6
+ const uncapitalize_1 = require("../xml-utils/uncapitalize");
6
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;
7
35
  function fastParseXML(text, options) {
8
36
  const parser = new fast_xml_parser_1.XMLParser({
9
37
  ignoreAttributes: false,
@@ -1,45 +1,10 @@
1
1
  import type { LoaderWithParser, LoaderOptions } from '@loaders.gl/loader-utils';
2
- import type { SAXParserOptions } from './sax-ts/sax';
3
- import { FastXMLParserOptions } from './lib/parsers/parse-xml';
2
+ import type { ParseXMLOptions } from './lib/parsers/parse-xml';
4
3
  export type XMLLoaderOptions = LoaderOptions & {
5
- xml?: {
6
- parser?: 'fast-xml-parser' | string;
7
- /** XML is typically PascalCase, JavaScript prefects camelCase */
8
- uncapitalizeKeys?: boolean;
9
- removeNSPrefix?: boolean;
10
- textNodeName?: string;
11
- arrayPaths?: string[];
12
- };
13
- /** @deprecated Experimental, passes options to fast-xml-parser, IF it is being used */
14
- _fastXML?: FastXMLParserOptions;
15
- /** @deprecated Experimental, passes options to the SAX XML parser, IF it is being used. */
16
- _sax?: SAXParserOptions;
4
+ xml?: ParseXMLOptions;
17
5
  };
18
6
  /**
19
7
  * Loader for XML files
20
8
  */
21
- export declare const XMLLoader: {
22
- name: string;
23
- id: string;
24
- module: string;
25
- version: any;
26
- worker: boolean;
27
- extensions: string[];
28
- mimeTypes: string[];
29
- testText: typeof testXMLFile;
30
- options: {
31
- xml: {
32
- parser: string;
33
- uncapitalizeKeys: boolean;
34
- removeNSPrefix: boolean;
35
- textNodeName: string;
36
- arrayPaths: never[];
37
- };
38
- };
39
- parse: (arrayBuffer: ArrayBuffer, options?: XMLLoaderOptions) => Promise<any>;
40
- parseTextSync: (text: string, options?: XMLLoaderOptions) => any;
41
- };
42
- declare function testXMLFile(text: string): boolean;
43
- export declare const _typecheckXMLLoader: LoaderWithParser;
44
- export {};
9
+ export declare const XMLLoader: LoaderWithParser<any, never, XMLLoaderOptions>;
45
10
  //# sourceMappingURL=xml-loader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"xml-loader.d.ts","sourceRoot":"","sources":["../src/xml-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAC9E,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AACnD,OAAO,EAAe,oBAAoB,EAAC,MAAM,yBAAyB,CAAC;AAO3E,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC7C,GAAG,CAAC,EAAE;QAEJ,MAAM,CAAC,EAAE,iBAAiB,GAAG,MAAM,CAAC;QACpC,iEAAiE;QACjE,gBAAgB,CAAC,EAAE,OAAO,CAAC;QAC3B,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;KACvB,CAAC;IACF,uFAAuF;IACvF,QAAQ,CAAC,EAAE,oBAAoB,CAAC;IAChC,2FAA2F;IAC3F,IAAI,CAAC,EAAE,gBAAgB,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;yBAkBO,WAAW,YAAY,gBAAgB;0BAE5C,MAAM,YAAY,gBAAgB;CACzD,CAAC;AAEF,iBAAS,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAG1C;AAwCD,eAAO,MAAM,mBAAmB,EAAE,gBAA4B,CAAC"}
1
+ {"version":3,"file":"xml-loader.d.ts","sourceRoot":"","sources":["../src/xml-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAC9E,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,yBAAyB,CAAC;AAO7D,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC7C,GAAG,CAAC,EAAE,eAAe,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,gBAAgB,CAAC,GAAG,EAAE,KAAK,EAAE,gBAAgB,CAyBpE,CAAC"}
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._typecheckXMLLoader = exports.XMLLoader = void 0;
3
+ exports.XMLLoader = void 0;
4
4
  const parse_xml_1 = require("./lib/parsers/parse-xml");
5
- const uncapitalize_1 = require("./lib/xml-utils/uncapitalize");
6
5
  // __VERSION__ is injected by babel-plugin-version-inline
7
6
  // @ts-ignore TS2304: Cannot find name '__VERSION__'.
8
7
  const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
@@ -20,47 +19,20 @@ exports.XMLLoader = {
20
19
  testText: testXMLFile,
21
20
  options: {
22
21
  xml: {
23
- parser: 'fast-xml-parser',
22
+ _parser: 'fast-xml-parser',
24
23
  uncapitalizeKeys: false,
25
24
  removeNSPrefix: false,
26
25
  textNodeName: 'value',
27
26
  arrayPaths: []
28
27
  }
29
28
  },
30
- parse: async (arrayBuffer, options) => parseTextSync(new TextDecoder().decode(arrayBuffer), options),
31
- parseTextSync: (text, options) => parseTextSync(text, options)
29
+ parse: async (arrayBuffer, options) => (0, parse_xml_1.parseXMLSync)(new TextDecoder().decode(arrayBuffer), {
30
+ ...exports.XMLLoader.options.xml,
31
+ ...options?.xml
32
+ }),
33
+ parseTextSync: (text, options) => (0, parse_xml_1.parseXMLSync)(text, { ...exports.XMLLoader.options.xml, ...options?.xml })
32
34
  };
33
35
  function testXMLFile(text) {
34
36
  // TODO - There could be space first.
35
37
  return text.startsWith('<?xml');
36
38
  }
37
- function parseTextSync(text, options) {
38
- const xmlOptions = { ...exports.XMLLoader.options.xml, ...options?.xml };
39
- switch (xmlOptions.parser) {
40
- case 'fast-xml-parser':
41
- const fastXMLOptions = {
42
- // Default FastXML options
43
- // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#allowbooleanattributes
44
- allowBooleanAttributes: true,
45
- // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#ignoredeclaration
46
- ignoreDeclaration: true,
47
- // XMLLoader Options: Map to FastXMLOptions
48
- // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#removensprefix
49
- removeNSPrefix: xmlOptions.removeNSPrefix,
50
- // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#textnodename
51
- textNodeName: xmlOptions.textNodeName,
52
- isArray: (name, jpath, isLeafNode, isAttribute) => {
53
- const array = Boolean(xmlOptions?.arrayPaths?.some((path) => jpath === path));
54
- return array;
55
- },
56
- // Application overrides
57
- ...options?._fastXML
58
- };
59
- const xml = (0, parse_xml_1.fastParseXML)(text, fastXMLOptions);
60
- // Note - could be done with FastXML tag processing
61
- return xmlOptions.uncapitalizeKeys ? (0, uncapitalize_1.uncapitalizeKeys)(xml) : xml;
62
- default:
63
- throw new Error(options?.xml?.parser);
64
- }
65
- }
66
- exports._typecheckXMLLoader = exports.XMLLoader;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/xml",
3
- "version": "3.4.0-alpha.3",
3
+ "version": "4.0.0-alpha.6",
4
4
  "description": "Framework-independent loaders for the XML (eXtensible Markup Language) format",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -33,12 +33,12 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@babel/runtime": "^7.3.1",
36
- "@loaders.gl/loader-utils": "3.4.0-alpha.3",
37
- "@loaders.gl/schema": "3.4.0-alpha.3",
36
+ "@loaders.gl/loader-utils": "4.0.0-alpha.6",
37
+ "@loaders.gl/schema": "4.0.0-alpha.6",
38
38
  "fast-xml-parser": "^4.1.3"
39
39
  },
40
40
  "devDependencies": {
41
41
  "xmldom": "0.6.0"
42
42
  },
43
- "gitHead": "a954528dd1d78a1f128d8f6b07e4baeb7a296924"
43
+ "gitHead": "acc1985050dfaa0f1f0c066f8da5bce7454a046c"
44
44
  }
@@ -35,12 +35,12 @@ function parseTextSync(text: string, options?: XMLLoaderOptions): any {
35
35
  // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/5.Entities.md
36
36
  options = mergeLoaderOptions(options, {
37
37
  xml: {
38
- parser: 'fast-xml-parser'
39
- },
40
- _fastXML: {
41
- htmlEntities: true
38
+ _parser: 'fast-xml-parser',
39
+ _fastXML: {
40
+ htmlEntities: true
41
+ }
42
42
  }
43
43
  });
44
44
 
45
- return XMLLoader.parseTextSync(text, options);
45
+ return XMLLoader.parseTextSync?.(text, options);
46
46
  }
@@ -1,13 +1,64 @@
1
1
  // loaders.gl, MIT license
2
2
 
3
+ import type {SAXParserOptions} from '../../sax-ts/sax';
3
4
  import {StreamingXMLParser} from './streaming-xml-parser';
5
+ import {uncapitalizeKeys} from '../xml-utils/uncapitalize';
4
6
  import {XMLParser as FastXMLParser} from 'fast-xml-parser';
5
7
  import type {X2jOptions} from 'fast-xml-parser';
6
8
 
9
+ export type ParseXMLOptions = {
10
+ /** XML is typically PascalCase, JavaScript prefects camelCase */
11
+ uncapitalizeKeys?: boolean;
12
+ removeNSPrefix?: boolean;
13
+ textNodeName?: string;
14
+ arrayPaths?: string[];
15
+
16
+ // NOTE: Only fast-xml-parser is implemented
17
+ _parser?: 'fast-xml-parser' | 'sax';
18
+ /** @deprecated Experimental, passes options to fast-xml-parser, IF it is being used */
19
+ _fastXML?: _FastParseXMLOptions;
20
+ /** @deprecated Experimental, passes options to the SAX XML parser, IF it is being used. */
21
+ _sax?: SAXParserOptions;
22
+ };
23
+
7
24
  /** Type for passing through fast-xml-parser options */
8
- export type FastXMLParserOptions = Partial<X2jOptions>;
25
+ export type _FastParseXMLOptions = Partial<X2jOptions>;
26
+
27
+ export function parseXMLSync(text: string, options?: ParseXMLOptions): any {
28
+ if (options?._parser && options._parser !== 'fast-xml-parser') {
29
+ throw new Error(options?._parser);
30
+ }
31
+
32
+ const fastXMLOptions: _FastParseXMLOptions = {
33
+ // Default FastXML options
34
+ // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#allowbooleanattributes
35
+ allowBooleanAttributes: true,
36
+ // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#ignoredeclaration
37
+ ignoreDeclaration: true,
38
+
39
+ // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#removensprefix
40
+ removeNSPrefix: options?.removeNSPrefix,
41
+
42
+ // https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/docs/v4/2.XMLparseOptions.md#textnodename
43
+ textNodeName: options?.textNodeName,
44
+
45
+ // Let's application specify keys that are always arrays
46
+ isArray: (name: string, jpath: string, isLeafNode: boolean, isAttribute: boolean) => {
47
+ const array = Boolean(options?.arrayPaths?.some((path) => jpath === path));
48
+ return array;
49
+ },
50
+
51
+ // Application overrides
52
+ ...options?._fastXML
53
+ };
54
+
55
+ const xml = fastParseXML(text, fastXMLOptions);
56
+
57
+ // Note - could be done with FastXML tag processing
58
+ return options?.uncapitalizeKeys ? uncapitalizeKeys(xml) : xml;
59
+ }
9
60
 
10
- export function fastParseXML(text: string, options: FastXMLParserOptions): any {
61
+ export function fastParseXML(text: string, options: _FastParseXMLOptions): any {
11
62
  const parser = new FastXMLParser({
12
63
  ignoreAttributes: false,
13
64
  attributeNamePrefix: '',
package/src/xml-loader.ts CHANGED
@@ -1,32 +1,19 @@
1
1
  import type {LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';
2
- import type {SAXParserOptions} from './sax-ts/sax';
3
- import {fastParseXML, FastXMLParserOptions} from './lib/parsers/parse-xml';
4
- import {uncapitalizeKeys} from './lib/xml-utils/uncapitalize';
2
+ import type {ParseXMLOptions} from './lib/parsers/parse-xml';
3
+ import {parseXMLSync} from './lib/parsers/parse-xml';
5
4
 
6
5
  // __VERSION__ is injected by babel-plugin-version-inline
7
6
  // @ts-ignore TS2304: Cannot find name '__VERSION__'.
8
7
  const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
9
8
 
10
9
  export type XMLLoaderOptions = LoaderOptions & {
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;
10
+ xml?: ParseXMLOptions;
24
11
  };
25
12
 
26
13
  /**
27
14
  * Loader for XML files
28
15
  */
29
- export const XMLLoader = {
16
+ export const XMLLoader: LoaderWithParser<any, never, XMLLoaderOptions> = {
30
17
  name: 'XML',
31
18
  id: 'xml',
32
19
  module: 'xml',
@@ -37,7 +24,7 @@ export const XMLLoader = {
37
24
  testText: testXMLFile,
38
25
  options: {
39
26
  xml: {
40
- parser: 'fast-xml-parser',
27
+ _parser: 'fast-xml-parser',
41
28
  uncapitalizeKeys: false,
42
29
  removeNSPrefix: false,
43
30
  textNodeName: 'value',
@@ -45,51 +32,15 @@ export const XMLLoader = {
45
32
  }
46
33
  },
47
34
  parse: async (arrayBuffer: ArrayBuffer, options?: XMLLoaderOptions) =>
48
- parseTextSync(new TextDecoder().decode(arrayBuffer), options),
49
- parseTextSync: (text: string, options?: XMLLoaderOptions) => parseTextSync(text, options)
35
+ parseXMLSync(new TextDecoder().decode(arrayBuffer), {
36
+ ...XMLLoader.options.xml,
37
+ ...options?.xml
38
+ }),
39
+ parseTextSync: (text: string, options?: XMLLoaderOptions) =>
40
+ parseXMLSync(text, {...XMLLoader.options.xml, ...options?.xml})
50
41
  };
51
42
 
52
43
  function testXMLFile(text: string): boolean {
53
44
  // TODO - There could be space first.
54
45
  return text.startsWith('<?xml');
55
46
  }
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
-
95
- export const _typecheckXMLLoader: LoaderWithParser = XMLLoader;