@depup/fast-xml-parser 5.5.6-depup.0

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.
Files changed (54) hide show
  1. package/CHANGELOG.md +752 -0
  2. package/LICENSE +21 -0
  3. package/README.md +31 -0
  4. package/changes.json +10 -0
  5. package/lib/fxbuilder.min.js +2 -0
  6. package/lib/fxbuilder.min.js.map +1 -0
  7. package/lib/fxp.cjs +1 -0
  8. package/lib/fxp.d.cts +595 -0
  9. package/lib/fxp.min.js +2 -0
  10. package/lib/fxp.min.js.map +1 -0
  11. package/lib/fxparser.min.js +2 -0
  12. package/lib/fxparser.min.js.map +1 -0
  13. package/lib/fxvalidator.min.js +2 -0
  14. package/lib/fxvalidator.min.js.map +1 -0
  15. package/package.json +112 -0
  16. package/src/cli/cli.js +97 -0
  17. package/src/cli/man.js +17 -0
  18. package/src/cli/read.js +43 -0
  19. package/src/fxp.d.ts +577 -0
  20. package/src/fxp.js +14 -0
  21. package/src/ignoreAttributes.js +18 -0
  22. package/src/util.js +61 -0
  23. package/src/v6/CharsSymbol.js +16 -0
  24. package/src/v6/EntitiesParser.js +106 -0
  25. package/src/v6/OptionsBuilder.js +61 -0
  26. package/src/v6/OutputBuilders/BaseOutputBuilder.js +69 -0
  27. package/src/v6/OutputBuilders/JsArrBuilder.js +103 -0
  28. package/src/v6/OutputBuilders/JsMinArrBuilder.js +100 -0
  29. package/src/v6/OutputBuilders/JsObjBuilder.js +154 -0
  30. package/src/v6/OutputBuilders/ParserOptionsBuilder.js +94 -0
  31. package/src/v6/Report.js +0 -0
  32. package/src/v6/TagPath.js +81 -0
  33. package/src/v6/TagPathMatcher.js +13 -0
  34. package/src/v6/XMLParser.js +83 -0
  35. package/src/v6/Xml2JsParser.js +235 -0
  36. package/src/v6/XmlPartReader.js +210 -0
  37. package/src/v6/XmlSpecialTagsReader.js +111 -0
  38. package/src/v6/inputSource/BufferSource.js +116 -0
  39. package/src/v6/inputSource/StringSource.js +121 -0
  40. package/src/v6/valueParsers/EntitiesParser.js +105 -0
  41. package/src/v6/valueParsers/booleanParser.js +22 -0
  42. package/src/v6/valueParsers/booleanParserExt.js +19 -0
  43. package/src/v6/valueParsers/currency.js +38 -0
  44. package/src/v6/valueParsers/join.js +13 -0
  45. package/src/v6/valueParsers/number.js +14 -0
  46. package/src/v6/valueParsers/trim.js +6 -0
  47. package/src/validator.js +425 -0
  48. package/src/xmlbuilder/json2xml.js +6 -0
  49. package/src/xmlparser/DocTypeReader.js +401 -0
  50. package/src/xmlparser/OptionsBuilder.js +159 -0
  51. package/src/xmlparser/OrderedObjParser.js +905 -0
  52. package/src/xmlparser/XMLParser.js +71 -0
  53. package/src/xmlparser/node2json.js +174 -0
  54. package/src/xmlparser/xmlNode.js +40 -0
