fast-xml-parser 4.3.3 → 4.3.5
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 +6 -0
- package/README.md +7 -14
- package/package.json +1 -1
- package/src/fxp.d.ts +2 -2
- package/src/v5/CharsSymbol.js +16 -0
- package/src/v5/EntitiesParser.js +105 -0
- package/src/v5/OptionsBuilder.js +73 -0
- package/src/v5/OutputBuilders/BaseOutputBuilder.js +69 -0
- package/src/v5/OutputBuilders/JsArrBuilder.js +102 -0
- package/src/v5/OutputBuilders/JsMinArrBuilder.js +101 -0
- package/src/v5/OutputBuilders/JsObjBuilder.js +155 -0
- package/src/v5/OutputBuilders/ParserOptionsBuilder.js +94 -0
- package/src/v5/Report.js +0 -0
- package/src/v5/TagPath.js +81 -0
- package/src/v5/TagPathMatcher.js +15 -0
- package/src/v5/XMLParser.js +85 -0
- package/src/v5/Xml2JsParser.js +237 -0
- package/src/v5/XmlPartReader.js +212 -0
- package/src/v5/XmlSpecialTagsReader.js +118 -0
- package/src/v5/inputSource/BufferSource.js +118 -0
- package/src/v5/inputSource/StringSource.js +123 -0
- package/src/v5/valueParsers/EntitiesParser.js +105 -0
- package/src/v5/valueParsers/booleanParser.js +23 -0
- package/src/v5/valueParsers/booleanParserExt.js +20 -0
- package/src/v5/valueParsers/currency.js +31 -0
- package/src/v5/valueParsers/join.js +14 -0
- package/src/v5/valueParsers/number.js +16 -0
- package/src/v5/valueParsers/trim.js +8 -0
- package/src/xmlparser/OrderedObjParser.js +3 -4
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
function boolParserExt(val){
|
|
2
|
+
if(isArray(val)){
|
|
3
|
+
for (let i = 0; i < val.length; i++) {
|
|
4
|
+
val[i] = parse(val[i])
|
|
5
|
+
}
|
|
6
|
+
}else{
|
|
7
|
+
val = parse(val)
|
|
8
|
+
}
|
|
9
|
+
return val;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function parse(val){
|
|
13
|
+
if (typeof val === 'string') {
|
|
14
|
+
const temp = val.toLowerCase();
|
|
15
|
+
if(temp === 'true' || temp ==="yes" || temp==="1") return true;
|
|
16
|
+
else if(temp === 'false' || temp ==="no" || temp==="0") return false;
|
|
17
|
+
}
|
|
18
|
+
return val;
|
|
19
|
+
}
|
|
20
|
+
module.exports = boolParserExt;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
const localeMap = {
|
|
3
|
+
"$":"en-US",
|
|
4
|
+
"€":"de-DE",
|
|
5
|
+
"£":"en-GB",
|
|
6
|
+
"¥":"ja-JP",
|
|
7
|
+
"₹":"en-IN",
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const currencyCheckRegex = /^\s*(?:-|\+)?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d{1,2})?\s*(?:\$|€|¥|₹)?\s*$/u;
|
|
11
|
+
|
|
12
|
+
class CurrencyParser{
|
|
13
|
+
constructor(options){
|
|
14
|
+
this.options = options;
|
|
15
|
+
}
|
|
16
|
+
parse(val){
|
|
17
|
+
if (typeof val === 'string') {
|
|
18
|
+
if(val.indexOf(",,") !== -1 && val.indexOf(".." !== -1)){
|
|
19
|
+
const match = val.match(currencyCheckRegex);
|
|
20
|
+
if(match){
|
|
21
|
+
const locale = this.options.locale || localeMap[match[2]||match[5]||"₹"];
|
|
22
|
+
const formatter = new Intl.NumberFormat(locale)
|
|
23
|
+
val = val.replace(/[^0-9,.]/g, '').trim();
|
|
24
|
+
val = Number(val.replace(formatter.format(1000)[1], ''));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return val;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
module.exports = CurrencyParser;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const toNumber = require("strnum");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class numParser{
|
|
5
|
+
constructor(options){
|
|
6
|
+
this.options = options;
|
|
7
|
+
}
|
|
8
|
+
parse(val){
|
|
9
|
+
if (typeof val === 'string') {
|
|
10
|
+
val = toNumber(val,this.options);
|
|
11
|
+
}
|
|
12
|
+
return val;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
module.exports = numParser;
|
|
@@ -265,14 +265,13 @@ const parseXml = function(xmlData) {
|
|
|
265
265
|
|
|
266
266
|
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
267
267
|
|
|
268
|
+
let val = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true, true);
|
|
269
|
+
if(val == undefined) val = "";
|
|
270
|
+
|
|
268
271
|
//cdata should be set even if it is 0 length string
|
|
269
272
|
if(this.options.cdataPropName){
|
|
270
|
-
// let val = this.parseTextData(tagExp, this.options.cdataPropName, jPath + "." + this.options.cdataPropName, true, false, true);
|
|
271
|
-
// if(!val) val = "";
|
|
272
273
|
currentNode.add(this.options.cdataPropName, [ { [this.options.textNodeName] : tagExp } ]);
|
|
273
274
|
}else{
|
|
274
|
-
let val = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true);
|
|
275
|
-
if(val == undefined) val = "";
|
|
276
275
|
currentNode.add(this.options.textNodeName, val);
|
|
277
276
|
}
|
|
278
277
|
|