fast-xml-parser 4.0.4 → 4.0.7
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/CHANGELOG.md +12 -0
- package/README.md +3 -0
- package/package.json +1 -1
- package/src/xmlbuilder/json2xml.js +25 -18
- package/src/xmlbuilder/orderedJs2Xml.js +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
Note: If you find missing information about particular minor version, that version must have been changed without any functional change in this library.
|
|
2
2
|
|
|
3
|
+
**4.0.7 / 2022-03-18**
|
|
4
|
+
* support CDATA even if tag order is not preserved
|
|
5
|
+
* support Comments even if tag order is not preserved
|
|
6
|
+
* fix #446: XMLbuilder should not indent XML declaration
|
|
7
|
+
|
|
8
|
+
**4.0.6 / 2022-03-08**
|
|
9
|
+
* fix: call tagValueProcessor only once for array items
|
|
10
|
+
* fix: missing changed for #437
|
|
11
|
+
|
|
12
|
+
**4.0.5 / 2022-03-06**
|
|
13
|
+
* fix #437: call tagValueProcessor from XML builder
|
|
14
|
+
|
|
3
15
|
**4.0.4 / 2022-03-03**
|
|
4
16
|
* fix #435: should skip unpaired and self-closing nodes when set as stopnodes
|
|
5
17
|
|
package/README.md
CHANGED
|
@@ -18,6 +18,9 @@ Validate XML, Parse XML to JS Object, or Build XML from JS Object without C/C++
|
|
|
18
18
|
|
|
19
19
|
Check [ThankYouBackers](https://github.com/NaturalIntelligence/ThankYouBackers) for our contributors
|
|
20
20
|
|
|
21
|
+
>Want to focus more on opensource, further study, and family. So open for part-time good job in technical architect, node js backend developer, research assistant, or IT teacher. https://amitkumargupta.work/
|
|
22
|
+
|
|
23
|
+
[](https://github.com/NaturalIntelligence/ads/)
|
|
21
24
|
## Users
|
|
22
25
|
|
|
23
26
|
<a href="https://github.com/renovatebot/renovate" title="renovate" ><img src="https://avatars1.githubusercontent.com/u/38656520" width="60px" ></a>
|
package/package.json
CHANGED
|
@@ -156,7 +156,7 @@ function buildAttrPairStr(attrName, val){
|
|
|
156
156
|
function processTextOrObjNode (object, key, level) {
|
|
157
157
|
const result = this.j2x(object, level + 1);
|
|
158
158
|
if (object[this.options.textNodeName] !== undefined && Object.keys(object).length === 1) {
|
|
159
|
-
return this.buildTextNode(
|
|
159
|
+
return this.buildTextNode(object[this.options.textNodeName], key, result.attrStr, level);
|
|
160
160
|
} else {
|
|
161
161
|
return this.buildObjNode(result.val, key, result.attrStr, level);
|
|
162
162
|
}
|
|
@@ -172,11 +172,10 @@ function buildObjectNode(val, key, attrStr, level) {
|
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
if (attrStr && val.indexOf('<') === -1) {
|
|
175
|
-
return (
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
} else {
|
|
175
|
+
return ( this.indentate(level) + '<' + key + attrStr + piClosingChar + '>' + val + tagEndExp );
|
|
176
|
+
} else if (this.options.commentPropName !== false && key === this.options.commentPropName && piClosingChar.length === 0) {
|
|
177
|
+
return this.indentate(level) + `<!--${val}-->` + this.newLine;
|
|
178
|
+
}else {
|
|
180
179
|
return (
|
|
181
180
|
this.indentate(level) + '<' + key + attrStr + piClosingChar + this.tagEndChar +
|
|
182
181
|
val +
|
|
@@ -194,19 +193,27 @@ function buildEmptyObjNode(val, key, attrStr, level) {
|
|
|
194
193
|
}
|
|
195
194
|
|
|
196
195
|
function buildTextValNode(val, key, attrStr, level) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
if(
|
|
200
|
-
|
|
201
|
-
return this.indentate(level) + '<' + key + this.tagEndChar;
|
|
202
|
-
}else{
|
|
203
|
-
return this.indentate(level) + '<' + key + "/" + this.tagEndChar;
|
|
204
|
-
}
|
|
196
|
+
if (this.options.cdataPropName !== false && key === this.options.cdataPropName) {
|
|
197
|
+
return this.indentate(level) + `<![CDATA[${val}]]>` + this.newLine;
|
|
198
|
+
}else if (this.options.commentPropName !== false && key === this.options.commentPropName) {
|
|
199
|
+
return this.indentate(level) + `<!--${val}-->` + this.newLine;
|
|
205
200
|
}else{
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
201
|
+
let textValue = this.options.tagValueProcessor(key, val);
|
|
202
|
+
textValue = this.replaceEntitiesValue(textValue);
|
|
203
|
+
|
|
204
|
+
if( textValue === '' && this.options.unpairedTags.indexOf(key) !== -1){ //unpaired
|
|
205
|
+
if(this.options.suppressUnpairedNode){
|
|
206
|
+
return this.indentate(level) + '<' + key + this.tagEndChar;
|
|
207
|
+
}else{
|
|
208
|
+
return this.indentate(level) + '<' + key + "/" + this.tagEndChar;
|
|
209
|
+
}
|
|
210
|
+
} else{
|
|
211
|
+
return (
|
|
212
|
+
this.indentate(level) + '<' + key + attrStr + '>' +
|
|
213
|
+
textValue +
|
|
214
|
+
'</' + key + this.tagEndChar );
|
|
215
|
+
}
|
|
216
|
+
|
|
210
217
|
}
|
|
211
218
|
}
|
|
212
219
|
|
|
@@ -41,7 +41,10 @@ function arrToStr(arr, options, jPath, level){
|
|
|
41
41
|
continue;
|
|
42
42
|
}else if( tagName[0] === "?"){
|
|
43
43
|
const attStr = attr_to_str(tagObj[":@"], options);
|
|
44
|
-
|
|
44
|
+
const tempInd = tagName === "?xml" ? "" : indentation;
|
|
45
|
+
let piTextNodeName = tagObj[tagName][0][options.textNodeName];
|
|
46
|
+
piTextNodeName = piTextNodeName.length !== 0 ? " " + piTextNodeName : ""; //remove extra spacing
|
|
47
|
+
xmlStr += tempInd + `<${tagName}${piTextNodeName}${attStr}?>`;
|
|
45
48
|
continue;
|
|
46
49
|
}
|
|
47
50
|
const attStr = attr_to_str(tagObj[":@"], options);
|