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,6 +1,6 @@
1
1
  {
2
2
  "name": "protobufjs",
3
- "version": "7.2.4",
3
+ "version": "7.2.5",
4
4
  "versionScheme": "~",
5
5
  "description": "Protocol Buffers for JavaScript (& TypeScript).",
6
6
  "author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
@@ -62,7 +62,7 @@ function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
62
62
  break;
63
63
  case "uint64":
64
64
  isUnsigned = true;
65
- // eslint-disable-line no-fallthrough
65
+ // eslint-disable-next-line no-fallthrough
66
66
  case "int64":
67
67
  case "sint64":
68
68
  case "fixed64":
@@ -176,7 +176,7 @@ function genValuePartial_toObject(gen, field, fieldIndex, prop) {
176
176
  break;
177
177
  case "uint64":
178
178
  isUnsigned = true;
179
- // eslint-disable-line no-fallthrough
179
+ // eslint-disable-next-line no-fallthrough
180
180
  case "int64":
181
181
  case "sint64":
182
182
  case "fixed64":
@@ -227,7 +227,7 @@ function parse(source, root, options) {
227
227
  break;
228
228
  case "public":
229
229
  next();
230
- // eslint-disable-line no-fallthrough
230
+ // eslint-disable-next-line no-fallthrough
231
231
  default:
232
232
  whichImports = imports || (imports = []);
233
233
  break;
@@ -621,6 +621,9 @@ function parse(source, root, options) {
621
621
  if (!nameRe.test(token = next())) {
622
622
  throw illegal(token, "name");
623
623
  }
624
+ if (token === null) {
625
+ throw illegal(token, "end of input");
626
+ }
624
627
 
625
628
  var value;
626
629
  var propName = token;
@@ -312,9 +312,14 @@ Reader.prototype.bytes = function read_bytes() {
312
312
  this.pos += length;
313
313
  if (Array.isArray(this.buf)) // plain array
314
314
  return this.buf.slice(start, end);
315
- return start === end // fix for IE 10/Win8 and others' subarray returning array of size 1
316
- ? new this.buf.constructor(0)
317
- : this._slice.call(this.buf, start, end);
315
+
316
+ if (start === end) { // fix for IE 10/Win8 and others' subarray returning array of size 1
317
+ var nativeBuffer = util.Buffer;
318
+ return nativeBuffer
319
+ ? nativeBuffer.alloc(0)
320
+ : new this.buf.constructor(0);
321
+ }
322
+ return this._slice.call(this.buf, start, end);
318
323
  };
319
324
 
320
325
  /**
@@ -197,9 +197,7 @@ function tokenize(source, alternateCommentMode) {
197
197
 
198
198
  // see if remaining line matches comment pattern
199
199
  var lineText = source.substring(startOffset, endOffset);
200
- // look for 1 or 2 slashes since startOffset would already point past
201
- // the first slash that started the comment.
202
- var isComment = /^\s*\/{1,2}/.test(lineText);
200
+ var isComment = /^\s*\/\//.test(lineText);
203
201
  return isComment;
204
202
  }
205
203
 
@@ -268,7 +266,7 @@ function tokenize(source, alternateCommentMode) {
268
266
  // check for double-slash comments, consolidating consecutive lines
269
267
  start = offset;
270
268
  isDoc = false;
271
- if (isDoubleSlashCommentLine(offset)) {
269
+ if (isDoubleSlashCommentLine(offset - 1)) {
272
270
  isDoc = true;
273
271
  do {
274
272
  offset = findEndOfLine(offset);
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "node-red-contrib-tak-registration",
3
- "version": "0.7.2",
3
+ "version": "0.8.3",
4
4
  "description": "A Node-RED node to register to TAK and to help wrap files as datapackages to send to TAK",
5
5
  "dependencies": {
6
6
  "@turf/turf": "6.5.0",
7
7
  "adm-zip": "0.5.10",
8
- "axios": "1.4.0",
9
- "fast-xml-parser": "3.21.1",
8
+ "axios": "1.5.0",
9
+ "fast-xml-parser": "4.2.7",
10
10
  "form-data": "4.0.0",
11
11
  "long": "5.2.3",
12
- "protobufjs": "7.2.4",
12
+ "protobufjs": "7.2.5",
13
13
  "uuid": "9.0.0"
14
14
  },
15
15
  "bundledDependencies": [
package/tak-ingest.js CHANGED
@@ -1,4 +1,4 @@
1
- var fastXmlParser = require('fast-xml-parser');
1
+ const { XMLParser, XMLBuilder, XMLValidator} = require("fast-xml-parser");
2
2
  var Long = require('long').Long;
3
3
  var protobuf = require('protobufjs');
4
4
  var path = require('path');
@@ -9,7 +9,7 @@ module.exports = function(RED) {
9
9
  "use strict";
10
10
  const fastXmlOptions = {
11
11
  attributeNamePrefix: "",
12
- // attrNodeName: "attr",
12
+ // attributesGroupName: "attr",
13
13
  ignoreAttributes: false,
14
14
  };
15
15
 
@@ -17,6 +17,7 @@ module.exports = function(RED) {
17
17
  RED.nodes.createNode(this,n);
18
18
  var node = this;
19
19
  var global = this.context().global;
20
+ const parser = new XMLParser(fastXmlOptions);
20
21
 
21
22
  node.on("input",function(msg) {
22
23
  if (Buffer.isBuffer(msg.payload)) {
@@ -72,7 +73,7 @@ module.exports = function(RED) {
72
73
  }
73
74
  return;
74
75
  }
75
- msg.payload = fastXmlParser.parse(msg.payload, fastXmlOptions);
76
+ msg.payload = parser.parse(msg.payload);
76
77
  // Add any unique ID/callsigns to some global variables just in case it's useful for later.
77
78
  if (msg.payload?.event?.detail?.contact?.callsign && msg.payload?.event?.uid) {
78
79
  var a = global.get("_takgatewaycs") || {};
@@ -35,6 +35,7 @@ module.exports = function(RED) {
35
35
  var gr = {};
36
36
  gr[node.callsign] = node.uuid;
37
37
  globalContext.set("_takgatewaycs",gr);
38
+ globalContext.set("_takdphost",node.host);
38
39
 
39
40
  if (node.role !== "Gateway") { node.ntype = "a-f-G-U-C" }
40
41
 
@@ -73,7 +74,7 @@ module.exports = function(RED) {
73
74
  var sendIt = function() {
74
75
  node.emit("input", {
75
76
  time: new Date().toISOString(),
76
- etime: new Date(Date.now() + 2000 * node.repeat).toISOString(),
77
+ etime: new Date(Date.now() + (2 * node.repeat)).toISOString(),
77
78
  lat: node.lat,
78
79
  lon: node.lon,
79
80
  alt: node.alt,
@@ -98,8 +99,8 @@ module.exports = function(RED) {
98
99
 
99
100
  node.on("input",function(msg) {
100
101
  if (msg.heartbeat) { // Register gateway and do the heartbeats
101
- var template = `<event version="2.0" uid="${node.uuid}" type="${msg.type}" how="h-e" time="${msg.time}" start="${msg.time}" stale="${msg.etime}"><point lat="${msg.lat}" lon="${msg.lon}" hae="${msg.alt}" ce="9999999" le="9999999"/><detail><takv device="${os.hostname()}" os="${os.platform()}" platform="NRedTAK" version="${ver}"/><contact endpoint="*:-1:stcp" callsign="${msg.callsign}"/><uid Droid="${msg.callsign}"/><__group name="${msg.group}" role="${msg.role}"/><status battery="99"/></detail></event>`;
102
- node.send({payload:template});
102
+ var template = `<event version="2.0" uid="${node.uuid}" type="${msg.type}" how="h-e" time="${msg.time}" start="${msg.time}" stale="${msg.etime}"><point lat="${msg.lat}" lon="${msg.lon}" hae="${msg.alt}" ce="9999999" le="9999999"/><detail><takv device="${os.hostname()}" os="${os.platform()}" platform="NRedTAK" version="${ver}"/><contact endpoint="*:-1:stcp" callsign="${msg.callsign}"/><uid Droid="${msg.callsign}"/><__group name="${msg.group}" role="${msg.role}"/><status battery="99"/><track course="0.00000000" speed="0.00000000"/></detail></event>`;
103
+ node.send({payload:template, topic:msg.type});
103
104
  node.status({fill:"green", shape:"dot", text:node.repeat/1000+"s - "+node.callsign});
104
105
  return;
105
106
  }
@@ -183,6 +184,7 @@ module.exports = function(RED) {
183
184
  m += '</detail></event>';
184
185
  node.log( "DP: " + node.host + "/Marti/sync/content?hash=" + msg.hash );
185
186
  msg.payload = m.replace(/>\s+</g, "><");
187
+ msg.topic = "b-f-t-r";
186
188
  node.send(msg);
187
189
  }
188
190
  })
@@ -197,6 +199,7 @@ module.exports = function(RED) {
197
199
  // Otherwise if it's a string maybe it's raw cot xml - or NMEA from GPS - or maybe a simple chat message
198
200
  else if (typeof msg.payload === "string" ) {
199
201
  if (msg.payload.trim().startsWith('<') && msg.payload.trim().endsWith('>')) { // Assume it's proper XML event so pass straight through
202
+ msg.topic = msg.payload.split('type="')[1].split('"')[0];
200
203
  node.send(msg);
201
204
  }
202
205
  else if (msg.payload.trim().startsWith('$GPGGA')) { // maybe it's an NMEA string
@@ -244,6 +247,7 @@ module.exports = function(RED) {
244
247
  </event>`;
245
248
  // console.log(xm);
246
249
  m.payload = xm.replace(/>\s+</g, "><");
250
+ m.topic = "b-t-f";
247
251
  node.send(m);
248
252
  }
249
253
  }
@@ -277,8 +281,13 @@ module.exports = function(RED) {
277
281
  type = s.split('').join('-').replace('s-','a-').replace('-p-','-');
278
282
  }
279
283
  }
280
- // console.log("TYPE",type)
284
+ if (msg.payload.icon === 'fa-circle fa-fw') {
285
+ type = 'b-m-p-s-m';
286
+ shapeXML = '<color argb="' + convertWMtoCOTColour(msg.payload.iconColor.replace('#', '')) + '"/>';
287
+ shapeXML = shapeXML+'<usericon iconsetpath="COT_MAPPING_SPOTMAP/b-m-p-s-m/-16711681"/>';
288
+ }
281
289
  }
290
+
282
291
  // Handle Worldmap drawing shapes
283
292
  if (msg.payload.hasOwnProperty("action") && msg.payload.action === "draw") {
284
293
  ttl = 24*60*60*1000; /// set TTL to 1 day for shapes...
@@ -342,7 +351,6 @@ module.exports = function(RED) {
342
351
  msg.payload.lon = polyCent.geometry.coordinates[1];
343
352
  }
344
353
  // console.log("SHAPE",shape)
345
-
346
354
  if (shape.type === 'ellipse') {
347
355
  type = "u-d-c-c";
348
356
 
@@ -406,6 +414,7 @@ module.exports = function(RED) {
406
414
  </detail>
407
415
  </event>`
408
416
  msg.payload = msg.payload.replace(/>\s+</g, "><");
417
+ msg.topic = type;
409
418
  node.send(msg);
410
419
  }
411
420
 
@@ -1,280 +0,0 @@
1
- 'use strict';
2
- //parse Empty Node as self closing node
3
- const buildOptions = require('./util').buildOptions;
4
-
5
- const defaultOptions = {
6
- attributeNamePrefix: '@_',
7
- attrNodeName: false,
8
- textNodeName: '#text',
9
- ignoreAttributes: true,
10
- cdataTagName: false,
11
- cdataPositionChar: '\\c',
12
- format: false,
13
- indentBy: ' ',
14
- supressEmptyNode: false,
15
- tagValueProcessor: function(a) {
16
- return a;
17
- },
18
- attrValueProcessor: function(a) {
19
- return a;
20
- },
21
- };
22
-
23
- const props = [
24
- 'attributeNamePrefix',
25
- 'attrNodeName',
26
- 'textNodeName',
27
- 'ignoreAttributes',
28
- 'cdataTagName',
29
- 'cdataPositionChar',
30
- 'format',
31
- 'indentBy',
32
- 'supressEmptyNode',
33
- 'tagValueProcessor',
34
- 'attrValueProcessor',
35
- 'rootNodeName', //when array as root
36
- ];
37
-
38
- function Parser(options) {
39
- this.options = buildOptions(options, defaultOptions, props);
40
- if (this.options.ignoreAttributes || this.options.attrNodeName) {
41
- this.isAttribute = function(/*a*/) {
42
- return false;
43
- };
44
- } else {
45
- this.attrPrefixLen = this.options.attributeNamePrefix.length;
46
- this.isAttribute = isAttribute;
47
- }
48
- if (this.options.cdataTagName) {
49
- this.isCDATA = isCDATA;
50
- } else {
51
- this.isCDATA = function(/*a*/) {
52
- return false;
53
- };
54
- }
55
- this.replaceCDATAstr = replaceCDATAstr;
56
- this.replaceCDATAarr = replaceCDATAarr;
57
-
58
- this.processTextOrObjNode = processTextOrObjNode
59
-
60
- if (this.options.format) {
61
- this.indentate = indentate;
62
- this.tagEndChar = '>\n';
63
- this.newLine = '\n';
64
- } else {
65
- this.indentate = function() {
66
- return '';
67
- };
68
- this.tagEndChar = '>';
69
- this.newLine = '';
70
- }
71
-
72
- if (this.options.supressEmptyNode) {
73
- this.buildTextNode = buildEmptyTextNode;
74
- this.buildObjNode = buildEmptyObjNode;
75
- } else {
76
- this.buildTextNode = buildTextValNode;
77
- this.buildObjNode = buildObjectNode;
78
- }
79
-
80
- this.buildTextValNode = buildTextValNode;
81
- this.buildObjectNode = buildObjectNode;
82
- }
83
-
84
- Parser.prototype.parse = function(jObj) {
85
- if(Array.isArray(jObj) && this.options.rootNodeName && this.options.rootNodeName.length > 1){
86
- jObj = {
87
- [this.options.rootNodeName] : jObj
88
- }
89
- }
90
- return this.j2x(jObj, 0).val;
91
- };
92
-
93
- Parser.prototype.j2x = function(jObj, level) {
94
- let attrStr = '';
95
- let val = '';
96
- for (let key in jObj) {
97
- if (typeof jObj[key] === 'undefined') {
98
- // supress undefined node
99
- } else if (jObj[key] === null) {
100
- val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
101
- } else if (jObj[key] instanceof Date) {
102
- val += this.buildTextNode(jObj[key], key, '', level);
103
- } else if (typeof jObj[key] !== 'object') {
104
- //premitive type
105
- const attr = this.isAttribute(key);
106
- if (attr) {
107
- attrStr += ' ' + attr + '="' + this.options.attrValueProcessor('' + jObj[key]) + '"';
108
- } else if (this.isCDATA(key)) {
109
- if (jObj[this.options.textNodeName]) {
110
- val += this.replaceCDATAstr(jObj[this.options.textNodeName], jObj[key]);
111
- } else {
112
- val += this.replaceCDATAstr('', jObj[key]);
113
- }
114
- } else {
115
- //tag value
116
- if (key === this.options.textNodeName) {
117
- if (jObj[this.options.cdataTagName]) {
118
- //value will added while processing cdata
119
- } else {
120
- val += this.options.tagValueProcessor('' + jObj[key]);
121
- }
122
- } else {
123
- val += this.buildTextNode(jObj[key], key, '', level);
124
- }
125
- }
126
- } else if (Array.isArray(jObj[key])) {
127
- //repeated nodes
128
- if (this.isCDATA(key)) {
129
- val += this.indentate(level);
130
- if (jObj[this.options.textNodeName]) {
131
- val += this.replaceCDATAarr(jObj[this.options.textNodeName], jObj[key]);
132
- } else {
133
- val += this.replaceCDATAarr('', jObj[key]);
134
- }
135
- } else {
136
- //nested nodes
137
- const arrLen = jObj[key].length;
138
- for (let j = 0; j < arrLen; j++) {
139
- const item = jObj[key][j];
140
- if (typeof item === 'undefined') {
141
- // supress undefined node
142
- } else if (item === null) {
143
- val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
144
- } else if (typeof item === 'object') {
145
- val += this.processTextOrObjNode(item, key, level)
146
- } else {
147
- val += this.buildTextNode(item, key, '', level);
148
- }
149
- }
150
- }
151
- } else {
152
- //nested node
153
- if (this.options.attrNodeName && key === this.options.attrNodeName) {
154
- const Ks = Object.keys(jObj[key]);
155
- const L = Ks.length;
156
- for (let j = 0; j < L; j++) {
157
- attrStr += ' ' + Ks[j] + '="' + this.options.attrValueProcessor('' + jObj[key][Ks[j]]) + '"';
158
- }
159
- } else {
160
- val += this.processTextOrObjNode(jObj[key], key, level)
161
- }
162
- }
163
- }
164
- return {attrStr: attrStr, val: val};
165
- };
166
-
167
- function processTextOrObjNode (object, key, level) {
168
- const result = this.j2x(object, level + 1);
169
- if (object[this.options.textNodeName] !== undefined && Object.keys(object).length === 1) {
170
- return this.buildTextNode(result.val, key, result.attrStr, level);
171
- } else {
172
- return this.buildObjNode(result.val, key, result.attrStr, level);
173
- }
174
- }
175
-
176
- function replaceCDATAstr(str, cdata) {
177
- str = this.options.tagValueProcessor('' + str);
178
- if (this.options.cdataPositionChar === '' || str === '') {
179
- return str + '<![CDATA[' + cdata + ']]' + this.tagEndChar;
180
- } else {
181
- return str.replace(this.options.cdataPositionChar, '<![CDATA[' + cdata + ']]' + this.tagEndChar);
182
- }
183
- }
184
-
185
- function replaceCDATAarr(str, cdata) {
186
- str = this.options.tagValueProcessor('' + str);
187
- if (this.options.cdataPositionChar === '' || str === '') {
188
- return str + '<![CDATA[' + cdata.join(']]><![CDATA[') + ']]' + this.tagEndChar;
189
- } else {
190
- for (let v in cdata) {
191
- str = str.replace(this.options.cdataPositionChar, '<![CDATA[' + cdata[v] + ']]>');
192
- }
193
- return str + this.newLine;
194
- }
195
- }
196
-
197
- function buildObjectNode(val, key, attrStr, level) {
198
- if (attrStr && val.indexOf('<') === -1) {
199
- return (
200
- this.indentate(level) +
201
- '<' +
202
- key +
203
- attrStr +
204
- '>' +
205
- val +
206
- //+ this.newLine
207
- // + this.indentate(level)
208
- '</' +
209
- key +
210
- this.tagEndChar
211
- );
212
- } else {
213
- return (
214
- this.indentate(level) +
215
- '<' +
216
- key +
217
- attrStr +
218
- this.tagEndChar +
219
- val +
220
- //+ this.newLine
221
- this.indentate(level) +
222
- '</' +
223
- key +
224
- this.tagEndChar
225
- );
226
- }
227
- }
228
-
229
- function buildEmptyObjNode(val, key, attrStr, level) {
230
- if (val !== '') {
231
- return this.buildObjectNode(val, key, attrStr, level);
232
- } else {
233
- return this.indentate(level) + '<' + key + attrStr + '/' + this.tagEndChar;
234
- //+ this.newLine
235
- }
236
- }
237
-
238
- function buildTextValNode(val, key, attrStr, level) {
239
- return (
240
- this.indentate(level) +
241
- '<' +
242
- key +
243
- attrStr +
244
- '>' +
245
- this.options.tagValueProcessor(val) +
246
- '</' +
247
- key +
248
- this.tagEndChar
249
- );
250
- }
251
-
252
- function buildEmptyTextNode(val, key, attrStr, level) {
253
- if (val !== '') {
254
- return this.buildTextValNode(val, key, attrStr, level);
255
- } else {
256
- return this.indentate(level) + '<' + key + attrStr + '/' + this.tagEndChar;
257
- }
258
- }
259
-
260
- function indentate(level) {
261
- return this.options.indentBy.repeat(level);
262
- }
263
-
264
- function isAttribute(name /*, options*/) {
265
- if (name.startsWith(this.options.attributeNamePrefix)) {
266
- return name.substr(this.attrPrefixLen);
267
- } else {
268
- return false;
269
- }
270
- }
271
-
272
- function isCDATA(name) {
273
- return name === this.options.cdataTagName;
274
- }
275
-
276
- //formatting
277
- //indentation
278
- //\n after each closing or self closing tag
279
-
280
- module.exports = Parser;
@@ -1,144 +0,0 @@
1
- 'use strict';
2
- const char = function(a) {
3
- return String.fromCharCode(a);
4
- };
5
-
6
- const chars = {
7
- nilChar: char(176),
8
- missingChar: char(201),
9
- nilPremitive: char(175),
10
- missingPremitive: char(200),
11
-
12
- emptyChar: char(178),
13
- emptyValue: char(177), //empty Premitive
14
-
15
- boundryChar: char(179),
16
-
17
- objStart: char(198),
18
- arrStart: char(204),
19
- arrayEnd: char(185),
20
- };
21
-
22
- const charsArr = [
23
- chars.nilChar,
24
- chars.nilPremitive,
25
- chars.missingChar,
26
- chars.missingPremitive,
27
- chars.boundryChar,
28
- chars.emptyChar,
29
- chars.emptyValue,
30
- chars.arrayEnd,
31
- chars.objStart,
32
- chars.arrStart,
33
- ];
34
-
35
- const _e = function(node, e_schema, options) {
36
- if (typeof e_schema === 'string') {
37
- //premitive
38
- if (node && node[0] && node[0].val !== undefined) {
39
- return getValue(node[0].val, e_schema);
40
- } else {
41
- return getValue(node, e_schema);
42
- }
43
- } else {
44
- const hasValidData = hasData(node);
45
- if (hasValidData === true) {
46
- let str = '';
47
- if (Array.isArray(e_schema)) {
48
- //attributes can't be repeated. hence check in children tags only
49
- str += chars.arrStart;
50
- const itemSchema = e_schema[0];
51
- //const itemSchemaType = itemSchema;
52
- const arr_len = node.length;
53
-
54
- if (typeof itemSchema === 'string') {
55
- for (let arr_i = 0; arr_i < arr_len; arr_i++) {
56
- const r = getValue(node[arr_i].val, itemSchema);
57
- str = processValue(str, r);
58
- }
59
- } else {
60
- for (let arr_i = 0; arr_i < arr_len; arr_i++) {
61
- const r = _e(node[arr_i], itemSchema, options);
62
- str = processValue(str, r);
63
- }
64
- }
65
- str += chars.arrayEnd; //indicates that next item is not array item
66
- } else {
67
- //object
68
- str += chars.objStart;
69
- const keys = Object.keys(e_schema);
70
- if (Array.isArray(node)) {
71
- node = node[0];
72
- }
73
- for (let i in keys) {
74
- const key = keys[i];
75
- //a property defined in schema can be present either in attrsMap or children tags
76
- //options.textNodeName will not present in both maps, take it's value from val
77
- //options.attrNodeName will be present in attrsMap
78
- let r;
79
- if (!options.ignoreAttributes && node.attrsMap && node.attrsMap[key]) {
80
- r = _e(node.attrsMap[key], e_schema[key], options);
81
- } else if (key === options.textNodeName) {
82
- r = _e(node.val, e_schema[key], options);
83
- } else {
84
- r = _e(node.child[key], e_schema[key], options);
85
- }
86
- str = processValue(str, r);
87
- }
88
- }
89
- return str;
90
- } else {
91
- return hasValidData;
92
- }
93
- }
94
- };
95
-
96
- const getValue = function(a /*, type*/) {
97
- switch (a) {
98
- case undefined:
99
- return chars.missingPremitive;
100
- case null:
101
- return chars.nilPremitive;
102
- case '':
103
- return chars.emptyValue;
104
- default:
105
- return a;
106
- }
107
- };
108
-
109
- const processValue = function(str, r) {
110
- if (!isAppChar(r[0]) && !isAppChar(str[str.length - 1])) {
111
- str += chars.boundryChar;
112
- }
113
- return str + r;
114
- };
115
-
116
- const isAppChar = function(ch) {
117
- return charsArr.indexOf(ch) !== -1;
118
- };
119
-
120
- function hasData(jObj) {
121
- if (jObj === undefined) {
122
- return chars.missingChar;
123
- } else if (jObj === null) {
124
- return chars.nilChar;
125
- } else if (
126
- jObj.child &&
127
- Object.keys(jObj.child).length === 0 &&
128
- (!jObj.attrsMap || Object.keys(jObj.attrsMap).length === 0)
129
- ) {
130
- return chars.emptyChar;
131
- } else {
132
- return true;
133
- }
134
- }
135
-
136
- const x2j = require('./xmlstr2xmlnode');
137
- const buildOptions = require('./util').buildOptions;
138
-
139
- const convert2nimn = function(node, e_schema, options) {
140
- options = buildOptions(options, x2j.defaultOptions, x2j.props);
141
- return _e(node, e_schema, options);
142
- };
143
-
144
- exports.convert2nimn = convert2nimn;
@@ -1,42 +0,0 @@
1
- 'use strict';
2
-
3
- const util = require('./util');
4
-
5
- const convertToJson = function(node, options, parentTagName) {
6
- const jObj = {};
7
-
8
- // when no child node or attr is present
9
- if (!options.alwaysCreateTextNode && (!node.child || util.isEmptyObject(node.child)) && (!node.attrsMap || util.isEmptyObject(node.attrsMap))) {
10
- return util.isExist(node.val) ? node.val : '';
11
- }
12
-
13
- // otherwise create a textnode if node has some text
14
- if (util.isExist(node.val) && !(typeof node.val === 'string' && (node.val === '' || node.val === options.cdataPositionChar))) {
15
- const asArray = util.isTagNameInArrayMode(node.tagname, options.arrayMode, parentTagName)
16
- jObj[options.textNodeName] = asArray ? [node.val] : node.val;
17
- }
18
-
19
- util.merge(jObj, node.attrsMap, options.arrayMode);
20
-
21
- const keys = Object.keys(node.child);
22
- for (let index = 0; index < keys.length; index++) {
23
- const tagName = keys[index];
24
- if (node.child[tagName] && node.child[tagName].length > 1) {
25
- jObj[tagName] = [];
26
- for (let tag in node.child[tagName]) {
27
- if (node.child[tagName].hasOwnProperty(tag)) {
28
- jObj[tagName].push(convertToJson(node.child[tagName][tag], options, tagName));
29
- }
30
- }
31
- } else {
32
- const result = convertToJson(node.child[tagName][0], options, tagName);
33
- const asArray = (options.arrayMode === true && typeof result === 'object') || util.isTagNameInArrayMode(tagName, options.arrayMode, parentTagName);
34
- jObj[tagName] = asArray ? [result] : result;
35
- }
36
- }
37
-
38
- //add value
39
- return jObj;
40
- };
41
-
42
- exports.convertToJson = convertToJson;