fast-xml-parser 4.1.3 → 4.1.4
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 +5 -0
- package/README.md +1 -0
- package/package.json +1 -1
- package/src/fxp.d.ts +2 -1
- package/src/xmlbuilder/json2xml.js +12 -2
- package/src/xmlparser/node2json.js +13 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
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.1.4 / 2023-04-08**
|
|
4
|
+
* update typings to let user create XMLBuilder instance without options (#556) (By [Patrick](https://github.com/omggga))
|
|
5
|
+
* fix: IsArray option isn't parsing tags with 0 as value correctly #490 (#557) (By [Aleksandr Murashkin](https://github.com/p-kuen))
|
|
6
|
+
* feature: support oneListGroup to group repeated children tags udder single group
|
|
7
|
+
|
|
3
8
|
**4.1.3 / 2023-02-26**
|
|
4
9
|
* fix #546: Support complex entity value
|
|
5
10
|
|
package/README.md
CHANGED
|
@@ -54,6 +54,7 @@ Check [ThankYouBackers](https://github.com/NaturalIntelligence/ThankYouBackers)
|
|
|
54
54
|
<a href="http://www.magento.com/" title="Magento" > <img src="https://avatars2.githubusercontent.com/u/168457" width="60px" ></a>
|
|
55
55
|
<a href="https://github.com/SAP" title="SAP" > <img src="https://user-images.githubusercontent.com/7692328/204835214-d9d25b58-e3df-408d-87a3-c7d36b578ee4.png" width="60px" ></a>
|
|
56
56
|
<a href="https://github.com/postmanlabs" title="postman" > <img src="https://user-images.githubusercontent.com/7692328/204835529-e9e290ad-696a-49ad-9d34-08e955704715.png" width="60px" ></a>
|
|
57
|
+
<a href="https://github.com/react-native-community" title="React Native Community" > <img src="https://avatars.githubusercontent.com/u/20269980?v=4" width="60px" ></a>
|
|
57
58
|
|
|
58
59
|
Check the list of all known users [here](./USERs.md);
|
|
59
60
|
|
package/package.json
CHANGED
package/src/fxp.d.ts
CHANGED
|
@@ -65,6 +65,7 @@ type XmlBuilderOptions = {
|
|
|
65
65
|
tagValueProcessor: (name: string, value: unknown) => string;
|
|
66
66
|
attributeValueProcessor: (name: string, value: unknown) => string;
|
|
67
67
|
processEntities: boolean;
|
|
68
|
+
oneListGroup: boolean;
|
|
68
69
|
};
|
|
69
70
|
type XmlBuilderOptionsOptional = Partial<XmlBuilderOptions>;
|
|
70
71
|
|
|
@@ -94,6 +95,6 @@ export class XMLValidator{
|
|
|
94
95
|
static validate( xmlData: string, options?: validationOptionsOptional): true | ValidationError;
|
|
95
96
|
}
|
|
96
97
|
export class XMLBuilder {
|
|
97
|
-
constructor(options
|
|
98
|
+
constructor(options?: XmlBuilderOptionsOptional);
|
|
98
99
|
build(jObj: any): any;
|
|
99
100
|
}
|
|
@@ -33,6 +33,7 @@ const defaultOptions = {
|
|
|
33
33
|
stopNodes: [],
|
|
34
34
|
// transformTagName: false,
|
|
35
35
|
// transformAttributeName: false,
|
|
36
|
+
oneListGroup: false
|
|
36
37
|
};
|
|
37
38
|
|
|
38
39
|
function Builder(options) {
|
|
@@ -103,6 +104,7 @@ Builder.prototype.j2x = function(jObj, level) {
|
|
|
103
104
|
} else if (Array.isArray(jObj[key])) {
|
|
104
105
|
//repeated nodes
|
|
105
106
|
const arrLen = jObj[key].length;
|
|
107
|
+
let listTagVal = "";
|
|
106
108
|
for (let j = 0; j < arrLen; j++) {
|
|
107
109
|
const item = jObj[key][j];
|
|
108
110
|
if (typeof item === 'undefined') {
|
|
@@ -112,11 +114,19 @@ Builder.prototype.j2x = function(jObj, level) {
|
|
|
112
114
|
else val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
|
|
113
115
|
// val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
|
|
114
116
|
} else if (typeof item === 'object') {
|
|
115
|
-
|
|
117
|
+
if(this.options.oneListGroup ){
|
|
118
|
+
listTagVal += this.j2x(item, level + 1).val;
|
|
119
|
+
}else{
|
|
120
|
+
listTagVal += this.processTextOrObjNode(item, key, level)
|
|
121
|
+
}
|
|
116
122
|
} else {
|
|
117
|
-
|
|
123
|
+
listTagVal += this.buildTextValNode(item, key, '', level);
|
|
118
124
|
}
|
|
119
125
|
}
|
|
126
|
+
if(this.options.oneListGroup){
|
|
127
|
+
listTagVal = this.buildObjectNode(listTagVal, key, '', level);
|
|
128
|
+
}
|
|
129
|
+
val += listTagVal;
|
|
120
130
|
} else {
|
|
121
131
|
//nested node
|
|
122
132
|
if (this.options.attributesGroupName && key === this.options.attributesGroupName) {
|
|
@@ -94,8 +94,20 @@ function assignAttributes(obj, attrMap, jpath, options){
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
function isLeafTag(obj, options){
|
|
97
|
+
const { textNodeName } = options;
|
|
97
98
|
const propCount = Object.keys(obj).length;
|
|
98
|
-
|
|
99
|
+
|
|
100
|
+
if (propCount === 0) {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (
|
|
105
|
+
propCount === 1 &&
|
|
106
|
+
(obj[textNodeName] || typeof obj[textNodeName] === "boolean" || obj[textNodeName] === 0)
|
|
107
|
+
) {
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
|
|
99
111
|
return false;
|
|
100
112
|
}
|
|
101
113
|
exports.prettify = prettify;
|