fast-xml-parser 4.3.4 → 4.3.6

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;
@@ -40,6 +40,8 @@ class OrderedObjParser{
40
40
  "copyright" : { regex: /&(copy|#169);/g, val: "©" },
41
41
  "reg" : { regex: /&(reg|#174);/g, val: "®" },
42
42
  "inr" : { regex: /&(inr|#8377);/g, val: "₹" },
43
+ "num_dec": { regex: /&#([0-9]{1,7});/g, val : (_, str) => String.fromCharCode(Number.parseInt(str, 10)) },
44
+ "num_hex": { regex: /&#x([0-9a-fA-F]{1,6});/g, val : (_, str) => String.fromCharCode(Number.parseInt(str, 16)) },
43
45
  };
44
46
  this.addExternalEntities = addExternalEntities;
45
47
  this.parseXml = parseXml;