node-red-contrib-tak-registration 0.7.2 → 0.8.0
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/README.md +1 -1
- package/node_modules/fast-xml-parser/CHANGELOG.md +561 -0
- package/node_modules/fast-xml-parser/README.md +134 -287
- package/node_modules/fast-xml-parser/package.json +17 -40
- package/node_modules/fast-xml-parser/{cli.js → src/cli/cli.js} +16 -24
- package/node_modules/fast-xml-parser/src/cli/man.js +12 -0
- package/node_modules/fast-xml-parser/src/fxp.d.ts +108 -0
- package/node_modules/fast-xml-parser/src/fxp.js +11 -0
- package/node_modules/fast-xml-parser/src/util.js +0 -36
- package/node_modules/fast-xml-parser/src/validator.js +15 -5
- package/node_modules/fast-xml-parser/src/xmlbuilder/json2xml.js +269 -0
- package/node_modules/fast-xml-parser/src/xmlbuilder/orderedJs2Xml.js +131 -0
- package/node_modules/fast-xml-parser/src/xmlbuilder/prettifyJs2Xml.js +0 -0
- package/node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js +152 -0
- package/node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js +48 -0
- package/node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js +589 -0
- package/node_modules/fast-xml-parser/src/xmlparser/XMLParser.js +58 -0
- package/node_modules/fast-xml-parser/src/xmlparser/node2json.js +113 -0
- package/node_modules/fast-xml-parser/src/xmlparser/xmlNode.js +25 -0
- package/package.json +2 -2
- package/tak-ingest.js +3 -2
- package/node_modules/fast-xml-parser/src/json2xml.js +0 -280
- package/node_modules/fast-xml-parser/src/nimndata.js +0 -144
- package/node_modules/fast-xml-parser/src/node2json.js +0 -42
- package/node_modules/fast-xml-parser/src/node2json_str.js +0 -63
- package/node_modules/fast-xml-parser/src/parser.d.ts +0 -79
- package/node_modules/fast-xml-parser/src/parser.js +0 -76
- package/node_modules/fast-xml-parser/src/xmlNode.js +0 -17
- package/node_modules/fast-xml-parser/src/xmlstr2xmlnode.js +0 -339
- /package/node_modules/fast-xml-parser/src/{read.js → cli/read.js} +0 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
const EOL = "\n";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {array} jArray
|
|
6
|
+
* @param {any} options
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
function toXml(jArray, options) {
|
|
10
|
+
let indentation = "";
|
|
11
|
+
if (options.format && options.indentBy.length > 0) {
|
|
12
|
+
indentation = EOL;
|
|
13
|
+
}
|
|
14
|
+
return arrToStr(jArray, options, "", indentation);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function arrToStr(arr, options, jPath, indentation) {
|
|
18
|
+
let xmlStr = "";
|
|
19
|
+
let isPreviousElementTag = false;
|
|
20
|
+
|
|
21
|
+
for (let i = 0; i < arr.length; i++) {
|
|
22
|
+
const tagObj = arr[i];
|
|
23
|
+
const tagName = propName(tagObj);
|
|
24
|
+
let newJPath = "";
|
|
25
|
+
if (jPath.length === 0) newJPath = tagName
|
|
26
|
+
else newJPath = `${jPath}.${tagName}`;
|
|
27
|
+
|
|
28
|
+
if (tagName === options.textNodeName) {
|
|
29
|
+
let tagText = tagObj[tagName];
|
|
30
|
+
if (!isStopNode(newJPath, options)) {
|
|
31
|
+
tagText = options.tagValueProcessor(tagName, tagText);
|
|
32
|
+
tagText = replaceEntitiesValue(tagText, options);
|
|
33
|
+
}
|
|
34
|
+
if (isPreviousElementTag) {
|
|
35
|
+
xmlStr += indentation;
|
|
36
|
+
}
|
|
37
|
+
xmlStr += tagText;
|
|
38
|
+
isPreviousElementTag = false;
|
|
39
|
+
continue;
|
|
40
|
+
} else if (tagName === options.cdataPropName) {
|
|
41
|
+
if (isPreviousElementTag) {
|
|
42
|
+
xmlStr += indentation;
|
|
43
|
+
}
|
|
44
|
+
xmlStr += `<![CDATA[${tagObj[tagName][0][options.textNodeName]}]]>`;
|
|
45
|
+
isPreviousElementTag = false;
|
|
46
|
+
continue;
|
|
47
|
+
} else if (tagName === options.commentPropName) {
|
|
48
|
+
xmlStr += indentation + `<!--${tagObj[tagName][0][options.textNodeName]}-->`;
|
|
49
|
+
isPreviousElementTag = true;
|
|
50
|
+
continue;
|
|
51
|
+
} else if (tagName[0] === "?") {
|
|
52
|
+
const attStr = attr_to_str(tagObj[":@"], options);
|
|
53
|
+
const tempInd = tagName === "?xml" ? "" : indentation;
|
|
54
|
+
let piTextNodeName = tagObj[tagName][0][options.textNodeName];
|
|
55
|
+
piTextNodeName = piTextNodeName.length !== 0 ? " " + piTextNodeName : ""; //remove extra spacing
|
|
56
|
+
xmlStr += tempInd + `<${tagName}${piTextNodeName}${attStr}?>`;
|
|
57
|
+
isPreviousElementTag = true;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
let newIdentation = indentation;
|
|
61
|
+
if (newIdentation !== "") {
|
|
62
|
+
newIdentation += options.indentBy;
|
|
63
|
+
}
|
|
64
|
+
const attStr = attr_to_str(tagObj[":@"], options);
|
|
65
|
+
const tagStart = indentation + `<${tagName}${attStr}`;
|
|
66
|
+
const tagValue = arrToStr(tagObj[tagName], options, newJPath, newIdentation);
|
|
67
|
+
if (options.unpairedTags.indexOf(tagName) !== -1) {
|
|
68
|
+
if (options.suppressUnpairedNode) xmlStr += tagStart + ">";
|
|
69
|
+
else xmlStr += tagStart + "/>";
|
|
70
|
+
} else if ((!tagValue || tagValue.length === 0) && options.suppressEmptyNode) {
|
|
71
|
+
xmlStr += tagStart + "/>";
|
|
72
|
+
} else if (tagValue && tagValue.endsWith(">")) {
|
|
73
|
+
xmlStr += tagStart + `>${tagValue}${indentation}</${tagName}>`;
|
|
74
|
+
} else {
|
|
75
|
+
xmlStr += tagStart + ">";
|
|
76
|
+
if (tagValue && indentation !== "" && (tagValue.includes("/>") || tagValue.includes("</"))) {
|
|
77
|
+
xmlStr += indentation + options.indentBy + tagValue + indentation;
|
|
78
|
+
} else {
|
|
79
|
+
xmlStr += tagValue;
|
|
80
|
+
}
|
|
81
|
+
xmlStr += `</${tagName}>`;
|
|
82
|
+
}
|
|
83
|
+
isPreviousElementTag = true;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return xmlStr;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function propName(obj) {
|
|
90
|
+
const keys = Object.keys(obj);
|
|
91
|
+
for (let i = 0; i < keys.length; i++) {
|
|
92
|
+
const key = keys[i];
|
|
93
|
+
if (key !== ":@") return key;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function attr_to_str(attrMap, options) {
|
|
98
|
+
let attrStr = "";
|
|
99
|
+
if (attrMap && !options.ignoreAttributes) {
|
|
100
|
+
for (let attr in attrMap) {
|
|
101
|
+
let attrVal = options.attributeValueProcessor(attr, attrMap[attr]);
|
|
102
|
+
attrVal = replaceEntitiesValue(attrVal, options);
|
|
103
|
+
if (attrVal === true && options.suppressBooleanAttributes) {
|
|
104
|
+
attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}`;
|
|
105
|
+
} else {
|
|
106
|
+
attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}="${attrVal}"`;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return attrStr;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function isStopNode(jPath, options) {
|
|
114
|
+
jPath = jPath.substr(0, jPath.length - options.textNodeName.length - 1);
|
|
115
|
+
let tagName = jPath.substr(jPath.lastIndexOf(".") + 1);
|
|
116
|
+
for (let index in options.stopNodes) {
|
|
117
|
+
if (options.stopNodes[index] === jPath || options.stopNodes[index] === "*." + tagName) return true;
|
|
118
|
+
}
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function replaceEntitiesValue(textValue, options) {
|
|
123
|
+
if (textValue && textValue.length > 0 && options.processEntities) {
|
|
124
|
+
for (let i = 0; i < options.entities.length; i++) {
|
|
125
|
+
const entity = options.entities[i];
|
|
126
|
+
textValue = textValue.replace(entity.regex, entity.val);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return textValue;
|
|
130
|
+
}
|
|
131
|
+
module.exports = toXml;
|
|
File without changes
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
const util = require('../util');
|
|
2
|
+
|
|
3
|
+
//TODO: handle comments
|
|
4
|
+
function readDocType(xmlData, i){
|
|
5
|
+
|
|
6
|
+
const entities = {};
|
|
7
|
+
if( xmlData[i + 3] === 'O' &&
|
|
8
|
+
xmlData[i + 4] === 'C' &&
|
|
9
|
+
xmlData[i + 5] === 'T' &&
|
|
10
|
+
xmlData[i + 6] === 'Y' &&
|
|
11
|
+
xmlData[i + 7] === 'P' &&
|
|
12
|
+
xmlData[i + 8] === 'E')
|
|
13
|
+
{
|
|
14
|
+
i = i+9;
|
|
15
|
+
let angleBracketsCount = 1;
|
|
16
|
+
let hasBody = false, comment = false;
|
|
17
|
+
let exp = "";
|
|
18
|
+
for(;i<xmlData.length;i++){
|
|
19
|
+
if (xmlData[i] === '<' && !comment) { //Determine the tag type
|
|
20
|
+
if( hasBody && isEntity(xmlData, i)){
|
|
21
|
+
i += 7;
|
|
22
|
+
[entityName, val,i] = readEntityExp(xmlData,i+1);
|
|
23
|
+
if(val.indexOf("&") === -1) //Parameter entities are not supported
|
|
24
|
+
entities[ validateEntityName(entityName) ] = {
|
|
25
|
+
regx : RegExp( `&${entityName};`,"g"),
|
|
26
|
+
val: val
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
else if( hasBody && isElement(xmlData, i)) i += 8;//Not supported
|
|
30
|
+
else if( hasBody && isAttlist(xmlData, i)) i += 8;//Not supported
|
|
31
|
+
else if( hasBody && isNotation(xmlData, i)) i += 9;//Not supported
|
|
32
|
+
else if( isComment) comment = true;
|
|
33
|
+
else throw new Error("Invalid DOCTYPE");
|
|
34
|
+
|
|
35
|
+
angleBracketsCount++;
|
|
36
|
+
exp = "";
|
|
37
|
+
} else if (xmlData[i] === '>') { //Read tag content
|
|
38
|
+
if(comment){
|
|
39
|
+
if( xmlData[i - 1] === "-" && xmlData[i - 2] === "-"){
|
|
40
|
+
comment = false;
|
|
41
|
+
angleBracketsCount--;
|
|
42
|
+
}
|
|
43
|
+
}else{
|
|
44
|
+
angleBracketsCount--;
|
|
45
|
+
}
|
|
46
|
+
if (angleBracketsCount === 0) {
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
}else if( xmlData[i] === '['){
|
|
50
|
+
hasBody = true;
|
|
51
|
+
}else{
|
|
52
|
+
exp += xmlData[i];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if(angleBracketsCount !== 0){
|
|
56
|
+
throw new Error(`Unclosed DOCTYPE`);
|
|
57
|
+
}
|
|
58
|
+
}else{
|
|
59
|
+
throw new Error(`Invalid Tag instead of DOCTYPE`);
|
|
60
|
+
}
|
|
61
|
+
return {entities, i};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function readEntityExp(xmlData,i){
|
|
65
|
+
//External entities are not supported
|
|
66
|
+
// <!ENTITY ext SYSTEM "http://normal-website.com" >
|
|
67
|
+
|
|
68
|
+
//Parameter entities are not supported
|
|
69
|
+
// <!ENTITY entityname "&anotherElement;">
|
|
70
|
+
|
|
71
|
+
//Internal entities are supported
|
|
72
|
+
// <!ENTITY entityname "replacement text">
|
|
73
|
+
|
|
74
|
+
//read EntityName
|
|
75
|
+
let entityName = "";
|
|
76
|
+
for (; i < xmlData.length && (xmlData[i] !== "'" && xmlData[i] !== '"' ); i++) {
|
|
77
|
+
// if(xmlData[i] === " ") continue;
|
|
78
|
+
// else
|
|
79
|
+
entityName += xmlData[i];
|
|
80
|
+
}
|
|
81
|
+
entityName = entityName.trim();
|
|
82
|
+
if(entityName.indexOf(" ") !== -1) throw new Error("External entites are not supported");
|
|
83
|
+
|
|
84
|
+
//read Entity Value
|
|
85
|
+
const startChar = xmlData[i++];
|
|
86
|
+
let val = ""
|
|
87
|
+
for (; i < xmlData.length && xmlData[i] !== startChar ; i++) {
|
|
88
|
+
val += xmlData[i];
|
|
89
|
+
}
|
|
90
|
+
return [entityName, val, i];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function isComment(xmlData, i){
|
|
94
|
+
if(xmlData[i+1] === '!' &&
|
|
95
|
+
xmlData[i+2] === '-' &&
|
|
96
|
+
xmlData[i+3] === '-') return true
|
|
97
|
+
return false
|
|
98
|
+
}
|
|
99
|
+
function isEntity(xmlData, i){
|
|
100
|
+
if(xmlData[i+1] === '!' &&
|
|
101
|
+
xmlData[i+2] === 'E' &&
|
|
102
|
+
xmlData[i+3] === 'N' &&
|
|
103
|
+
xmlData[i+4] === 'T' &&
|
|
104
|
+
xmlData[i+5] === 'I' &&
|
|
105
|
+
xmlData[i+6] === 'T' &&
|
|
106
|
+
xmlData[i+7] === 'Y') return true
|
|
107
|
+
return false
|
|
108
|
+
}
|
|
109
|
+
function isElement(xmlData, i){
|
|
110
|
+
if(xmlData[i+1] === '!' &&
|
|
111
|
+
xmlData[i+2] === 'E' &&
|
|
112
|
+
xmlData[i+3] === 'L' &&
|
|
113
|
+
xmlData[i+4] === 'E' &&
|
|
114
|
+
xmlData[i+5] === 'M' &&
|
|
115
|
+
xmlData[i+6] === 'E' &&
|
|
116
|
+
xmlData[i+7] === 'N' &&
|
|
117
|
+
xmlData[i+8] === 'T') return true
|
|
118
|
+
return false
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function isAttlist(xmlData, i){
|
|
122
|
+
if(xmlData[i+1] === '!' &&
|
|
123
|
+
xmlData[i+2] === 'A' &&
|
|
124
|
+
xmlData[i+3] === 'T' &&
|
|
125
|
+
xmlData[i+4] === 'T' &&
|
|
126
|
+
xmlData[i+5] === 'L' &&
|
|
127
|
+
xmlData[i+6] === 'I' &&
|
|
128
|
+
xmlData[i+7] === 'S' &&
|
|
129
|
+
xmlData[i+8] === 'T') return true
|
|
130
|
+
return false
|
|
131
|
+
}
|
|
132
|
+
function isNotation(xmlData, i){
|
|
133
|
+
if(xmlData[i+1] === '!' &&
|
|
134
|
+
xmlData[i+2] === 'N' &&
|
|
135
|
+
xmlData[i+3] === 'O' &&
|
|
136
|
+
xmlData[i+4] === 'T' &&
|
|
137
|
+
xmlData[i+5] === 'A' &&
|
|
138
|
+
xmlData[i+6] === 'T' &&
|
|
139
|
+
xmlData[i+7] === 'I' &&
|
|
140
|
+
xmlData[i+8] === 'O' &&
|
|
141
|
+
xmlData[i+9] === 'N') return true
|
|
142
|
+
return false
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function validateEntityName(name){
|
|
146
|
+
if (util.isName(name))
|
|
147
|
+
return name;
|
|
148
|
+
else
|
|
149
|
+
throw new Error(`Invalid entity name ${name}`);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
module.exports = readDocType;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
|
|
2
|
+
const defaultOptions = {
|
|
3
|
+
preserveOrder: false,
|
|
4
|
+
attributeNamePrefix: '@_',
|
|
5
|
+
attributesGroupName: false,
|
|
6
|
+
textNodeName: '#text',
|
|
7
|
+
ignoreAttributes: true,
|
|
8
|
+
removeNSPrefix: false, // remove NS from tag name or attribute name if true
|
|
9
|
+
allowBooleanAttributes: false, //a tag can have attributes without any value
|
|
10
|
+
//ignoreRootElement : false,
|
|
11
|
+
parseTagValue: true,
|
|
12
|
+
parseAttributeValue: false,
|
|
13
|
+
trimValues: true, //Trim string values of tag and attributes
|
|
14
|
+
cdataPropName: false,
|
|
15
|
+
numberParseOptions: {
|
|
16
|
+
hex: true,
|
|
17
|
+
leadingZeros: true,
|
|
18
|
+
eNotation: true
|
|
19
|
+
},
|
|
20
|
+
tagValueProcessor: function(tagName, val) {
|
|
21
|
+
return val;
|
|
22
|
+
},
|
|
23
|
+
attributeValueProcessor: function(attrName, val) {
|
|
24
|
+
return val;
|
|
25
|
+
},
|
|
26
|
+
stopNodes: [], //nested tags will not be parsed even for errors
|
|
27
|
+
alwaysCreateTextNode: false,
|
|
28
|
+
isArray: () => false,
|
|
29
|
+
commentPropName: false,
|
|
30
|
+
unpairedTags: [],
|
|
31
|
+
processEntities: true,
|
|
32
|
+
htmlEntities: false,
|
|
33
|
+
ignoreDeclaration: false,
|
|
34
|
+
ignorePiTags: false,
|
|
35
|
+
transformTagName: false,
|
|
36
|
+
transformAttributeName: false,
|
|
37
|
+
updateTag: function(tagName, jPath, attrs){
|
|
38
|
+
return tagName
|
|
39
|
+
},
|
|
40
|
+
// skipEmptyListItem: false
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const buildOptions = function(options) {
|
|
44
|
+
return Object.assign({}, defaultOptions, options);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
exports.buildOptions = buildOptions;
|
|
48
|
+
exports.defaultOptions = defaultOptions;
|