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.
@@ -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,14 @@
1
+ /**
2
+ *
3
+ * @param {array} val
4
+ * @param {string} by
5
+ * @returns
6
+ */
7
+ function join(val, by=" "){
8
+ if(isArray(val)){
9
+ val.join(by)
10
+ }
11
+ return val;
12
+ }
13
+
14
+ module.exports = join;
@@ -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;
@@ -0,0 +1,8 @@
1
+ class trimmer{
2
+ parse(val){
3
+ if(typeof val === "string") return val.trim();
4
+ else return val;
5
+ }
6
+ }
7
+
8
+ module.exports = trimmer;
@@ -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