node-red-contrib-tak-registration 0.7.2 → 0.8.3

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 (102) hide show
  1. package/README.md +3 -1
  2. package/node_modules/@types/node/README.md +1 -1
  3. package/node_modules/@types/node/child_process.d.ts +5 -0
  4. package/node_modules/@types/node/dgram.d.ts +5 -0
  5. package/node_modules/@types/node/events.d.ts +35 -0
  6. package/node_modules/@types/node/fs/promises.d.ts +5 -0
  7. package/node_modules/@types/node/fs.d.ts +43 -5
  8. package/node_modules/@types/node/globals.d.ts +22 -0
  9. package/node_modules/@types/node/index.d.ts +1 -1
  10. package/node_modules/@types/node/inspector.d.ts +1 -1
  11. package/node_modules/@types/node/module.d.ts +103 -0
  12. package/node_modules/@types/node/net.d.ts +5 -0
  13. package/node_modules/@types/node/package.json +2 -2
  14. package/node_modules/@types/node/stream.d.ts +143 -0
  15. package/node_modules/@types/node/test.d.ts +33 -4
  16. package/node_modules/@types/node/timers.d.ts +12 -2
  17. package/node_modules/@types/node/ts4.8/child_process.d.ts +5 -0
  18. package/node_modules/@types/node/ts4.8/dgram.d.ts +5 -0
  19. package/node_modules/@types/node/ts4.8/events.d.ts +35 -0
  20. package/node_modules/@types/node/ts4.8/fs/promises.d.ts +5 -0
  21. package/node_modules/@types/node/ts4.8/fs.d.ts +43 -5
  22. package/node_modules/@types/node/ts4.8/globals.d.ts +22 -0
  23. package/node_modules/@types/node/ts4.8/inspector.d.ts +1 -1
  24. package/node_modules/@types/node/ts4.8/module.d.ts +103 -0
  25. package/node_modules/@types/node/ts4.8/net.d.ts +5 -0
  26. package/node_modules/@types/node/ts4.8/stream.d.ts +762 -728
  27. package/node_modules/@types/node/ts4.8/test.d.ts +97 -50
  28. package/node_modules/@types/node/ts4.8/timers.d.ts +12 -2
  29. package/node_modules/@types/node/ts4.8/vm.d.ts +2 -1
  30. package/node_modules/@types/node/vm.d.ts +2 -1
  31. package/node_modules/axios/CHANGELOG.md +23 -0
  32. package/node_modules/axios/README.md +33 -5
  33. package/node_modules/axios/dist/axios.js +26 -18
  34. package/node_modules/axios/dist/axios.js.map +1 -1
  35. package/node_modules/axios/dist/axios.min.js +1 -1
  36. package/node_modules/axios/dist/axios.min.js.map +1 -1
  37. package/node_modules/axios/dist/browser/axios.cjs +24 -20
  38. package/node_modules/axios/dist/browser/axios.cjs.map +1 -1
  39. package/node_modules/axios/dist/esm/axios.js +26 -21
  40. package/node_modules/axios/dist/esm/axios.js.map +1 -1
  41. package/node_modules/axios/dist/esm/axios.min.js +1 -1
  42. package/node_modules/axios/dist/esm/axios.min.js.map +1 -1
  43. package/node_modules/axios/dist/node/axios.cjs +27 -21
  44. package/node_modules/axios/dist/node/axios.cjs.map +1 -1
  45. package/node_modules/axios/index.d.cts +1 -0
  46. package/node_modules/axios/index.d.ts +3 -0
  47. package/node_modules/axios/index.js +2 -0
  48. package/node_modules/axios/lib/adapters/http.js +3 -1
  49. package/node_modules/axios/lib/axios.js +3 -0
  50. package/node_modules/axios/lib/core/Axios.js +2 -4
  51. package/node_modules/axios/lib/core/AxiosHeaders.js +11 -1
  52. package/node_modules/axios/lib/defaults/index.js +4 -11
  53. package/node_modules/axios/lib/env/data.js +1 -1
  54. package/node_modules/axios/lib/utils.js +3 -2
  55. package/node_modules/axios/package.json +3 -1
  56. package/node_modules/fast-xml-parser/CHANGELOG.md +561 -0
  57. package/node_modules/fast-xml-parser/README.md +134 -287
  58. package/node_modules/fast-xml-parser/package.json +17 -40
  59. package/node_modules/fast-xml-parser/{cli.js → src/cli/cli.js} +16 -24
  60. package/node_modules/fast-xml-parser/src/cli/man.js +12 -0
  61. package/node_modules/fast-xml-parser/src/fxp.d.ts +108 -0
  62. package/node_modules/fast-xml-parser/src/fxp.js +11 -0
  63. package/node_modules/fast-xml-parser/src/util.js +0 -36
  64. package/node_modules/fast-xml-parser/src/validator.js +15 -5
  65. package/node_modules/fast-xml-parser/src/xmlbuilder/json2xml.js +269 -0
  66. package/node_modules/fast-xml-parser/src/xmlbuilder/orderedJs2Xml.js +131 -0
  67. package/node_modules/fast-xml-parser/src/xmlbuilder/prettifyJs2Xml.js +0 -0
  68. package/node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js +152 -0
  69. package/node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js +48 -0
  70. package/node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js +589 -0
  71. package/node_modules/fast-xml-parser/src/xmlparser/XMLParser.js +58 -0
  72. package/node_modules/fast-xml-parser/src/xmlparser/node2json.js +113 -0
  73. package/node_modules/fast-xml-parser/src/xmlparser/xmlNode.js +25 -0
  74. package/node_modules/protobufjs/dist/light/protobuf.js +24 -13
  75. package/node_modules/protobufjs/dist/light/protobuf.js.map +1 -1
  76. package/node_modules/protobufjs/dist/light/protobuf.min.js +3 -3
  77. package/node_modules/protobufjs/dist/light/protobuf.min.js.map +1 -1
  78. package/node_modules/protobufjs/dist/minimal/protobuf.js +12 -7
  79. package/node_modules/protobufjs/dist/minimal/protobuf.js.map +1 -1
  80. package/node_modules/protobufjs/dist/minimal/protobuf.min.js +3 -3
  81. package/node_modules/protobufjs/dist/minimal/protobuf.min.js.map +1 -1
  82. package/node_modules/protobufjs/dist/protobuf.js +40 -18
  83. package/node_modules/protobufjs/dist/protobuf.js.map +1 -1
  84. package/node_modules/protobufjs/dist/protobuf.min.js +3 -3
  85. package/node_modules/protobufjs/dist/protobuf.min.js.map +1 -1
  86. package/node_modules/protobufjs/package.json +1 -1
  87. package/node_modules/protobufjs/src/converter.js +2 -2
  88. package/node_modules/protobufjs/src/parse.js +4 -1
  89. package/node_modules/protobufjs/src/reader.js +8 -3
  90. package/node_modules/protobufjs/src/tokenize.js +2 -4
  91. package/package.json +4 -4
  92. package/tak-ingest.js +4 -3
  93. package/tak-registration.js +14 -5
  94. package/node_modules/fast-xml-parser/src/json2xml.js +0 -280
  95. package/node_modules/fast-xml-parser/src/nimndata.js +0 -144
  96. package/node_modules/fast-xml-parser/src/node2json.js +0 -42
  97. package/node_modules/fast-xml-parser/src/node2json_str.js +0 -63
  98. package/node_modules/fast-xml-parser/src/parser.d.ts +0 -79
  99. package/node_modules/fast-xml-parser/src/parser.js +0 -76
  100. package/node_modules/fast-xml-parser/src/xmlNode.js +0 -17
  101. package/node_modules/fast-xml-parser/src/xmlstr2xmlnode.js +0 -339
  102. /package/node_modules/fast-xml-parser/src/{read.js → cli/read.js} +0 -0