@@ -0,0 +1,111 @@
1
+ import {readPiExp} from './XmlPartReader.js';
2
+
3
+ export function readCdata(parser){
4
+ //<![ are already read till this point
5
+ let str = parser.source.readStr(6); //CDATA[
6
+ parser.source.updateBufferBoundary(6);
7
+
8
+ if(str !== "CDATA[") throw new Error(`Invalid CDATA expression at ${parser.source.line}:${parser.source.cols}`);
9
+
10
+ let text = parser.source.readUpto("]]>");
11
+ parser.outputBuilder.addCdata(text);
12
+ }
13
+ export function readPiTag(parser){
14
+ //<? are already read till this point
15
+ let tagExp = readPiExp(parser, "?>");
16
+ if(!tagExp) throw new Error("Invalid Pi Tag expression.");
17
+
18
+ if (tagExp.tagName === "?xml") {//TODO: test if tagName is just xml
19
+ parser.outputBuilder.addDeclaration();
20
+ } else {
21
+ parser.outputBuilder.addPi("?"+tagExp.tagName);
22
+ }
23
+ }
24
+
25
+ export function readComment(parser){
26
+ //<!- are already read till this point
27
+ let ch = parser.source.readCh();
28
+ if(ch !== "-") throw new Error(`Invalid comment expression at ${parser.source.line}:${parser.source.cols}`);
29
+
30
+ let text = parser.source.readUpto("-->");
31
+ parser.outputBuilder.addComment(text);
32
+ }
33
+
34
+ const DOCTYPE_tags = {
35
+ "EL":/^EMENT\s+([^\s>]+)\s+(ANY|EMPTY|\(.+\)\s*$)/m,
36
+ "AT":/^TLIST\s+[^\s]+\s+[^\s]+\s+[^\s]+\s+[^\s]+\s+$/m,
37
+ "NO":/^TATION.+$/m
38
+ }
39
+ export function readDocType(parser){
40
+ //<!D are already read till this point
41
+ let str = parser.source.readStr(6); //OCTYPE
42
+ parser.source.updateBufferBoundary(6);
43
+
44
+ if(str !== "OCTYPE") throw new Error(`Invalid DOCTYPE expression at ${parser.source.line}:${parser.source.cols}`);
45
+
46
+ let hasBody = false, lastch = "";
47
+
48
+ while(parser.source.canRead()){
49
+ //TODO: use readChAt like used in partReader
50
+ let ch = parser.source.readCh();
51
+ if(hasBody){
52
+ if (ch === '<') { //Determine the tag type
53
+ let str = parser.source.readStr(2);
54
+ parser.source.updateBufferBoundary(2);
55
+ if(str === "EN"){ //ENTITY
56
+ let str = parser.source.readStr(4);
57
+ parser.source.updateBufferBoundary(4);
58
+ if(str !== "TITY") throw new Error("Invalid DOCTYPE ENTITY expression");
59
+
60
+ registerEntity(parser);
61
+ }else if(str === "!-") {//comment
62
+ readComment(parser);
63
+ }else{ //ELEMENT, ATTLIST, NOTATION
64
+ let dTagExp = parser.source.readUpto(">");
65
+ const regx = DOCTYPE_tags[str];
66
+ if(regx){
67
+ const match = dTagExp.match(regx);
68
+ if(!match) throw new Error("Invalid DOCTYPE");
69
+ }else throw new Error("Invalid DOCTYPE");
70
+ }
71
+ }else if( ch === '>' && lastch === "]"){//end of doctype
72
+ return;
73
+ }
74
+ }else if( ch === '>'){//end of doctype
75
+ return;
76
+ }else if( ch === '['){
77
+ hasBody = true;
78
+ }else{
79
+ lastch = ch;
80
+ }
81
+ }//End While loop
82
+
83
+ }
84
+
85
+ function registerEntity(parser){
86
+ //read Entity
87
+ let attrBoundary="";
88
+ let name ="", val ="";
89
+ while(source.canRead()){
90
+ let ch = source.readCh();
91
+
92
+ if(attrBoundary){
93
+ if (ch === attrBoundary){
94
+ val = text;
95
+ text = ""
96
+ }
97
+ }else if(ch === " " || ch === "\t"){
98
+ if(!name){
99
+ name = text.trimStart();
100
+ text = "";
101
+ }
102
+ }else if (ch === '"' || ch === "'") {//start of attrBoundary
103
+ attrBoundary = ch;
104
+ }else if(ch === ">"){
105
+ parser.entityParser.addExternalEntity(name,val);
106
+ return;
107
+ }else{
108
+ text+=ch;
109
+ }
110
+ }
111
+ }
@@ -0,0 +1,116 @@
1
+ const Constants = {
2
+ space: 32,
3
+ tab: 9
4
+ }
5
+ export default class BufferSource{
6
+ constructor(bytesArr){
7
+ this.line = 1;
8
+ this.cols = 0;
9
+ this.buffer = bytesArr;
10
+ this.startIndex = 0;
11
+ }
12
+
13
+
14
+
15
+ readCh() {
16
+ return String.fromCharCode(this.buffer[this.startIndex++]);
17
+ }
18
+
19
+ readChAt(index) {
20
+ return String.fromCharCode(this.buffer[this.startIndex+index]);
21
+ }
22
+
23
+ readStr(n,from){
24
+ if(typeof from === "undefined") from = this.startIndex;
25
+ return this.buffer.slice(from, from + n).toString();
26
+ }
27
+
28
+ readUpto(stopStr) {
29
+ const inputLength = this.buffer.length;
30
+ const stopLength = stopStr.length;
31
+ const stopBuffer = Buffer.from(stopStr);
32
+
33
+ for (let i = this.startIndex; i < inputLength; i++) {
34
+ let match = true;
35
+ for (let j = 0; j < stopLength; j++) {
36
+ if (this.buffer[i + j] !== stopBuffer[j]) {
37
+ match = false;
38
+ break;
39
+ }
40
+ }
41
+
42
+ if (match) {
43
+ const result = this.buffer.slice(this.startIndex, i).toString();
44
+ this.startIndex = i + stopLength;
45
+ return result;
46
+ }
47
+ }
48
+
49
+ throw new Error(`Unexpected end of source. Reading '${stopStr}'`);
50
+ }
51
+
52
+ readUptoCloseTag(stopStr) { //stopStr: "</tagname"
53
+ const inputLength = this.buffer.length;
54
+ const stopLength = stopStr.length;
55
+ const stopBuffer = Buffer.from(stopStr);
56
+ let stopIndex = 0;
57
+ //0: non-matching, 1: matching stop string, 2: matching closing
58
+ let match = 0;
59
+
60
+ for (let i = this.startIndex; i < inputLength; i++) {
61
+ if(match === 1){//initial part matched
62
+ if(stopIndex === 0) stopIndex = i;
63
+ if(this.buffer[i] === Constants.space || this.buffer[i] === Constants.tab) continue;
64
+ else if(this.buffer[i] === '>'){ //TODO: if it should be equivalent ASCII
65
+ match = 2;
66
+ //tag boundary found
67
+ // this.startIndex
68
+ }
69
+ }else{
70
+ match = 1;
71
+ for (let j = 0; j < stopLength; j++) {
72
+ if (this.buffer[i + j] !== stopBuffer[j]) {
73
+ match = 0;
74
+ break;
75
+ }
76
+ }
77
+ }
78
+ if (match === 2) {//matched closing part
79
+ const result = this.buffer.slice(this.startIndex, stopIndex - 1 ).toString();
80
+ this.startIndex = i + 1;
81
+ return result;
82
+ }
83
+ }
84
+
85
+ throw new Error(`Unexpected end of source. Reading '${stopStr}'`);
86
+ }
87
+
88
+ readFromBuffer(n, shouldUpdate) {
89
+ let ch;
90
+ if (n === 1) {
91
+ ch = this.buffer[this.startIndex];
92
+ if (ch === 10) {
93
+ this.line++;
94
+ this.cols = 1;
95
+ } else {
96
+ this.cols++;
97
+ }
98
+ ch = String.fromCharCode(ch);
99
+ } else {
100
+ this.cols += n;
101
+ ch = this.buffer.slice(this.startIndex, this.startIndex + n).toString();
102
+ }
103
+ if (shouldUpdate) this.updateBuffer(n);
104
+ return ch;
105
+ }
106
+
107
+ updateBufferBoundary(n = 1) { //n: number of characters read
108
+ this.startIndex += n;
109
+ }
110
+
111
+ canRead(n){
112
+ n = n || this.startIndex;
113
+ return this.buffer.length - n + 1 > 0;
114
+ }
115
+
116
+ }
@@ -0,0 +1,121 @@
1
+ const whiteSpaces = [" ", "\n", "\t"];
2
+
3
+
4
+ export default class StringSource{
5
+ constructor(str){
6
+ this.line = 1;
7
+ this.cols = 0;
8
+ this.buffer = str;
9
+ //a boundary pointer to indicate where from the buffer dat should be read
10
+ // data before this pointer can be deleted to free the memory
11
+ this.startIndex = 0;
12
+ }
13
+
14
+ readCh() {
15
+ return this.buffer[this.startIndex++];
16
+ }
17
+
18
+ readChAt(index) {
19
+ return this.buffer[this.startIndex+index];
20
+ }
21
+
22
+ readStr(n,from){
23
+ if(typeof from === "undefined") from = this.startIndex;
24
+ return this.buffer.substring(from, from + n);
25
+ }
26
+
27
+ readUpto(stopStr) {
28
+ const inputLength = this.buffer.length;
29
+ const stopLength = stopStr.length;
30
+
31
+ for (let i = this.startIndex; i < inputLength; i++) {
32
+ let match = true;
33
+ for (let j = 0; j < stopLength; j++) {
34
+ if (this.buffer[i + j] !== stopStr[j]) {
35
+ match = false;
36
+ break;
37
+ }
38
+ }
39
+
40
+ if (match) {
41
+ const result = this.buffer.substring(this.startIndex, i);
42
+ this.startIndex = i + stopLength;
43
+ return result;
44
+ }
45
+ }
46
+
47
+ throw new Error(`Unexpected end of source. Reading '${stopStr}'`);
48
+ }
49
+
50
+ readUptoCloseTag(stopStr) { //stopStr: "</tagname"
51
+ const inputLength = this.buffer.length;
52
+ const stopLength = stopStr.length;
53
+ let stopIndex = 0;
54
+ //0: non-matching, 1: matching stop string, 2: matching closing
55
+ let match = 0;
56
+
57
+ for (let i = this.startIndex; i < inputLength; i++) {
58
+ if(match === 1){//initial part matched
59
+ if(stopIndex === 0) stopIndex = i;
60
+ if(this.buffer[i] === ' ' || this.buffer[i] === '\t') continue;
61
+ else if(this.buffer[i] === '>'){
62
+ match = 2;
63
+ //tag boundary found
64
+ // this.startIndex
65
+ }
66
+ }else{
67
+ match = 1;
68
+ for (let j = 0; j < stopLength; j++) {
69
+ if (this.buffer[i + j] !== stopStr[j]) {
70
+ match = 0;
71
+ break;
72
+ }
73
+ }
74
+ }
75
+ if (match === 2) {//matched closing part
76
+ const result = this.buffer.substring(this.startIndex, stopIndex - 1 );
77
+ this.startIndex = i + 1;
78
+ return result;
79
+ }
80
+ }
81
+
82
+ throw new Error(`Unexpected end of source. Reading '${stopStr}'`);
83
+ }
84
+
85
+ readFromBuffer(n, updateIndex){
86
+ let ch;
87
+ if(n===1){
88
+ ch = this.buffer[this.startIndex];
89
+ // if(ch === "\n") {
90
+ // this.line++;
91
+ // this.cols = 1;
92
+ // }else{
93
+ // this.cols++;
94
+ // }
95
+ }else{
96
+ ch = this.buffer.substring(this.startIndex, this.startIndex + n);
97
+ // if("".indexOf("\n") !== -1){
98
+ // //TODO: handle the scenario when there are multiple lines
99
+ // //TODO: col should be set to number of chars after last '\n'
100
+ // // this.cols = 1;
101
+ // }else{
102
+ // this.cols += n;
103
+
104
+ // }
105
+ }
106
+ if(updateIndex) this.updateBufferBoundary(n);
107
+ return ch;
108
+ }
109
+
110
+ //TODO: rename to updateBufferReadIndex
111
+
112
+ updateBufferBoundary(n = 1) { //n: number of characters read
113
+ this.startIndex += n;
114
+ }
115
+
116
+ canRead(n){
117
+ n = n || this.startIndex;
118
+ return this.buffer.length - n + 1 > 0;
119
+ }
120
+
121
+ }
@@ -0,0 +1,105 @@
1
+ const ampEntity = { regex: /&(amp|#38|#x26);/g, val: "&" };
2
+ const htmlEntities = {
3
+ "space": { regex: /&(nbsp|#160);/g, val: " " },
4
+ // "lt" : { regex: /&(lt|#60);/g, val: "<" },
5
+ // "gt" : { regex: /&(gt|#62);/g, val: ">" },
6
+ // "amp" : { regex: /&(amp|#38);/g, val: "&" },
7
+ // "quot" : { regex: /&(quot|#34);/g, val: "\"" },
8
+ // "apos" : { regex: /&(apos|#39);/g, val: "'" },
9
+ "cent": { regex: /&(cent|#162);/g, val: "¢" },
10
+ "pound": { regex: /&(pound|#163);/g, val: "£" },
11
+ "yen": { regex: /&(yen|#165);/g, val: "¥" },
12
+ "euro": { regex: /&(euro|#8364);/g, val: "€" },
13
+ "copyright": { regex: /&(copy|#169);/g, val: "©" },
14
+ "reg": { regex: /&(reg|#174);/g, val: "®" },
15
+ "inr": { regex: /&(inr|#8377);/g, val: "₹" },
16
+ "num_dec": { regex: /&#([0-9]{1,7});/g, val: (_, str) => String.fromCodePoint(Number.parseInt(str, 10)) },
17
+ "num_hex": { regex: /&#x([0-9a-fA-F]{1,6});/g, val: (_, str) => String.fromCodePoint(Number.parseInt(str, 16)) },
18
+ };
19
+
20
+ export default class EntitiesParser {
21
+ constructor(replaceHtmlEntities) {
22
+ this.replaceHtmlEntities = replaceHtmlEntities;
23
+ this.docTypeEntities = {};
24
+ this.lastEntities = {
25
+ "apos": { regex: /&(apos|#39|#x27);/g, val: "'" },
26
+ "gt": { regex: /&(gt|#62|#x3E);/g, val: ">" },
27
+ "lt": { regex: /&(lt|#60|#x3C);/g, val: "<" },
28
+ "quot": { regex: /&(quot|#34|#x22);/g, val: "\"" },
29
+ };
30
+ }
31
+
32
+ addExternalEntities(externalEntities) {
33
+ const entKeys = Object.keys(externalEntities);
34
+ for (let i = 0; i < entKeys.length; i++) {
35
+ const ent = entKeys[i];
36
+ this.addExternalEntity(ent, externalEntities[ent])
37
+ }
38
+ }
39
+ addExternalEntity(key, val) {
40
+ validateEntityName(key);
41
+ if (val.indexOf("&") !== -1) {
42
+ reportWarning(`Entity ${key} is not added as '&' is found in value;`)
43
+ return;
44
+ } else {
45
+ this.lastEntities[ent] = {
46
+ regex: new RegExp("&" + key + ";", "g"),
47
+ val: val
48
+ }
49
+ }
50
+ }
51
+
52
+ addDocTypeEntities(entities) {
53
+ const entKeys = Object.keys(entities);
54
+ for (let i = 0; i < entKeys.length; i++) {
55
+ const ent = entKeys[i];
56
+ this.docTypeEntities[ent] = {
57
+ regex: new RegExp("&" + ent + ";", "g"),
58
+ val: entities[ent]
59
+ }
60
+ }
61
+ }
62
+
63
+ parse(val) {
64
+ return this.replaceEntitiesValue(val)
65
+ }
66
+
67
+ /**
68
+ * 1. Replace DOCTYPE entities
69
+ * 2. Replace external entities
70
+ * 3. Replace HTML entities if asked
71
+ * @param {string} val
72
+ */
73
+ replaceEntitiesValue(val) {
74
+ if (typeof val === "string" && val.length > 0) {
75
+ for (let entityName in this.docTypeEntities) {
76
+ const entity = this.docTypeEntities[entityName];
77
+ val = val.replace(entity.regx, entity.val);
78
+ }
79
+ for (let entityName in this.lastEntities) {
80
+ const entity = this.lastEntities[entityName];
81
+ val = val.replace(entity.regex, entity.val);
82
+ }
83
+ if (this.replaceHtmlEntities) {
84
+ for (let entityName in htmlEntities) {
85
+ const entity = htmlEntities[entityName];
86
+ val = val.replace(entity.regex, entity.val);
87
+ }
88
+ }
89
+ val = val.replace(ampEntity.regex, ampEntity.val);
90
+ }
91
+ return val;
92
+ }
93
+ };
94
+
95
+ //an entity name should not contains special characters that may be used in regex
96
+ //Eg !?\\\/[]$%{}^&*()<>
97
+ const specialChar = "!?\\\/[]$%{}^&*()<>|+";
98
+
99
+ function validateEntityName(name) {
100
+ for (let i = 0; i < specialChar.length; i++) {
101
+ const ch = specialChar[i];
102
+ if (name.indexOf(ch) !== -1) throw new Error(`Invalid character ${ch} in entity name`);
103
+ }
104
+ return name;
105
+ }
@@ -0,0 +1,22 @@
1
+ export default class boolParser{
2
+ constructor(trueList, falseList){
3
+ if(trueList)
4
+ this.trueList = trueList;
5
+ else
6
+ this.trueList = ["true"];
7
+
8
+ if(falseList)
9
+ this.falseList = falseList;
10
+ else
11
+ this.falseList = ["false"];
12
+ }
13
+ parse(val){
14
+ if (typeof val === 'string') {
15
+ //TODO: performance: don't convert
16
+ const temp = val.toLowerCase();
17
+ if(this.trueList.indexOf(temp) !== -1) return true;
18
+ else if(this.falseList.indexOf(temp) !== -1 ) return false;
19
+ }
20
+ return val;
21
+ }
22
+ }
@@ -0,0 +1,19 @@
1
+ export default 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
+ }
@@ -0,0 +1,38 @@
1
+ const defaultOptions = {
2
+ maxLength: 200,
3
+ // locale: "en-IN"
4
+ }
5
+ const localeMap = {
6
+ "$":"en-US",
7
+ "€":"de-DE",
8
+ "£":"en-GB",
9
+ "¥":"ja-JP",
10
+ "₹":"en-IN",
11
+ }
12
+ const sign = "(?:-|\+)?";
13
+ const digitsAndSeparator = "(?:\d+|\d{1,3}(?:,\d{3})+)";
14
+ const decimalPart = "(?:\.\d{1,2})?";
15
+ const symbol = "(?:\$|€|¥|₹)?";
16
+
17
+ const currencyCheckRegex = /^\s*(?:-|\+)?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d{1,2})?\s*(?:\$|€|¥|₹)?\s*$/u;
18
+
19
+ export default class CurrencyParser{
20
+ constructor(options){
21
+ this.options = options || defaultOptions;
22
+ }
23
+ parse(val){
24
+ if (typeof val === 'string' && val.length <= this.options.maxLength) {
25
+ if(val.indexOf(",,") !== -1 && val.indexOf(".." !== -1)){
26
+ const match = val.match(currencyCheckRegex);
27
+ if(match){
28
+ const locale = this.options.locale || localeMap[match[2]||match[5]||"₹"];
29
+ const formatter = new Intl.NumberFormat(locale)
30
+ val = val.replace(/[^0-9,.]/g, '').trim();
31
+ val = Number(val.replace(formatter.format(1000)[1], ''));
32
+ }
33
+ }
34
+ }
35
+ return val;
36
+ }
37
+ }
38
+ CurrencyParser.defaultOptions = defaultOptions;
@@ -0,0 +1,13 @@
1
+ /**
2
+ *
3
+ * @param {array} val
4
+ * @param {string} by
5
+ * @returns
6
+ */
7
+ export default function join(val, by=" "){
8
+ if(isArray(val)){
9
+ val.join(by)
10
+ }
11
+ return val;
12
+ }
13
+
@@ -0,0 +1,14 @@
1
+ import toNumber from "strnum";
2
+
3
+
4
+ export default 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
+ }
@@ -0,0 +1,6 @@
1
+ export default class trimmer{
2
+ parse(val){
3
+ if(typeof val === "string") return val.trim();
4
+ else return val;
5
+ }
6
+ }