@@ -1,63 +0,0 @@
1
- 'use strict';
2
-
3
- const util = require('./util');
4
- const buildOptions = require('./util').buildOptions;
5
- const x2j = require('./xmlstr2xmlnode');
6
-
7
- //TODO: do it later
8
- const convertToJsonString = function(node, options) {
9
- options = buildOptions(options, x2j.defaultOptions, x2j.props);
10
-
11
- options.indentBy = options.indentBy || '';
12
- return _cToJsonStr(node, options, 0);
13
- };
14
-
15
- const _cToJsonStr = function(node, options, level) {
16
- let jObj = '{';
17
-
18
- //traver through all the children
19
- const keys = Object.keys(node.child);
20
-
21
- for (let index = 0; index < keys.length; index++) {
22
- const tagname = keys[index];
23
- if (node.child[tagname] && node.child[tagname].length > 1) {
24
- jObj += '"' + tagname + '" : [ ';
25
- for (let tag in node.child[tagname]) {
26
- jObj += _cToJsonStr(node.child[tagname][tag], options) + ' , ';
27
- }
28
- jObj = jObj.substr(0, jObj.length - 1) + ' ] '; //remove extra comma in last
29
- } else {
30
- jObj += '"' + tagname + '" : ' + _cToJsonStr(node.child[tagname][0], options) + ' ,';
31
- }
32
- }
33
- util.merge(jObj, node.attrsMap);
34
- //add attrsMap as new children
35
- if (util.isEmptyObject(jObj)) {
36
- return util.isExist(node.val) ? node.val : '';
37
- } else {
38
- if (util.isExist(node.val)) {
39
- if (!(typeof node.val === 'string' && (node.val === '' || node.val === options.cdataPositionChar))) {
40
- jObj += '"' + options.textNodeName + '" : ' + stringval(node.val);
41
- }
42
- }
43
- }
44
- //add value
45
- if (jObj[jObj.length - 1] === ',') {
46
- jObj = jObj.substr(0, jObj.length - 2);
47
- }
48
- return jObj + '}';
49
- };
50
-
51
- function stringval(v) {
52
- if (v === true || v === false || !isNaN(v)) {
53
- return v;
54
- } else {
55
- return '"' + v + '"';
56
- }
57
- }
58
-
59
- function indentate(options, level) {
60
- return options.indentBy.repeat(level);
61
- }
62
-
63
- exports.convertToJsonString = convertToJsonString;
@@ -1,79 +0,0 @@
1
- type X2jOptions = {
2
- attributeNamePrefix: string;
3
- attrNodeName: false | string;
4
- textNodeName: string;
5
- ignoreAttributes: boolean;
6
- ignoreNameSpace: boolean;
7
- allowBooleanAttributes: boolean;
8
- parseNodeValue: boolean;
9
- parseAttributeValue: boolean;
10
- arrayMode: boolean | 'strict' | RegExp | ((tagName: string, parentTagName: string) => boolean);
11
- trimValues: boolean;
12
- cdataTagName: false | string;
13
- cdataPositionChar: string;
14
- parseTrueNumberOnly: boolean;
15
- numParseOptions: strnumOptions;
16
- tagValueProcessor: (tagValue: string, tagName: string) => string;
17
- attrValueProcessor: (attrValue: string, attrName: string) => string;
18
- stopNodes: string[];
19
- alwaysCreateTextNode: boolean;
20
- };
21
- type strnumOptions = {
22
- hex: boolean;
23
- leadingZeros: boolean,
24
- skipLike?: RegExp
25
- }
26
- type X2jOptionsOptional = Partial<X2jOptions>;
27
- type validationOptions = {
28
- allowBooleanAttributes: boolean;
29
- };
30
- type validationOptionsOptional = Partial<validationOptions>;
31
- type J2xOptions = {
32
- attributeNamePrefix: string;
33
- attrNodeName: false | string;
34
- textNodeName: string;
35
- ignoreAttributes: boolean;
36
- cdataTagName: false | string;
37
- cdataPositionChar: string;
38
- format: boolean;
39
- indentBy: string;
40
- supressEmptyNode: boolean;
41
- tagValueProcessor: (tagValue: string) => string;
42
- attrValueProcessor: (attrValue: string) => string;
43
- };
44
- type J2xOptionsOptional = Partial<J2xOptions>;
45
-
46
- type ESchema = string | object | Array<string|object>;
47
-
48
- type ValidationError = {
49
- err: { code: string; msg: string, line: number, col: number };
50
- };
51
-
52
- export function parse(xmlData: string, options?: X2jOptionsOptional, validationOptions?: validationOptionsOptional | boolean): any;
53
- export function convert2nimn(
54
- node: any,
55
- e_schema: ESchema,
56
- options?: X2jOptionsOptional
57
- ): any;
58
- export function getTraversalObj(
59
- xmlData: string,
60
- options?: X2jOptionsOptional
61
- ): any;
62
- export function convertToJson(node: any, options?: X2jOptionsOptional): any;
63
- export function convertToJsonString(
64
- node: any,
65
- options?: X2jOptionsOptional
66
- ): string;
67
- export function validate(
68
- xmlData: string,
69
- options?: validationOptionsOptional
70
- ): true | ValidationError;
71
- export class j2xParser {
72
- constructor(options: J2xOptionsOptional);
73
- parse(options: any): any;
74
- }
75
- export function parseToNimn(
76
- xmlData: string,
77
- schema: any,
78
- options: Partial<X2jOptions>
79
- ): any;
@@ -1,76 +0,0 @@
1
- 'use strict';
2
-
3
- const nodeToJson = require('./node2json');
4
- const xmlToNodeobj = require('./xmlstr2xmlnode');
5
- const x2xmlnode = require('./xmlstr2xmlnode');
6
- const buildOptions = require('./util').buildOptions;
7
- const validator = require('./validator');
8
-
9
- exports.parse = function(xmlData, givenOptions = {}, validationOption) {
10
- if( validationOption){
11
- if(validationOption === true) validationOption = {}
12
-
13
- const result = validator.validate(xmlData, validationOption);
14
- if (result !== true) {
15
- throw Error( result.err.msg)
16
- }
17
- }
18
- if(givenOptions.parseTrueNumberOnly
19
- && givenOptions.parseNodeValue !== false
20
- && !givenOptions.numParseOptions){
21
-
22
- givenOptions.numParseOptions = {
23
- leadingZeros: false,
24
- }
25
- }
26
- let options = buildOptions(givenOptions, x2xmlnode.defaultOptions, x2xmlnode.props);
27
-
28
- const traversableObj = xmlToNodeobj.getTraversalObj(xmlData, options)
29
- //print(traversableObj, " ");
30
- return nodeToJson.convertToJson(traversableObj, options);
31
- };
32
- exports.convertTonimn = require('./nimndata').convert2nimn;
33
- exports.getTraversalObj = xmlToNodeobj.getTraversalObj;
34
- exports.convertToJson = nodeToJson.convertToJson;
35
- exports.convertToJsonString = require('./node2json_str').convertToJsonString;
36
- exports.validate = validator.validate;
37
- exports.j2xParser = require('./json2xml');
38
- exports.parseToNimn = function(xmlData, schema, options) {
39
- return exports.convertTonimn(exports.getTraversalObj(xmlData, options), schema, options);
40
- };
41
-
42
-
43
- function print(xmlNode, indentation){
44
- if(xmlNode){
45
- console.log(indentation + "{")
46
- console.log(indentation + " \"tagName\": \"" + xmlNode.tagname + "\", ");
47
- if(xmlNode.parent){
48
- console.log(indentation + " \"parent\": \"" + xmlNode.parent.tagname + "\", ");
49
- }
50
- console.log(indentation + " \"val\": \"" + xmlNode.val + "\", ");
51
- console.log(indentation + " \"attrs\": " + JSON.stringify(xmlNode.attrsMap,null,4) + ", ");
52
-
53
- if(xmlNode.child){
54
- console.log(indentation + "\"child\": {")
55
- const indentation2 = indentation + indentation;
56
- Object.keys(xmlNode.child).forEach( function(key) {
57
- const node = xmlNode.child[key];
58
-
59
- if(Array.isArray(node)){
60
- console.log(indentation + "\""+key+"\" :[")
61
- node.forEach( function(item,index) {
62
- //console.log(indentation + " \""+index+"\" : [")
63
- print(item, indentation2);
64
- })
65
- console.log(indentation + "],")
66
- }else{
67
- console.log(indentation + " \""+key+"\" : {")
68
- print(node, indentation2);
69
- console.log(indentation + "},")
70
- }
71
- });
72
- console.log(indentation + "},")
73
- }
74
- console.log(indentation + "},")
75
- }
76
- }
@@ -1,17 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = function(tagname, parent, val) {
4
- this.tagname = tagname;
5
- this.parent = parent;
6
- this.child = {}; //child tags
7
- this.attrsMap = {}; //attributes map
8
- this.val = val; //text only
9
- this.addChild = function(child) {
10
- if (Array.isArray(this.child[child.tagname])) {
11
- //already presents
12
- this.child[child.tagname].push(child);
13
- } else {
14
- this.child[child.tagname] = [child];
15
- }
16
- };
17
- };
@@ -1,339 +0,0 @@
1
- 'use strict';
2
-
3
- const util = require('./util');
4
- const buildOptions = require('./util').buildOptions;
5
- const xmlNode = require('./xmlNode');
6
- const toNumber = require("strnum");
7
-
8
- const regx =
9
- '<((!\\[CDATA\\[([\\s\\S]*?)(]]>))|((NAME:)?(NAME))([^>]*)>|((\\/)(NAME)\\s*>))([^<]*)'
10
- .replace(/NAME/g, util.nameRegexp);
11
-
12
- //const tagsRegx = new RegExp("<(\\/?[\\w:\\-\._]+)([^>]*)>(\\s*"+cdataRegx+")*([^<]+)?","g");
13
- //const tagsRegx = new RegExp("<(\\/?)((\\w*:)?([\\w:\\-\._]+))([^>]*)>([^<]*)("+cdataRegx+"([^<]*))*([^<]+)?","g");
14
-
15
- //polyfill
16
- if (!Number.parseInt && window.parseInt) {
17
- Number.parseInt = window.parseInt;
18
- }
19
- if (!Number.parseFloat && window.parseFloat) {
20
- Number.parseFloat = window.parseFloat;
21
- }
22
-
23
- const defaultOptions = {
24
- attributeNamePrefix: '@_',
25
- attrNodeName: false,
26
- textNodeName: '#text',
27
- ignoreAttributes: true,
28
- ignoreNameSpace: false,
29
- allowBooleanAttributes: false, //a tag can have attributes without any value
30
- //ignoreRootElement : false,
31
- parseNodeValue: true,
32
- parseAttributeValue: false,
33
- arrayMode: false,
34
- trimValues: true, //Trim string values of tag and attributes
35
- cdataTagName: false,
36
- cdataPositionChar: '\\c',
37
- numParseOptions: {
38
- hex: true,
39
- leadingZeros: true
40
- },
41
- tagValueProcessor: function(a, tagName) {
42
- return a;
43
- },
44
- attrValueProcessor: function(a, attrName) {
45
- return a;
46
- },
47
- stopNodes: [],
48
- alwaysCreateTextNode: false
49
- //decodeStrict: false,
50
- };
51
-
52
- exports.defaultOptions = defaultOptions;
53
-
54
- const props = [
55
- 'attributeNamePrefix',
56
- 'attrNodeName',
57
- 'textNodeName',
58
- 'ignoreAttributes',
59
- 'ignoreNameSpace',
60
- 'allowBooleanAttributes',
61
- 'parseNodeValue',
62
- 'parseAttributeValue',
63
- 'arrayMode',
64
- 'trimValues',
65
- 'cdataTagName',
66
- 'cdataPositionChar',
67
- 'tagValueProcessor',
68
- 'attrValueProcessor',
69
- 'parseTrueNumberOnly',
70
- 'numParseOptions',
71
- 'stopNodes',
72
- 'alwaysCreateTextNode'
73
- ];
74
- exports.props = props;
75
-
76
- /**
77
- * Trim -> valueProcessor -> parse value
78
- * @param {string} tagName
79
- * @param {string} val
80
- * @param {object} options
81
- */
82
- function processTagValue(tagName, val, options) {
83
- if (val) {
84
- if (options.trimValues) {
85
- val = val.trim();
86
- }
87
- val = options.tagValueProcessor(val, tagName);
88
- val = parseValue(val, options.parseNodeValue, options.numParseOptions);
89
- }
90
-
91
- return val;
92
- }
93
-
94
- function resolveNameSpace(tagname, options) {
95
- if (options.ignoreNameSpace) {
96
- const tags = tagname.split(':');
97
- const prefix = tagname.charAt(0) === '/' ? '/' : '';
98
- if (tags[0] === 'xmlns') {
99
- return '';
100
- }
101
- if (tags.length === 2) {
102
- tagname = prefix + tags[1];
103
- }
104
- }
105
- return tagname;
106
- }
107
-
108
- function parseValue(val, shouldParse, options) {
109
- if (shouldParse && typeof val === 'string') {
110
- //console.log(options)
111
- const newval = val.trim();
112
- if(newval === 'true' ) return true;
113
- else if(newval === 'false' ) return false;
114
- else return toNumber(val, options);
115
- } else {
116
- if (util.isExist(val)) {
117
- return val;
118
- } else {
119
- return '';
120
- }
121
- }
122
- }
123
-
124
- //TODO: change regex to capture NS
125
- //const attrsRegx = new RegExp("([\\w\\-\\.\\:]+)\\s*=\\s*(['\"])((.|\n)*?)\\2","gm");
126
- const attrsRegx = new RegExp('([^\\s=]+)\\s*(=\\s*([\'"])(.*?)\\3)?', 'g');
127
-
128
- function buildAttributesMap(attrStr, options) {
129
- if (!options.ignoreAttributes && typeof attrStr === 'string') {
130
- attrStr = attrStr.replace(/\r?\n/g, ' ');
131
- //attrStr = attrStr || attrStr.trim();
132
-
133
- const matches = util.getAllMatches(attrStr, attrsRegx);
134
- const len = matches.length; //don't make it inline
135
- const attrs = {};
136
- for (let i = 0; i < len; i++) {
137
- const attrName = resolveNameSpace(matches[i][1], options);
138
- if (attrName.length) {
139
- if (matches[i][4] !== undefined) {
140
- if (options.trimValues) {
141
- matches[i][4] = matches[i][4].trim();
142
- }
143
- matches[i][4] = options.attrValueProcessor(matches[i][4], attrName);
144
- attrs[options.attributeNamePrefix + attrName] = parseValue(
145
- matches[i][4],
146
- options.parseAttributeValue,
147
- options.numParseOptions
148
- );
149
- } else if (options.allowBooleanAttributes) {
150
- attrs[options.attributeNamePrefix + attrName] = true;
151
- }
152
- }
153
- }
154
- if (!Object.keys(attrs).length) {
155
- return;
156
- }
157
- if (options.attrNodeName) {
158
- const attrCollection = {};
159
- attrCollection[options.attrNodeName] = attrs;
160
- return attrCollection;
161
- }
162
- return attrs;
163
- }
164
- }
165
-
166
- const getTraversalObj = function(xmlData, options) {
167
- xmlData = xmlData.replace(/\r\n?/g, "\n");
168
- options = buildOptions(options, defaultOptions, props);
169
- const xmlObj = new xmlNode('!xml');
170
- let currentNode = xmlObj;
171
- let textData = "";
172
-
173
- //function match(xmlData){
174
- for(let i=0; i< xmlData.length; i++){
175
- const ch = xmlData[i];
176
- if(ch === '<'){
177
- if( xmlData[i+1] === '/') {//Closing Tag
178
- const closeIndex = findClosingIndex(xmlData, ">", i, "Closing Tag is not closed.")
179
- let tagName = xmlData.substring(i+2,closeIndex).trim();
180
-
181
- if(options.ignoreNameSpace){
182
- const colonIndex = tagName.indexOf(":");
183
- if(colonIndex !== -1){
184
- tagName = tagName.substr(colonIndex+1);
185
- }
186
- }
187
-
188
- /* if (currentNode.parent) {
189
- currentNode.parent.val = util.getValue(currentNode.parent.val) + '' + processTagValue2(tagName, textData , options);
190
- } */
191
- if(currentNode){
192
- if(currentNode.val){
193
- currentNode.val = util.getValue(currentNode.val) + '' + processTagValue(tagName, textData , options);
194
- }else{
195
- currentNode.val = processTagValue(tagName, textData , options);
196
- }
197
- }
198
-
199
- if (options.stopNodes.length && options.stopNodes.includes(currentNode.tagname)) {
200
- currentNode.child = []
201
- if (currentNode.attrsMap == undefined) { currentNode.attrsMap = {}}
202
- currentNode.val = xmlData.substr(currentNode.startIndex + 1, i - currentNode.startIndex - 1)
203
- }
204
- currentNode = currentNode.parent;
205
- textData = "";
206
- i = closeIndex;
207
- } else if( xmlData[i+1] === '?') {
208
- i = findClosingIndex(xmlData, "?>", i, "Pi Tag is not closed.")
209
- } else if(xmlData.substr(i + 1, 3) === '!--') {
210
- i = findClosingIndex(xmlData, "-->", i, "Comment is not closed.")
211
- } else if( xmlData.substr(i + 1, 2) === '!D') {
212
- const closeIndex = findClosingIndex(xmlData, ">", i, "DOCTYPE is not closed.")
213
- const tagExp = xmlData.substring(i, closeIndex);
214
- if(tagExp.indexOf("[") >= 0){
215
- i = xmlData.indexOf("]>", i) + 1;
216
- }else{
217
- i = closeIndex;
218
- }
219
- }else if(xmlData.substr(i + 1, 2) === '![') {
220
- const closeIndex = findClosingIndex(xmlData, "]]>", i, "CDATA is not closed.") - 2
221
- const tagExp = xmlData.substring(i + 9,closeIndex);
222
-
223
- //considerations
224
- //1. CDATA will always have parent node
225
- //2. A tag with CDATA is not a leaf node so it's value would be string type.
226
- if(textData){
227
- currentNode.val = util.getValue(currentNode.val) + '' + processTagValue(currentNode.tagname, textData , options);
228
- textData = "";
229
- }
230
-
231
- if (options.cdataTagName) {
232
- //add cdata node
233
- const childNode = new xmlNode(options.cdataTagName, currentNode, tagExp);
234
- currentNode.addChild(childNode);
235
- //for backtracking
236
- currentNode.val = util.getValue(currentNode.val) + options.cdataPositionChar;
237
- //add rest value to parent node
238
- if (tagExp) {
239
- childNode.val = tagExp;
240
- }
241
- } else {
242
- currentNode.val = (currentNode.val || '') + (tagExp || '');
243
- }
244
-
245
- i = closeIndex + 2;
246
- }else {//Opening tag
247
- const result = closingIndexForOpeningTag(xmlData, i+1)
248
- let tagExp = result.data;
249
- const closeIndex = result.index;
250
- const separatorIndex = tagExp.indexOf(" ");
251
- let tagName = tagExp;
252
- let shouldBuildAttributesMap = true;
253
- if(separatorIndex !== -1){
254
- tagName = tagExp.substr(0, separatorIndex).replace(/\s\s*$/, '');
255
- tagExp = tagExp.substr(separatorIndex + 1);
256
- }
257
-
258
- if(options.ignoreNameSpace){
259
- const colonIndex = tagName.indexOf(":");
260
- if(colonIndex !== -1){
261
- tagName = tagName.substr(colonIndex+1);
262
- shouldBuildAttributesMap = tagName !== result.data.substr(colonIndex + 1);
263
- }
264
- }
265
-
266
- //save text to parent node
267
- if (currentNode && textData) {
268
- if(currentNode.tagname !== '!xml'){
269
- currentNode.val = util.getValue(currentNode.val) + '' + processTagValue( currentNode.tagname, textData, options);
270
- }
271
- }
272
-
273
- if(tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1){//selfClosing tag
274
-
275
- if(tagName[tagName.length - 1] === "/"){ //remove trailing '/'
276
- tagName = tagName.substr(0, tagName.length - 1);
277
- tagExp = tagName;
278
- }else{
279
- tagExp = tagExp.substr(0, tagExp.length - 1);
280
- }
281
-
282
- const childNode = new xmlNode(tagName, currentNode, '');
283
- if(tagName !== tagExp){
284
- childNode.attrsMap = buildAttributesMap(tagExp, options);
285
- }
286
- currentNode.addChild(childNode);
287
- }else{//opening tag
288
-
289
- const childNode = new xmlNode( tagName, currentNode );
290
- if (options.stopNodes.length && options.stopNodes.includes(childNode.tagname)) {
291
- childNode.startIndex=closeIndex;
292
- }
293
- if(tagName !== tagExp && shouldBuildAttributesMap){
294
- childNode.attrsMap = buildAttributesMap(tagExp, options);
295
- }
296
- currentNode.addChild(childNode);
297
- currentNode = childNode;
298
- }
299
- textData = "";
300
- i = closeIndex;
301
- }
302
- }else{
303
- textData += xmlData[i];
304
- }
305
- }
306
- return xmlObj;
307
- }
308
-
309
- function closingIndexForOpeningTag(data, i){
310
- let attrBoundary;
311
- let tagExp = "";
312
- for (let index = i; index < data.length; index++) {
313
- let ch = data[index];
314
- if (attrBoundary) {
315
- if (ch === attrBoundary) attrBoundary = "";//reset
316
- } else if (ch === '"' || ch === "'") {
317
- attrBoundary = ch;
318
- } else if (ch === '>') {
319
- return {
320
- data: tagExp,
321
- index: index
322
- }
323
- } else if (ch === '\t') {
324
- ch = " "
325
- }
326
- tagExp += ch;
327
- }
328
- }
329
-
330
- function findClosingIndex(xmlData, str, i, errMsg){
331
- const closingIndex = xmlData.indexOf(str, i);
332
- if(closingIndex === -1){
333
- throw new Error(errMsg)
334
- }else{
335
- return closingIndex + str.length - 1;
336
- }
337
- }
338
-
339
- exports.getTraversalObj = getTraversalObj;