@abaplint/cli 2.113.105 → 2.113.107
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/build/cli.js +169 -2145
- package/package.json +3 -3
package/build/cli.js
CHANGED
|
@@ -45797,7 +45797,7 @@ exports.ABAPObject = ABAPObject;
|
|
|
45797
45797
|
|
|
45798
45798
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
45799
45799
|
exports.AbstractObject = void 0;
|
|
45800
|
-
const fast_xml_parser_1 = __webpack_require__(/*! fast-xml-parser */ "./node_modules/fast-xml-parser/
|
|
45800
|
+
const fast_xml_parser_1 = __webpack_require__(/*! fast-xml-parser */ "./node_modules/fast-xml-parser/lib/fxp.cjs");
|
|
45801
45801
|
const _identifier_1 = __webpack_require__(/*! ../abap/4_file_information/_identifier */ "./node_modules/@abaplint/core/build/src/abap/4_file_information/_identifier.js");
|
|
45802
45802
|
const identifier_1 = __webpack_require__(/*! ../abap/1_lexer/tokens/identifier */ "./node_modules/@abaplint/core/build/src/abap/1_lexer/tokens/identifier.js");
|
|
45803
45803
|
const position_1 = __webpack_require__(/*! ../position */ "./node_modules/@abaplint/core/build/src/position.js");
|
|
@@ -45937,6 +45937,7 @@ function parseDynpros(parsed) {
|
|
|
45937
45937
|
number: d.HEADER.SCREEN,
|
|
45938
45938
|
description: d.HEADER.DESCRIPT,
|
|
45939
45939
|
nextScreen: d.HEADER.NEXTSCREEN,
|
|
45940
|
+
type: d.HEADER.TYPE,
|
|
45940
45941
|
fields: fields,
|
|
45941
45942
|
});
|
|
45942
45943
|
}
|
|
@@ -48437,7 +48438,7 @@ exports.FunctionGroup = void 0;
|
|
|
48437
48438
|
const _abap_object_1 = __webpack_require__(/*! ./_abap_object */ "./node_modules/@abaplint/core/build/src/objects/_abap_object.js");
|
|
48438
48439
|
const types_1 = __webpack_require__(/*! ../abap/types */ "./node_modules/@abaplint/core/build/src/abap/types/index.js");
|
|
48439
48440
|
const xml_utils_1 = __webpack_require__(/*! ../xml_utils */ "./node_modules/@abaplint/core/build/src/xml_utils.js");
|
|
48440
|
-
const fast_xml_parser_1 = __webpack_require__(/*! fast-xml-parser */ "./node_modules/fast-xml-parser/
|
|
48441
|
+
const fast_xml_parser_1 = __webpack_require__(/*! fast-xml-parser */ "./node_modules/fast-xml-parser/lib/fxp.cjs");
|
|
48441
48442
|
const _dynpros_1 = __webpack_require__(/*! ./_dynpros */ "./node_modules/@abaplint/core/build/src/objects/_dynpros.js");
|
|
48442
48443
|
class FunctionGroup extends _abap_object_1.ABAPObject {
|
|
48443
48444
|
constructor() {
|
|
@@ -52944,8 +52945,9 @@ class TypePool extends _abap_object_1.ABAPObject {
|
|
|
52944
52945
|
};
|
|
52945
52946
|
}
|
|
52946
52947
|
getDescription() {
|
|
52947
|
-
|
|
52948
|
-
|
|
52948
|
+
var _a, _b, _c;
|
|
52949
|
+
const parsed = super.parseRaw2();
|
|
52950
|
+
return ((_c = (_b = (_a = parsed === null || parsed === void 0 ? void 0 : parsed.abapGit) === null || _a === void 0 ? void 0 : _a["asx:abap"]) === null || _b === void 0 ? void 0 : _b["asx:values"]) === null || _c === void 0 ? void 0 : _c.DDTEXT) || "";
|
|
52949
52951
|
}
|
|
52950
52952
|
}
|
|
52951
52953
|
exports.TypePool = TypePool;
|
|
@@ -53850,7 +53852,7 @@ class Registry {
|
|
|
53850
53852
|
}
|
|
53851
53853
|
static abaplintVersion() {
|
|
53852
53854
|
// magic, see build script "version.sh"
|
|
53853
|
-
return "2.113.
|
|
53855
|
+
return "2.113.107";
|
|
53854
53856
|
}
|
|
53855
53857
|
getDDICReferences() {
|
|
53856
53858
|
return this.ddicReferences;
|
|
@@ -71582,7 +71584,7 @@ exports.ReleaseIdoc = ReleaseIdoc;
|
|
|
71582
71584
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
71583
71585
|
exports.RemoveDescriptions = exports.RemoveDescriptionsConf = void 0;
|
|
71584
71586
|
const issue_1 = __webpack_require__(/*! ../issue */ "./node_modules/@abaplint/core/build/src/issue.js");
|
|
71585
|
-
const fast_xml_parser_1 = __webpack_require__(/*! fast-xml-parser */ "./node_modules/fast-xml-parser/
|
|
71587
|
+
const fast_xml_parser_1 = __webpack_require__(/*! fast-xml-parser */ "./node_modules/fast-xml-parser/lib/fxp.cjs");
|
|
71586
71588
|
const Objects = __webpack_require__(/*! ../objects */ "./node_modules/@abaplint/core/build/src/objects/index.js");
|
|
71587
71589
|
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "./node_modules/@abaplint/core/build/src/rules/_basic_rule_config.js");
|
|
71588
71590
|
const position_1 = __webpack_require__(/*! ../position */ "./node_modules/@abaplint/core/build/src/position.js");
|
|
@@ -76492,7 +76494,7 @@ const issue_1 = __webpack_require__(/*! ../issue */ "./node_modules/@abaplint/co
|
|
|
76492
76494
|
const _irule_1 = __webpack_require__(/*! ./_irule */ "./node_modules/@abaplint/core/build/src/rules/_irule.js");
|
|
76493
76495
|
const Objects = __webpack_require__(/*! ../objects */ "./node_modules/@abaplint/core/build/src/objects/index.js");
|
|
76494
76496
|
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "./node_modules/@abaplint/core/build/src/rules/_basic_rule_config.js");
|
|
76495
|
-
const fast_xml_parser_1 = __webpack_require__(/*! fast-xml-parser */ "./node_modules/fast-xml-parser/
|
|
76497
|
+
const fast_xml_parser_1 = __webpack_require__(/*! fast-xml-parser */ "./node_modules/fast-xml-parser/lib/fxp.cjs");
|
|
76496
76498
|
class XMLConsistencyConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
76497
76499
|
}
|
|
76498
76500
|
exports.XMLConsistencyConf = XMLConsistencyConf;
|
|
@@ -78501,2077 +78503,219 @@ var isArray = Array.isArray || function (xs) {
|
|
|
78501
78503
|
|
|
78502
78504
|
/***/ }),
|
|
78503
78505
|
|
|
78504
|
-
/***/ "./node_modules/fast-xml-parser/
|
|
78505
|
-
/*!*************************************************!*\
|
|
78506
|
-
!*** ./node_modules/fast-xml-parser/src/fxp.js ***!
|
|
78507
|
-
\*************************************************/
|
|
78508
|
-
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
78509
|
-
|
|
78510
|
-
"use strict";
|
|
78511
|
-
|
|
78512
|
-
|
|
78513
|
-
const validator = __webpack_require__(/*! ./validator */ "./node_modules/fast-xml-parser/src/validator.js");
|
|
78514
|
-
const XMLParser = __webpack_require__(/*! ./xmlparser/XMLParser */ "./node_modules/fast-xml-parser/src/xmlparser/XMLParser.js");
|
|
78515
|
-
const XMLBuilder = __webpack_require__(/*! ./xmlbuilder/json2xml */ "./node_modules/fast-xml-parser/src/xmlbuilder/json2xml.js");
|
|
78516
|
-
|
|
78517
|
-
module.exports = {
|
|
78518
|
-
XMLParser: XMLParser,
|
|
78519
|
-
XMLValidator: validator,
|
|
78520
|
-
XMLBuilder: XMLBuilder
|
|
78521
|
-
}
|
|
78522
|
-
|
|
78523
|
-
/***/ }),
|
|
78524
|
-
|
|
78525
|
-
/***/ "./node_modules/fast-xml-parser/src/ignoreAttributes.js":
|
|
78526
|
-
/*!**************************************************************!*\
|
|
78527
|
-
!*** ./node_modules/fast-xml-parser/src/ignoreAttributes.js ***!
|
|
78528
|
-
\**************************************************************/
|
|
78529
|
-
/***/ ((module) => {
|
|
78530
|
-
|
|
78531
|
-
function getIgnoreAttributesFn(ignoreAttributes) {
|
|
78532
|
-
if (typeof ignoreAttributes === 'function') {
|
|
78533
|
-
return ignoreAttributes
|
|
78534
|
-
}
|
|
78535
|
-
if (Array.isArray(ignoreAttributes)) {
|
|
78536
|
-
return (attrName) => {
|
|
78537
|
-
for (const pattern of ignoreAttributes) {
|
|
78538
|
-
if (typeof pattern === 'string' && attrName === pattern) {
|
|
78539
|
-
return true
|
|
78540
|
-
}
|
|
78541
|
-
if (pattern instanceof RegExp && pattern.test(attrName)) {
|
|
78542
|
-
return true
|
|
78543
|
-
}
|
|
78544
|
-
}
|
|
78545
|
-
}
|
|
78546
|
-
}
|
|
78547
|
-
return () => false
|
|
78548
|
-
}
|
|
78549
|
-
|
|
78550
|
-
module.exports = getIgnoreAttributesFn
|
|
78551
|
-
|
|
78552
|
-
/***/ }),
|
|
78553
|
-
|
|
78554
|
-
/***/ "./node_modules/fast-xml-parser/src/util.js":
|
|
78506
|
+
/***/ "./node_modules/fast-xml-parser/lib/fxp.cjs":
|
|
78555
78507
|
/*!**************************************************!*\
|
|
78556
|
-
!*** ./node_modules/fast-xml-parser/
|
|
78508
|
+
!*** ./node_modules/fast-xml-parser/lib/fxp.cjs ***!
|
|
78557
78509
|
\**************************************************/
|
|
78558
|
-
/***/ ((
|
|
78559
|
-
|
|
78560
|
-
"use strict";
|
|
78561
|
-
|
|
78562
|
-
|
|
78563
|
-
const nameStartChar = ':A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD';
|
|
78564
|
-
const nameChar = nameStartChar + '\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040';
|
|
78565
|
-
const nameRegexp = '[' + nameStartChar + '][' + nameChar + ']*'
|
|
78566
|
-
const regexName = new RegExp('^' + nameRegexp + '$');
|
|
78567
|
-
|
|
78568
|
-
const getAllMatches = function(string, regex) {
|
|
78569
|
-
const matches = [];
|
|
78570
|
-
let match = regex.exec(string);
|
|
78571
|
-
while (match) {
|
|
78572
|
-
const allmatches = [];
|
|
78573
|
-
allmatches.startIndex = regex.lastIndex - match[0].length;
|
|
78574
|
-
const len = match.length;
|
|
78575
|
-
for (let index = 0; index < len; index++) {
|
|
78576
|
-
allmatches.push(match[index]);
|
|
78577
|
-
}
|
|
78578
|
-
matches.push(allmatches);
|
|
78579
|
-
match = regex.exec(string);
|
|
78580
|
-
}
|
|
78581
|
-
return matches;
|
|
78582
|
-
};
|
|
78583
|
-
|
|
78584
|
-
const isName = function(string) {
|
|
78585
|
-
const match = regexName.exec(string);
|
|
78586
|
-
return !(match === null || typeof match === 'undefined');
|
|
78587
|
-
};
|
|
78588
|
-
|
|
78589
|
-
exports.isExist = function(v) {
|
|
78590
|
-
return typeof v !== 'undefined';
|
|
78591
|
-
};
|
|
78592
|
-
|
|
78593
|
-
exports.isEmptyObject = function(obj) {
|
|
78594
|
-
return Object.keys(obj).length === 0;
|
|
78595
|
-
};
|
|
78510
|
+
/***/ ((module) => {
|
|
78596
78511
|
|
|
78597
|
-
|
|
78598
|
-
*
|
|
78599
|
-
*
|
|
78600
|
-
*
|
|
78512
|
+
/*
|
|
78513
|
+
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
|
78514
|
+
* This devtool is neither made for production nor for readable output files.
|
|
78515
|
+
* It uses "eval()" calls to create a separate source file in the browser devtools.
|
|
78516
|
+
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
|
78517
|
+
* or disable the default devtool with "devtool: false".
|
|
78518
|
+
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
|
78601
78519
|
*/
|
|
78602
|
-
|
|
78603
|
-
|
|
78604
|
-
|
|
78605
|
-
const len = keys.length; //don't make it inline
|
|
78606
|
-
for (let i = 0; i < len; i++) {
|
|
78607
|
-
if (arrayMode === 'strict') {
|
|
78608
|
-
target[keys[i]] = [ a[keys[i]] ];
|
|
78609
|
-
} else {
|
|
78610
|
-
target[keys[i]] = a[keys[i]];
|
|
78611
|
-
}
|
|
78612
|
-
}
|
|
78613
|
-
}
|
|
78614
|
-
};
|
|
78615
|
-
/* exports.merge =function (b,a){
|
|
78616
|
-
return Object.assign(b,a);
|
|
78617
|
-
} */
|
|
78618
|
-
|
|
78619
|
-
exports.getValue = function(v) {
|
|
78620
|
-
if (exports.isExist(v)) {
|
|
78621
|
-
return v;
|
|
78622
|
-
} else {
|
|
78623
|
-
return '';
|
|
78624
|
-
}
|
|
78625
|
-
};
|
|
78626
|
-
|
|
78627
|
-
// const fakeCall = function(a) {return a;};
|
|
78628
|
-
// const fakeCallNoReturn = function() {};
|
|
78520
|
+
/******/ (() => { // webpackBootstrap
|
|
78521
|
+
/******/ "use strict";
|
|
78522
|
+
/******/ var __webpack_modules__ = ({
|
|
78629
78523
|
|
|
78630
|
-
|
|
78631
|
-
|
|
78632
|
-
|
|
78524
|
+
/***/ "./node_modules/strnum/strnum.js":
|
|
78525
|
+
/*!***************************************!*\
|
|
78526
|
+
!*** ./node_modules/strnum/strnum.js ***!
|
|
78527
|
+
\***************************************/
|
|
78528
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
78633
78529
|
|
|
78530
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ toNumber)\n/* harmony export */ });\nconst hexRegex = /^[-+]?0x[a-fA-F0-9]+$/;\nconst numRegex = /^([\\-\\+])?(0*)([0-9]*(\\.[0-9]*)?)$/;\n// const octRegex = /^0x[a-z0-9]+/;\n// const binRegex = /0x[a-z0-9]+/;\n\n \nconst consider = {\n hex : true,\n // oct: false,\n leadingZeros: true,\n decimalPoint: \"\\.\",\n eNotation: true,\n //skipLike: /regex/\n};\n\nfunction toNumber(str, options = {}){\n options = Object.assign({}, consider, options );\n if(!str || typeof str !== \"string\" ) return str;\n \n let trimmedStr = str.trim();\n \n if(options.skipLike !== undefined && options.skipLike.test(trimmedStr)) return str;\n else if(str===\"0\") return 0;\n else if (options.hex && hexRegex.test(trimmedStr)) {\n return parse_int(trimmedStr, 16);\n // }else if (options.oct && octRegex.test(str)) {\n // return Number.parseInt(val, 8);\n }else if (trimmedStr.search(/[eE]/)!== -1) { //eNotation\n const notation = trimmedStr.match(/^([-\\+])?(0*)([0-9]*(\\.[0-9]*)?[eE][-\\+]?[0-9]+)$/); \n // +00.123 => [ , '+', '00', '.123', ..\n if(notation){\n // console.log(notation)\n if(options.leadingZeros){ //accept with leading zeros\n trimmedStr = (notation[1] || \"\") + notation[3];\n }else{\n if(notation[2] === \"0\" && notation[3][0]=== \".\"){ //valid number\n }else{\n return str;\n }\n }\n return options.eNotation ? Number(trimmedStr) : str;\n }else{\n return str;\n }\n // }else if (options.parseBin && binRegex.test(str)) {\n // return Number.parseInt(val, 2);\n }else{\n //separate negative sign, leading zeros, and rest number\n const match = numRegex.exec(trimmedStr);\n // +00.123 => [ , '+', '00', '.123', ..\n if(match){\n const sign = match[1];\n const leadingZeros = match[2];\n let numTrimmedByZeros = trimZeros(match[3]); //complete num without leading zeros\n //trim ending zeros for floating number\n \n if(!options.leadingZeros && leadingZeros.length > 0 && sign && trimmedStr[2] !== \".\") return str; //-0123\n else if(!options.leadingZeros && leadingZeros.length > 0 && !sign && trimmedStr[1] !== \".\") return str; //0123\n else if(options.leadingZeros && leadingZeros===str) return 0; //00\n \n else{//no leading zeros or leading zeros are allowed\n const num = Number(trimmedStr);\n const numStr = \"\" + num;\n\n if(numStr.search(/[eE]/) !== -1){ //given number is long and parsed to eNotation\n if(options.eNotation) return num;\n else return str;\n }else if(trimmedStr.indexOf(\".\") !== -1){ //floating number\n if(numStr === \"0\" && (numTrimmedByZeros === \"\") ) return num; //0.0\n else if(numStr === numTrimmedByZeros) return num; //0.456. 0.79000\n else if( sign && numStr === \"-\"+numTrimmedByZeros) return num;\n else return str;\n }\n \n if(leadingZeros){\n return (numTrimmedByZeros === numStr) || (sign+numTrimmedByZeros === numStr) ? num : str\n }else {\n return (trimmedStr === numStr) || (trimmedStr === sign+numStr) ? num : str\n }\n }\n }else{ //non-numeric string\n return str;\n }\n }\n}\n\n/**\n * \n * @param {string} numStr without leading zeros\n * @returns \n */\nfunction trimZeros(numStr){\n if(numStr && numStr.indexOf(\".\") !== -1){//float\n numStr = numStr.replace(/0+$/, \"\"); //remove ending zeros\n if(numStr === \".\") numStr = \"0\";\n else if(numStr[0] === \".\") numStr = \"0\"+numStr;\n else if(numStr[numStr.length-1] === \".\") numStr = numStr.substr(0,numStr.length-1);\n return numStr;\n }\n return numStr;\n}\n\nfunction parse_int(numStr, base){\n //polyfill\n if(parseInt) return parseInt(numStr, base);\n else if(Number.parseInt) return Number.parseInt(numStr, base);\n else if(window && window.parseInt) return window.parseInt(numStr, base);\n else throw new Error(\"parseInt, Number.parseInt, window.parseInt are not supported\")\n}\n\n//# sourceURL=webpack://fast-xml-parser/./node_modules/strnum/strnum.js?");
|
|
78634
78531
|
|
|
78635
78532
|
/***/ }),
|
|
78636
78533
|
|
|
78637
|
-
/***/ "./
|
|
78638
|
-
|
|
78639
|
-
!*** ./
|
|
78640
|
-
|
|
78641
|
-
/***/ ((
|
|
78642
|
-
|
|
78643
|
-
"use strict";
|
|
78644
|
-
|
|
78645
|
-
|
|
78646
|
-
const util = __webpack_require__(/*! ./util */ "./node_modules/fast-xml-parser/src/util.js");
|
|
78647
|
-
|
|
78648
|
-
const defaultOptions = {
|
|
78649
|
-
allowBooleanAttributes: false, //A tag can have attributes without any value
|
|
78650
|
-
unpairedTags: []
|
|
78651
|
-
};
|
|
78652
|
-
|
|
78653
|
-
//const tagsPattern = new RegExp("<\\/?([\\w:\\-_\.]+)\\s*\/?>","g");
|
|
78654
|
-
exports.validate = function (xmlData, options) {
|
|
78655
|
-
options = Object.assign({}, defaultOptions, options);
|
|
78656
|
-
|
|
78657
|
-
//xmlData = xmlData.replace(/(\r\n|\n|\r)/gm,"");//make it single line
|
|
78658
|
-
//xmlData = xmlData.replace(/(^\s*<\?xml.*?\?>)/g,"");//Remove XML starting tag
|
|
78659
|
-
//xmlData = xmlData.replace(/(<!DOCTYPE[\s\w\"\.\/\-\:]+(\[.*\])*\s*>)/g,"");//Remove DOCTYPE
|
|
78660
|
-
const tags = [];
|
|
78661
|
-
let tagFound = false;
|
|
78662
|
-
|
|
78663
|
-
//indicates that the root tag has been closed (aka. depth 0 has been reached)
|
|
78664
|
-
let reachedRoot = false;
|
|
78665
|
-
|
|
78666
|
-
if (xmlData[0] === '\ufeff') {
|
|
78667
|
-
// check for byte order mark (BOM)
|
|
78668
|
-
xmlData = xmlData.substr(1);
|
|
78669
|
-
}
|
|
78670
|
-
|
|
78671
|
-
for (let i = 0; i < xmlData.length; i++) {
|
|
78672
|
-
|
|
78673
|
-
if (xmlData[i] === '<' && xmlData[i+1] === '?') {
|
|
78674
|
-
i+=2;
|
|
78675
|
-
i = readPI(xmlData,i);
|
|
78676
|
-
if (i.err) return i;
|
|
78677
|
-
}else if (xmlData[i] === '<') {
|
|
78678
|
-
//starting of tag
|
|
78679
|
-
//read until you reach to '>' avoiding any '>' in attribute value
|
|
78680
|
-
let tagStartPos = i;
|
|
78681
|
-
i++;
|
|
78682
|
-
|
|
78683
|
-
if (xmlData[i] === '!') {
|
|
78684
|
-
i = readCommentAndCDATA(xmlData, i);
|
|
78685
|
-
continue;
|
|
78686
|
-
} else {
|
|
78687
|
-
let closingTag = false;
|
|
78688
|
-
if (xmlData[i] === '/') {
|
|
78689
|
-
//closing tag
|
|
78690
|
-
closingTag = true;
|
|
78691
|
-
i++;
|
|
78692
|
-
}
|
|
78693
|
-
//read tagname
|
|
78694
|
-
let tagName = '';
|
|
78695
|
-
for (; i < xmlData.length &&
|
|
78696
|
-
xmlData[i] !== '>' &&
|
|
78697
|
-
xmlData[i] !== ' ' &&
|
|
78698
|
-
xmlData[i] !== '\t' &&
|
|
78699
|
-
xmlData[i] !== '\n' &&
|
|
78700
|
-
xmlData[i] !== '\r'; i++
|
|
78701
|
-
) {
|
|
78702
|
-
tagName += xmlData[i];
|
|
78703
|
-
}
|
|
78704
|
-
tagName = tagName.trim();
|
|
78705
|
-
//console.log(tagName);
|
|
78706
|
-
|
|
78707
|
-
if (tagName[tagName.length - 1] === '/') {
|
|
78708
|
-
//self closing tag without attributes
|
|
78709
|
-
tagName = tagName.substring(0, tagName.length - 1);
|
|
78710
|
-
//continue;
|
|
78711
|
-
i--;
|
|
78712
|
-
}
|
|
78713
|
-
if (!validateTagName(tagName)) {
|
|
78714
|
-
let msg;
|
|
78715
|
-
if (tagName.trim().length === 0) {
|
|
78716
|
-
msg = "Invalid space after '<'.";
|
|
78717
|
-
} else {
|
|
78718
|
-
msg = "Tag '"+tagName+"' is an invalid name.";
|
|
78719
|
-
}
|
|
78720
|
-
return getErrorObject('InvalidTag', msg, getLineNumberForPosition(xmlData, i));
|
|
78721
|
-
}
|
|
78722
|
-
|
|
78723
|
-
const result = readAttributeStr(xmlData, i);
|
|
78724
|
-
if (result === false) {
|
|
78725
|
-
return getErrorObject('InvalidAttr', "Attributes for '"+tagName+"' have open quote.", getLineNumberForPosition(xmlData, i));
|
|
78726
|
-
}
|
|
78727
|
-
let attrStr = result.value;
|
|
78728
|
-
i = result.index;
|
|
78729
|
-
|
|
78730
|
-
if (attrStr[attrStr.length - 1] === '/') {
|
|
78731
|
-
//self closing tag
|
|
78732
|
-
const attrStrStart = i - attrStr.length;
|
|
78733
|
-
attrStr = attrStr.substring(0, attrStr.length - 1);
|
|
78734
|
-
const isValid = validateAttributeString(attrStr, options);
|
|
78735
|
-
if (isValid === true) {
|
|
78736
|
-
tagFound = true;
|
|
78737
|
-
//continue; //text may presents after self closing tag
|
|
78738
|
-
} else {
|
|
78739
|
-
//the result from the nested function returns the position of the error within the attribute
|
|
78740
|
-
//in order to get the 'true' error line, we need to calculate the position where the attribute begins (i - attrStr.length) and then add the position within the attribute
|
|
78741
|
-
//this gives us the absolute index in the entire xml, which we can use to find the line at last
|
|
78742
|
-
return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, attrStrStart + isValid.err.line));
|
|
78743
|
-
}
|
|
78744
|
-
} else if (closingTag) {
|
|
78745
|
-
if (!result.tagClosed) {
|
|
78746
|
-
return getErrorObject('InvalidTag', "Closing tag '"+tagName+"' doesn't have proper closing.", getLineNumberForPosition(xmlData, i));
|
|
78747
|
-
} else if (attrStr.trim().length > 0) {
|
|
78748
|
-
return getErrorObject('InvalidTag', "Closing tag '"+tagName+"' can't have attributes or invalid starting.", getLineNumberForPosition(xmlData, tagStartPos));
|
|
78749
|
-
} else if (tags.length === 0) {
|
|
78750
|
-
return getErrorObject('InvalidTag', "Closing tag '"+tagName+"' has not been opened.", getLineNumberForPosition(xmlData, tagStartPos));
|
|
78751
|
-
} else {
|
|
78752
|
-
const otg = tags.pop();
|
|
78753
|
-
if (tagName !== otg.tagName) {
|
|
78754
|
-
let openPos = getLineNumberForPosition(xmlData, otg.tagStartPos);
|
|
78755
|
-
return getErrorObject('InvalidTag',
|
|
78756
|
-
"Expected closing tag '"+otg.tagName+"' (opened in line "+openPos.line+", col "+openPos.col+") instead of closing tag '"+tagName+"'.",
|
|
78757
|
-
getLineNumberForPosition(xmlData, tagStartPos));
|
|
78758
|
-
}
|
|
78759
|
-
|
|
78760
|
-
//when there are no more tags, we reached the root level.
|
|
78761
|
-
if (tags.length == 0) {
|
|
78762
|
-
reachedRoot = true;
|
|
78763
|
-
}
|
|
78764
|
-
}
|
|
78765
|
-
} else {
|
|
78766
|
-
const isValid = validateAttributeString(attrStr, options);
|
|
78767
|
-
if (isValid !== true) {
|
|
78768
|
-
//the result from the nested function returns the position of the error within the attribute
|
|
78769
|
-
//in order to get the 'true' error line, we need to calculate the position where the attribute begins (i - attrStr.length) and then add the position within the attribute
|
|
78770
|
-
//this gives us the absolute index in the entire xml, which we can use to find the line at last
|
|
78771
|
-
return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, i - attrStr.length + isValid.err.line));
|
|
78772
|
-
}
|
|
78773
|
-
|
|
78774
|
-
//if the root level has been reached before ...
|
|
78775
|
-
if (reachedRoot === true) {
|
|
78776
|
-
return getErrorObject('InvalidXml', 'Multiple possible root nodes found.', getLineNumberForPosition(xmlData, i));
|
|
78777
|
-
} else if(options.unpairedTags.indexOf(tagName) !== -1){
|
|
78778
|
-
//don't push into stack
|
|
78779
|
-
} else {
|
|
78780
|
-
tags.push({tagName, tagStartPos});
|
|
78781
|
-
}
|
|
78782
|
-
tagFound = true;
|
|
78783
|
-
}
|
|
78784
|
-
|
|
78785
|
-
//skip tag text value
|
|
78786
|
-
//It may include comments and CDATA value
|
|
78787
|
-
for (i++; i < xmlData.length; i++) {
|
|
78788
|
-
if (xmlData[i] === '<') {
|
|
78789
|
-
if (xmlData[i + 1] === '!') {
|
|
78790
|
-
//comment or CADATA
|
|
78791
|
-
i++;
|
|
78792
|
-
i = readCommentAndCDATA(xmlData, i);
|
|
78793
|
-
continue;
|
|
78794
|
-
} else if (xmlData[i+1] === '?') {
|
|
78795
|
-
i = readPI(xmlData, ++i);
|
|
78796
|
-
if (i.err) return i;
|
|
78797
|
-
} else{
|
|
78798
|
-
break;
|
|
78799
|
-
}
|
|
78800
|
-
} else if (xmlData[i] === '&') {
|
|
78801
|
-
const afterAmp = validateAmpersand(xmlData, i);
|
|
78802
|
-
if (afterAmp == -1)
|
|
78803
|
-
return getErrorObject('InvalidChar', "char '&' is not expected.", getLineNumberForPosition(xmlData, i));
|
|
78804
|
-
i = afterAmp;
|
|
78805
|
-
}else{
|
|
78806
|
-
if (reachedRoot === true && !isWhiteSpace(xmlData[i])) {
|
|
78807
|
-
return getErrorObject('InvalidXml', "Extra text at the end", getLineNumberForPosition(xmlData, i));
|
|
78808
|
-
}
|
|
78809
|
-
}
|
|
78810
|
-
} //end of reading tag text value
|
|
78811
|
-
if (xmlData[i] === '<') {
|
|
78812
|
-
i--;
|
|
78813
|
-
}
|
|
78814
|
-
}
|
|
78815
|
-
} else {
|
|
78816
|
-
if ( isWhiteSpace(xmlData[i])) {
|
|
78817
|
-
continue;
|
|
78818
|
-
}
|
|
78819
|
-
return getErrorObject('InvalidChar', "char '"+xmlData[i]+"' is not expected.", getLineNumberForPosition(xmlData, i));
|
|
78820
|
-
}
|
|
78821
|
-
}
|
|
78822
|
-
|
|
78823
|
-
if (!tagFound) {
|
|
78824
|
-
return getErrorObject('InvalidXml', 'Start tag expected.', 1);
|
|
78825
|
-
}else if (tags.length == 1) {
|
|
78826
|
-
return getErrorObject('InvalidTag', "Unclosed tag '"+tags[0].tagName+"'.", getLineNumberForPosition(xmlData, tags[0].tagStartPos));
|
|
78827
|
-
}else if (tags.length > 0) {
|
|
78828
|
-
return getErrorObject('InvalidXml', "Invalid '"+
|
|
78829
|
-
JSON.stringify(tags.map(t => t.tagName), null, 4).replace(/\r?\n/g, '')+
|
|
78830
|
-
"' found.", {line: 1, col: 1});
|
|
78831
|
-
}
|
|
78832
|
-
|
|
78833
|
-
return true;
|
|
78834
|
-
};
|
|
78835
|
-
|
|
78836
|
-
function isWhiteSpace(char){
|
|
78837
|
-
return char === ' ' || char === '\t' || char === '\n' || char === '\r';
|
|
78838
|
-
}
|
|
78839
|
-
/**
|
|
78840
|
-
* Read Processing insstructions and skip
|
|
78841
|
-
* @param {*} xmlData
|
|
78842
|
-
* @param {*} i
|
|
78843
|
-
*/
|
|
78844
|
-
function readPI(xmlData, i) {
|
|
78845
|
-
const start = i;
|
|
78846
|
-
for (; i < xmlData.length; i++) {
|
|
78847
|
-
if (xmlData[i] == '?' || xmlData[i] == ' ') {
|
|
78848
|
-
//tagname
|
|
78849
|
-
const tagname = xmlData.substr(start, i - start);
|
|
78850
|
-
if (i > 5 && tagname === 'xml') {
|
|
78851
|
-
return getErrorObject('InvalidXml', 'XML declaration allowed only at the start of the document.', getLineNumberForPosition(xmlData, i));
|
|
78852
|
-
} else if (xmlData[i] == '?' && xmlData[i + 1] == '>') {
|
|
78853
|
-
//check if valid attribut string
|
|
78854
|
-
i++;
|
|
78855
|
-
break;
|
|
78856
|
-
} else {
|
|
78857
|
-
continue;
|
|
78858
|
-
}
|
|
78859
|
-
}
|
|
78860
|
-
}
|
|
78861
|
-
return i;
|
|
78862
|
-
}
|
|
78863
|
-
|
|
78864
|
-
function readCommentAndCDATA(xmlData, i) {
|
|
78865
|
-
if (xmlData.length > i + 5 && xmlData[i + 1] === '-' && xmlData[i + 2] === '-') {
|
|
78866
|
-
//comment
|
|
78867
|
-
for (i += 3; i < xmlData.length; i++) {
|
|
78868
|
-
if (xmlData[i] === '-' && xmlData[i + 1] === '-' && xmlData[i + 2] === '>') {
|
|
78869
|
-
i += 2;
|
|
78870
|
-
break;
|
|
78871
|
-
}
|
|
78872
|
-
}
|
|
78873
|
-
} else if (
|
|
78874
|
-
xmlData.length > i + 8 &&
|
|
78875
|
-
xmlData[i + 1] === 'D' &&
|
|
78876
|
-
xmlData[i + 2] === 'O' &&
|
|
78877
|
-
xmlData[i + 3] === 'C' &&
|
|
78878
|
-
xmlData[i + 4] === 'T' &&
|
|
78879
|
-
xmlData[i + 5] === 'Y' &&
|
|
78880
|
-
xmlData[i + 6] === 'P' &&
|
|
78881
|
-
xmlData[i + 7] === 'E'
|
|
78882
|
-
) {
|
|
78883
|
-
let angleBracketsCount = 1;
|
|
78884
|
-
for (i += 8; i < xmlData.length; i++) {
|
|
78885
|
-
if (xmlData[i] === '<') {
|
|
78886
|
-
angleBracketsCount++;
|
|
78887
|
-
} else if (xmlData[i] === '>') {
|
|
78888
|
-
angleBracketsCount--;
|
|
78889
|
-
if (angleBracketsCount === 0) {
|
|
78890
|
-
break;
|
|
78891
|
-
}
|
|
78892
|
-
}
|
|
78893
|
-
}
|
|
78894
|
-
} else if (
|
|
78895
|
-
xmlData.length > i + 9 &&
|
|
78896
|
-
xmlData[i + 1] === '[' &&
|
|
78897
|
-
xmlData[i + 2] === 'C' &&
|
|
78898
|
-
xmlData[i + 3] === 'D' &&
|
|
78899
|
-
xmlData[i + 4] === 'A' &&
|
|
78900
|
-
xmlData[i + 5] === 'T' &&
|
|
78901
|
-
xmlData[i + 6] === 'A' &&
|
|
78902
|
-
xmlData[i + 7] === '['
|
|
78903
|
-
) {
|
|
78904
|
-
for (i += 8; i < xmlData.length; i++) {
|
|
78905
|
-
if (xmlData[i] === ']' && xmlData[i + 1] === ']' && xmlData[i + 2] === '>') {
|
|
78906
|
-
i += 2;
|
|
78907
|
-
break;
|
|
78908
|
-
}
|
|
78909
|
-
}
|
|
78910
|
-
}
|
|
78911
|
-
|
|
78912
|
-
return i;
|
|
78913
|
-
}
|
|
78914
|
-
|
|
78915
|
-
const doubleQuote = '"';
|
|
78916
|
-
const singleQuote = "'";
|
|
78917
|
-
|
|
78918
|
-
/**
|
|
78919
|
-
* Keep reading xmlData until '<' is found outside the attribute value.
|
|
78920
|
-
* @param {string} xmlData
|
|
78921
|
-
* @param {number} i
|
|
78922
|
-
*/
|
|
78923
|
-
function readAttributeStr(xmlData, i) {
|
|
78924
|
-
let attrStr = '';
|
|
78925
|
-
let startChar = '';
|
|
78926
|
-
let tagClosed = false;
|
|
78927
|
-
for (; i < xmlData.length; i++) {
|
|
78928
|
-
if (xmlData[i] === doubleQuote || xmlData[i] === singleQuote) {
|
|
78929
|
-
if (startChar === '') {
|
|
78930
|
-
startChar = xmlData[i];
|
|
78931
|
-
} else if (startChar !== xmlData[i]) {
|
|
78932
|
-
//if vaue is enclosed with double quote then single quotes are allowed inside the value and vice versa
|
|
78933
|
-
} else {
|
|
78934
|
-
startChar = '';
|
|
78935
|
-
}
|
|
78936
|
-
} else if (xmlData[i] === '>') {
|
|
78937
|
-
if (startChar === '') {
|
|
78938
|
-
tagClosed = true;
|
|
78939
|
-
break;
|
|
78940
|
-
}
|
|
78941
|
-
}
|
|
78942
|
-
attrStr += xmlData[i];
|
|
78943
|
-
}
|
|
78944
|
-
if (startChar !== '') {
|
|
78945
|
-
return false;
|
|
78946
|
-
}
|
|
78947
|
-
|
|
78948
|
-
return {
|
|
78949
|
-
value: attrStr,
|
|
78950
|
-
index: i,
|
|
78951
|
-
tagClosed: tagClosed
|
|
78952
|
-
};
|
|
78953
|
-
}
|
|
78954
|
-
|
|
78955
|
-
/**
|
|
78956
|
-
* Select all the attributes whether valid or invalid.
|
|
78957
|
-
*/
|
|
78958
|
-
const validAttrStrRegxp = new RegExp('(\\s*)([^\\s=]+)(\\s*=)?(\\s*([\'"])(([\\s\\S])*?)\\5)?', 'g');
|
|
78959
|
-
|
|
78960
|
-
//attr, ="sd", a="amit's", a="sd"b="saf", ab cd=""
|
|
78961
|
-
|
|
78962
|
-
function validateAttributeString(attrStr, options) {
|
|
78963
|
-
//console.log("start:"+attrStr+":end");
|
|
78964
|
-
|
|
78965
|
-
//if(attrStr.trim().length === 0) return true; //empty string
|
|
78966
|
-
|
|
78967
|
-
const matches = util.getAllMatches(attrStr, validAttrStrRegxp);
|
|
78968
|
-
const attrNames = {};
|
|
78969
|
-
|
|
78970
|
-
for (let i = 0; i < matches.length; i++) {
|
|
78971
|
-
if (matches[i][1].length === 0) {
|
|
78972
|
-
//nospace before attribute name: a="sd"b="saf"
|
|
78973
|
-
return getErrorObject('InvalidAttr', "Attribute '"+matches[i][2]+"' has no space in starting.", getPositionFromMatch(matches[i]))
|
|
78974
|
-
} else if (matches[i][3] !== undefined && matches[i][4] === undefined) {
|
|
78975
|
-
return getErrorObject('InvalidAttr', "Attribute '"+matches[i][2]+"' is without value.", getPositionFromMatch(matches[i]));
|
|
78976
|
-
} else if (matches[i][3] === undefined && !options.allowBooleanAttributes) {
|
|
78977
|
-
//independent attribute: ab
|
|
78978
|
-
return getErrorObject('InvalidAttr', "boolean attribute '"+matches[i][2]+"' is not allowed.", getPositionFromMatch(matches[i]));
|
|
78979
|
-
}
|
|
78980
|
-
/* else if(matches[i][6] === undefined){//attribute without value: ab=
|
|
78981
|
-
return { err: { code:"InvalidAttr",msg:"attribute " + matches[i][2] + " has no value assigned."}};
|
|
78982
|
-
} */
|
|
78983
|
-
const attrName = matches[i][2];
|
|
78984
|
-
if (!validateAttrName(attrName)) {
|
|
78985
|
-
return getErrorObject('InvalidAttr', "Attribute '"+attrName+"' is an invalid name.", getPositionFromMatch(matches[i]));
|
|
78986
|
-
}
|
|
78987
|
-
if (!attrNames.hasOwnProperty(attrName)) {
|
|
78988
|
-
//check for duplicate attribute.
|
|
78989
|
-
attrNames[attrName] = 1;
|
|
78990
|
-
} else {
|
|
78991
|
-
return getErrorObject('InvalidAttr', "Attribute '"+attrName+"' is repeated.", getPositionFromMatch(matches[i]));
|
|
78992
|
-
}
|
|
78993
|
-
}
|
|
78994
|
-
|
|
78995
|
-
return true;
|
|
78996
|
-
}
|
|
78997
|
-
|
|
78998
|
-
function validateNumberAmpersand(xmlData, i) {
|
|
78999
|
-
let re = /\d/;
|
|
79000
|
-
if (xmlData[i] === 'x') {
|
|
79001
|
-
i++;
|
|
79002
|
-
re = /[\da-fA-F]/;
|
|
79003
|
-
}
|
|
79004
|
-
for (; i < xmlData.length; i++) {
|
|
79005
|
-
if (xmlData[i] === ';')
|
|
79006
|
-
return i;
|
|
79007
|
-
if (!xmlData[i].match(re))
|
|
79008
|
-
break;
|
|
79009
|
-
}
|
|
79010
|
-
return -1;
|
|
79011
|
-
}
|
|
79012
|
-
|
|
79013
|
-
function validateAmpersand(xmlData, i) {
|
|
79014
|
-
// https://www.w3.org/TR/xml/#dt-charref
|
|
79015
|
-
i++;
|
|
79016
|
-
if (xmlData[i] === ';')
|
|
79017
|
-
return -1;
|
|
79018
|
-
if (xmlData[i] === '#') {
|
|
79019
|
-
i++;
|
|
79020
|
-
return validateNumberAmpersand(xmlData, i);
|
|
79021
|
-
}
|
|
79022
|
-
let count = 0;
|
|
79023
|
-
for (; i < xmlData.length; i++, count++) {
|
|
79024
|
-
if (xmlData[i].match(/\w/) && count < 20)
|
|
79025
|
-
continue;
|
|
79026
|
-
if (xmlData[i] === ';')
|
|
79027
|
-
break;
|
|
79028
|
-
return -1;
|
|
79029
|
-
}
|
|
79030
|
-
return i;
|
|
79031
|
-
}
|
|
79032
|
-
|
|
79033
|
-
function getErrorObject(code, message, lineNumber) {
|
|
79034
|
-
return {
|
|
79035
|
-
err: {
|
|
79036
|
-
code: code,
|
|
79037
|
-
msg: message,
|
|
79038
|
-
line: lineNumber.line || lineNumber,
|
|
79039
|
-
col: lineNumber.col,
|
|
79040
|
-
},
|
|
79041
|
-
};
|
|
79042
|
-
}
|
|
79043
|
-
|
|
79044
|
-
function validateAttrName(attrName) {
|
|
79045
|
-
return util.isName(attrName);
|
|
79046
|
-
}
|
|
79047
|
-
|
|
79048
|
-
// const startsWithXML = /^xml/i;
|
|
79049
|
-
|
|
79050
|
-
function validateTagName(tagname) {
|
|
79051
|
-
return util.isName(tagname) /* && !tagname.match(startsWithXML) */;
|
|
79052
|
-
}
|
|
79053
|
-
|
|
79054
|
-
//this function returns the line number for the character at the given index
|
|
79055
|
-
function getLineNumberForPosition(xmlData, index) {
|
|
79056
|
-
const lines = xmlData.substring(0, index).split(/\r?\n/);
|
|
79057
|
-
return {
|
|
79058
|
-
line: lines.length,
|
|
79059
|
-
|
|
79060
|
-
// column number is last line's length + 1, because column numbering starts at 1:
|
|
79061
|
-
col: lines[lines.length - 1].length + 1
|
|
79062
|
-
};
|
|
79063
|
-
}
|
|
79064
|
-
|
|
79065
|
-
//this function returns the position of the first character of match within attrStr
|
|
79066
|
-
function getPositionFromMatch(match) {
|
|
79067
|
-
return match.startIndex + match[1].length;
|
|
79068
|
-
}
|
|
78534
|
+
/***/ "./src/fxp.js":
|
|
78535
|
+
/*!********************!*\
|
|
78536
|
+
!*** ./src/fxp.js ***!
|
|
78537
|
+
\********************/
|
|
78538
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
79069
78539
|
|
|
78540
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ XMLBuilder: () => (/* reexport safe */ _xmlbuilder_json2xml_js__WEBPACK_IMPORTED_MODULE_2__[\"default\"]),\n/* harmony export */ XMLParser: () => (/* reexport safe */ _xmlparser_XMLParser_js__WEBPACK_IMPORTED_MODULE_1__[\"default\"]),\n/* harmony export */ XMLValidator: () => (/* binding */ XMLValidator)\n/* harmony export */ });\n/* harmony import */ var _validator_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./validator.js */ \"./src/validator.js\");\n/* harmony import */ var _xmlparser_XMLParser_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./xmlparser/XMLParser.js */ \"./src/xmlparser/XMLParser.js\");\n/* harmony import */ var _xmlbuilder_json2xml_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./xmlbuilder/json2xml.js */ \"./src/xmlbuilder/json2xml.js\");\n\n\n\n\n\n\nconst XMLValidator = {\n validate: _validator_js__WEBPACK_IMPORTED_MODULE_0__.validate\n}\n\n\n//# sourceURL=webpack://fast-xml-parser/./src/fxp.js?");
|
|
79070
78541
|
|
|
79071
78542
|
/***/ }),
|
|
79072
78543
|
|
|
79073
|
-
/***/ "./
|
|
79074
|
-
|
|
79075
|
-
!*** ./
|
|
79076
|
-
|
|
79077
|
-
/***/ ((
|
|
79078
|
-
|
|
79079
|
-
"use strict";
|
|
79080
|
-
|
|
79081
|
-
//parse Empty Node as self closing node
|
|
79082
|
-
const buildFromOrderedJs = __webpack_require__(/*! ./orderedJs2Xml */ "./node_modules/fast-xml-parser/src/xmlbuilder/orderedJs2Xml.js");
|
|
79083
|
-
const getIgnoreAttributesFn = __webpack_require__(/*! ../ignoreAttributes */ "./node_modules/fast-xml-parser/src/ignoreAttributes.js")
|
|
79084
|
-
|
|
79085
|
-
const defaultOptions = {
|
|
79086
|
-
attributeNamePrefix: '@_',
|
|
79087
|
-
attributesGroupName: false,
|
|
79088
|
-
textNodeName: '#text',
|
|
79089
|
-
ignoreAttributes: true,
|
|
79090
|
-
cdataPropName: false,
|
|
79091
|
-
format: false,
|
|
79092
|
-
indentBy: ' ',
|
|
79093
|
-
suppressEmptyNode: false,
|
|
79094
|
-
suppressUnpairedNode: true,
|
|
79095
|
-
suppressBooleanAttributes: true,
|
|
79096
|
-
tagValueProcessor: function(key, a) {
|
|
79097
|
-
return a;
|
|
79098
|
-
},
|
|
79099
|
-
attributeValueProcessor: function(attrName, a) {
|
|
79100
|
-
return a;
|
|
79101
|
-
},
|
|
79102
|
-
preserveOrder: false,
|
|
79103
|
-
commentPropName: false,
|
|
79104
|
-
unpairedTags: [],
|
|
79105
|
-
entities: [
|
|
79106
|
-
{ regex: new RegExp("&", "g"), val: "&" },//it must be on top
|
|
79107
|
-
{ regex: new RegExp(">", "g"), val: ">" },
|
|
79108
|
-
{ regex: new RegExp("<", "g"), val: "<" },
|
|
79109
|
-
{ regex: new RegExp("\'", "g"), val: "'" },
|
|
79110
|
-
{ regex: new RegExp("\"", "g"), val: """ }
|
|
79111
|
-
],
|
|
79112
|
-
processEntities: true,
|
|
79113
|
-
stopNodes: [],
|
|
79114
|
-
// transformTagName: false,
|
|
79115
|
-
// transformAttributeName: false,
|
|
79116
|
-
oneListGroup: false
|
|
79117
|
-
};
|
|
79118
|
-
|
|
79119
|
-
function Builder(options) {
|
|
79120
|
-
this.options = Object.assign({}, defaultOptions, options);
|
|
79121
|
-
if (this.options.ignoreAttributes === true || this.options.attributesGroupName) {
|
|
79122
|
-
this.isAttribute = function(/*a*/) {
|
|
79123
|
-
return false;
|
|
79124
|
-
};
|
|
79125
|
-
} else {
|
|
79126
|
-
this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes)
|
|
79127
|
-
this.attrPrefixLen = this.options.attributeNamePrefix.length;
|
|
79128
|
-
this.isAttribute = isAttribute;
|
|
79129
|
-
}
|
|
79130
|
-
|
|
79131
|
-
this.processTextOrObjNode = processTextOrObjNode
|
|
79132
|
-
|
|
79133
|
-
if (this.options.format) {
|
|
79134
|
-
this.indentate = indentate;
|
|
79135
|
-
this.tagEndChar = '>\n';
|
|
79136
|
-
this.newLine = '\n';
|
|
79137
|
-
} else {
|
|
79138
|
-
this.indentate = function() {
|
|
79139
|
-
return '';
|
|
79140
|
-
};
|
|
79141
|
-
this.tagEndChar = '>';
|
|
79142
|
-
this.newLine = '';
|
|
79143
|
-
}
|
|
79144
|
-
}
|
|
79145
|
-
|
|
79146
|
-
Builder.prototype.build = function(jObj) {
|
|
79147
|
-
if(this.options.preserveOrder){
|
|
79148
|
-
return buildFromOrderedJs(jObj, this.options);
|
|
79149
|
-
}else {
|
|
79150
|
-
if(Array.isArray(jObj) && this.options.arrayNodeName && this.options.arrayNodeName.length > 1){
|
|
79151
|
-
jObj = {
|
|
79152
|
-
[this.options.arrayNodeName] : jObj
|
|
79153
|
-
}
|
|
79154
|
-
}
|
|
79155
|
-
return this.j2x(jObj, 0, []).val;
|
|
79156
|
-
}
|
|
79157
|
-
};
|
|
79158
|
-
|
|
79159
|
-
Builder.prototype.j2x = function(jObj, level, ajPath) {
|
|
79160
|
-
let attrStr = '';
|
|
79161
|
-
let val = '';
|
|
79162
|
-
const jPath = ajPath.join('.')
|
|
79163
|
-
for (let key in jObj) {
|
|
79164
|
-
if(!Object.prototype.hasOwnProperty.call(jObj, key)) continue;
|
|
79165
|
-
if (typeof jObj[key] === 'undefined') {
|
|
79166
|
-
// supress undefined node only if it is not an attribute
|
|
79167
|
-
if (this.isAttribute(key)) {
|
|
79168
|
-
val += '';
|
|
79169
|
-
}
|
|
79170
|
-
} else if (jObj[key] === null) {
|
|
79171
|
-
// null attribute should be ignored by the attribute list, but should not cause the tag closing
|
|
79172
|
-
if (this.isAttribute(key)) {
|
|
79173
|
-
val += '';
|
|
79174
|
-
} else if (key === this.options.cdataPropName) {
|
|
79175
|
-
val += '';
|
|
79176
|
-
} else if (key[0] === '?') {
|
|
79177
|
-
val += this.indentate(level) + '<' + key + '?' + this.tagEndChar;
|
|
79178
|
-
} else {
|
|
79179
|
-
val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
|
|
79180
|
-
}
|
|
79181
|
-
// val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
|
|
79182
|
-
} else if (jObj[key] instanceof Date) {
|
|
79183
|
-
val += this.buildTextValNode(jObj[key], key, '', level);
|
|
79184
|
-
} else if (typeof jObj[key] !== 'object') {
|
|
79185
|
-
//premitive type
|
|
79186
|
-
const attr = this.isAttribute(key);
|
|
79187
|
-
if (attr && !this.ignoreAttributesFn(attr, jPath)) {
|
|
79188
|
-
attrStr += this.buildAttrPairStr(attr, '' + jObj[key]);
|
|
79189
|
-
} else if (!attr) {
|
|
79190
|
-
//tag value
|
|
79191
|
-
if (key === this.options.textNodeName) {
|
|
79192
|
-
let newval = this.options.tagValueProcessor(key, '' + jObj[key]);
|
|
79193
|
-
val += this.replaceEntitiesValue(newval);
|
|
79194
|
-
} else {
|
|
79195
|
-
val += this.buildTextValNode(jObj[key], key, '', level);
|
|
79196
|
-
}
|
|
79197
|
-
}
|
|
79198
|
-
} else if (Array.isArray(jObj[key])) {
|
|
79199
|
-
//repeated nodes
|
|
79200
|
-
const arrLen = jObj[key].length;
|
|
79201
|
-
let listTagVal = "";
|
|
79202
|
-
let listTagAttr = "";
|
|
79203
|
-
for (let j = 0; j < arrLen; j++) {
|
|
79204
|
-
const item = jObj[key][j];
|
|
79205
|
-
if (typeof item === 'undefined') {
|
|
79206
|
-
// supress undefined node
|
|
79207
|
-
} else if (item === null) {
|
|
79208
|
-
if(key[0] === "?") val += this.indentate(level) + '<' + key + '?' + this.tagEndChar;
|
|
79209
|
-
else val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
|
|
79210
|
-
// val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
|
|
79211
|
-
} else if (typeof item === 'object') {
|
|
79212
|
-
if(this.options.oneListGroup){
|
|
79213
|
-
const result = this.j2x(item, level + 1, ajPath.concat(key));
|
|
79214
|
-
listTagVal += result.val;
|
|
79215
|
-
if (this.options.attributesGroupName && item.hasOwnProperty(this.options.attributesGroupName)) {
|
|
79216
|
-
listTagAttr += result.attrStr
|
|
79217
|
-
}
|
|
79218
|
-
}else{
|
|
79219
|
-
listTagVal += this.processTextOrObjNode(item, key, level, ajPath)
|
|
79220
|
-
}
|
|
79221
|
-
} else {
|
|
79222
|
-
if (this.options.oneListGroup) {
|
|
79223
|
-
let textValue = this.options.tagValueProcessor(key, item);
|
|
79224
|
-
textValue = this.replaceEntitiesValue(textValue);
|
|
79225
|
-
listTagVal += textValue;
|
|
79226
|
-
} else {
|
|
79227
|
-
listTagVal += this.buildTextValNode(item, key, '', level);
|
|
79228
|
-
}
|
|
79229
|
-
}
|
|
79230
|
-
}
|
|
79231
|
-
if(this.options.oneListGroup){
|
|
79232
|
-
listTagVal = this.buildObjectNode(listTagVal, key, listTagAttr, level);
|
|
79233
|
-
}
|
|
79234
|
-
val += listTagVal;
|
|
79235
|
-
} else {
|
|
79236
|
-
//nested node
|
|
79237
|
-
if (this.options.attributesGroupName && key === this.options.attributesGroupName) {
|
|
79238
|
-
const Ks = Object.keys(jObj[key]);
|
|
79239
|
-
const L = Ks.length;
|
|
79240
|
-
for (let j = 0; j < L; j++) {
|
|
79241
|
-
attrStr += this.buildAttrPairStr(Ks[j], '' + jObj[key][Ks[j]]);
|
|
79242
|
-
}
|
|
79243
|
-
} else {
|
|
79244
|
-
val += this.processTextOrObjNode(jObj[key], key, level, ajPath)
|
|
79245
|
-
}
|
|
79246
|
-
}
|
|
79247
|
-
}
|
|
79248
|
-
return {attrStr: attrStr, val: val};
|
|
79249
|
-
};
|
|
79250
|
-
|
|
79251
|
-
Builder.prototype.buildAttrPairStr = function(attrName, val){
|
|
79252
|
-
val = this.options.attributeValueProcessor(attrName, '' + val);
|
|
79253
|
-
val = this.replaceEntitiesValue(val);
|
|
79254
|
-
if (this.options.suppressBooleanAttributes && val === "true") {
|
|
79255
|
-
return ' ' + attrName;
|
|
79256
|
-
} else return ' ' + attrName + '="' + val + '"';
|
|
79257
|
-
}
|
|
79258
|
-
|
|
79259
|
-
function processTextOrObjNode (object, key, level, ajPath) {
|
|
79260
|
-
const result = this.j2x(object, level + 1, ajPath.concat(key));
|
|
79261
|
-
if (object[this.options.textNodeName] !== undefined && Object.keys(object).length === 1) {
|
|
79262
|
-
return this.buildTextValNode(object[this.options.textNodeName], key, result.attrStr, level);
|
|
79263
|
-
} else {
|
|
79264
|
-
return this.buildObjectNode(result.val, key, result.attrStr, level);
|
|
79265
|
-
}
|
|
79266
|
-
}
|
|
79267
|
-
|
|
79268
|
-
Builder.prototype.buildObjectNode = function(val, key, attrStr, level) {
|
|
79269
|
-
if(val === ""){
|
|
79270
|
-
if(key[0] === "?") return this.indentate(level) + '<' + key + attrStr+ '?' + this.tagEndChar;
|
|
79271
|
-
else {
|
|
79272
|
-
return this.indentate(level) + '<' + key + attrStr + this.closeTag(key) + this.tagEndChar;
|
|
79273
|
-
}
|
|
79274
|
-
}else{
|
|
79275
|
-
|
|
79276
|
-
let tagEndExp = '</' + key + this.tagEndChar;
|
|
79277
|
-
let piClosingChar = "";
|
|
79278
|
-
|
|
79279
|
-
if(key[0] === "?") {
|
|
79280
|
-
piClosingChar = "?";
|
|
79281
|
-
tagEndExp = "";
|
|
79282
|
-
}
|
|
79283
|
-
|
|
79284
|
-
// attrStr is an empty string in case the attribute came as undefined or null
|
|
79285
|
-
if ((attrStr || attrStr === '') && val.indexOf('<') === -1) {
|
|
79286
|
-
return ( this.indentate(level) + '<' + key + attrStr + piClosingChar + '>' + val + tagEndExp );
|
|
79287
|
-
} else if (this.options.commentPropName !== false && key === this.options.commentPropName && piClosingChar.length === 0) {
|
|
79288
|
-
return this.indentate(level) + `<!--${val}-->` + this.newLine;
|
|
79289
|
-
}else {
|
|
79290
|
-
return (
|
|
79291
|
-
this.indentate(level) + '<' + key + attrStr + piClosingChar + this.tagEndChar +
|
|
79292
|
-
val +
|
|
79293
|
-
this.indentate(level) + tagEndExp );
|
|
79294
|
-
}
|
|
79295
|
-
}
|
|
79296
|
-
}
|
|
79297
|
-
|
|
79298
|
-
Builder.prototype.closeTag = function(key){
|
|
79299
|
-
let closeTag = "";
|
|
79300
|
-
if(this.options.unpairedTags.indexOf(key) !== -1){ //unpaired
|
|
79301
|
-
if(!this.options.suppressUnpairedNode) closeTag = "/"
|
|
79302
|
-
}else if(this.options.suppressEmptyNode){ //empty
|
|
79303
|
-
closeTag = "/";
|
|
79304
|
-
}else{
|
|
79305
|
-
closeTag = `></${key}`
|
|
79306
|
-
}
|
|
79307
|
-
return closeTag;
|
|
79308
|
-
}
|
|
79309
|
-
|
|
79310
|
-
function buildEmptyObjNode(val, key, attrStr, level) {
|
|
79311
|
-
if (val !== '') {
|
|
79312
|
-
return this.buildObjectNode(val, key, attrStr, level);
|
|
79313
|
-
} else {
|
|
79314
|
-
if(key[0] === "?") return this.indentate(level) + '<' + key + attrStr+ '?' + this.tagEndChar;
|
|
79315
|
-
else {
|
|
79316
|
-
return this.indentate(level) + '<' + key + attrStr + '/' + this.tagEndChar;
|
|
79317
|
-
// return this.buildTagStr(level,key, attrStr);
|
|
79318
|
-
}
|
|
79319
|
-
}
|
|
79320
|
-
}
|
|
79321
|
-
|
|
79322
|
-
Builder.prototype.buildTextValNode = function(val, key, attrStr, level) {
|
|
79323
|
-
if (this.options.cdataPropName !== false && key === this.options.cdataPropName) {
|
|
79324
|
-
return this.indentate(level) + `<![CDATA[${val}]]>` + this.newLine;
|
|
79325
|
-
}else if (this.options.commentPropName !== false && key === this.options.commentPropName) {
|
|
79326
|
-
return this.indentate(level) + `<!--${val}-->` + this.newLine;
|
|
79327
|
-
}else if(key[0] === "?") {//PI tag
|
|
79328
|
-
return this.indentate(level) + '<' + key + attrStr+ '?' + this.tagEndChar;
|
|
79329
|
-
}else{
|
|
79330
|
-
let textValue = this.options.tagValueProcessor(key, val);
|
|
79331
|
-
textValue = this.replaceEntitiesValue(textValue);
|
|
79332
|
-
|
|
79333
|
-
if( textValue === ''){
|
|
79334
|
-
return this.indentate(level) + '<' + key + attrStr + this.closeTag(key) + this.tagEndChar;
|
|
79335
|
-
}else{
|
|
79336
|
-
return this.indentate(level) + '<' + key + attrStr + '>' +
|
|
79337
|
-
textValue +
|
|
79338
|
-
'</' + key + this.tagEndChar;
|
|
79339
|
-
}
|
|
79340
|
-
}
|
|
79341
|
-
}
|
|
79342
|
-
|
|
79343
|
-
Builder.prototype.replaceEntitiesValue = function(textValue){
|
|
79344
|
-
if(textValue && textValue.length > 0 && this.options.processEntities){
|
|
79345
|
-
for (let i=0; i<this.options.entities.length; i++) {
|
|
79346
|
-
const entity = this.options.entities[i];
|
|
79347
|
-
textValue = textValue.replace(entity.regex, entity.val);
|
|
79348
|
-
}
|
|
79349
|
-
}
|
|
79350
|
-
return textValue;
|
|
79351
|
-
}
|
|
79352
|
-
|
|
79353
|
-
function indentate(level) {
|
|
79354
|
-
return this.options.indentBy.repeat(level);
|
|
79355
|
-
}
|
|
79356
|
-
|
|
79357
|
-
function isAttribute(name /*, options*/) {
|
|
79358
|
-
if (name.startsWith(this.options.attributeNamePrefix) && name !== this.options.textNodeName) {
|
|
79359
|
-
return name.substr(this.attrPrefixLen);
|
|
79360
|
-
} else {
|
|
79361
|
-
return false;
|
|
79362
|
-
}
|
|
79363
|
-
}
|
|
79364
|
-
|
|
79365
|
-
module.exports = Builder;
|
|
78544
|
+
/***/ "./src/ignoreAttributes.js":
|
|
78545
|
+
/*!*********************************!*\
|
|
78546
|
+
!*** ./src/ignoreAttributes.js ***!
|
|
78547
|
+
\*********************************/
|
|
78548
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
79366
78549
|
|
|
78550
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ getIgnoreAttributesFn)\n/* harmony export */ });\nfunction getIgnoreAttributesFn(ignoreAttributes) {\n if (typeof ignoreAttributes === 'function') {\n return ignoreAttributes\n }\n if (Array.isArray(ignoreAttributes)) {\n return (attrName) => {\n for (const pattern of ignoreAttributes) {\n if (typeof pattern === 'string' && attrName === pattern) {\n return true\n }\n if (pattern instanceof RegExp && pattern.test(attrName)) {\n return true\n }\n }\n }\n }\n return () => false\n}\n\n//# sourceURL=webpack://fast-xml-parser/./src/ignoreAttributes.js?");
|
|
79367
78551
|
|
|
79368
78552
|
/***/ }),
|
|
79369
78553
|
|
|
79370
|
-
/***/ "./
|
|
79371
|
-
|
|
79372
|
-
!*** ./
|
|
79373
|
-
|
|
79374
|
-
/***/ ((
|
|
79375
|
-
|
|
79376
|
-
const EOL = "\n";
|
|
79377
|
-
|
|
79378
|
-
/**
|
|
79379
|
-
*
|
|
79380
|
-
* @param {array} jArray
|
|
79381
|
-
* @param {any} options
|
|
79382
|
-
* @returns
|
|
79383
|
-
*/
|
|
79384
|
-
function toXml(jArray, options) {
|
|
79385
|
-
let indentation = "";
|
|
79386
|
-
if (options.format && options.indentBy.length > 0) {
|
|
79387
|
-
indentation = EOL;
|
|
79388
|
-
}
|
|
79389
|
-
return arrToStr(jArray, options, "", indentation);
|
|
79390
|
-
}
|
|
79391
|
-
|
|
79392
|
-
function arrToStr(arr, options, jPath, indentation) {
|
|
79393
|
-
let xmlStr = "";
|
|
79394
|
-
let isPreviousElementTag = false;
|
|
79395
|
-
|
|
79396
|
-
for (let i = 0; i < arr.length; i++) {
|
|
79397
|
-
const tagObj = arr[i];
|
|
79398
|
-
const tagName = propName(tagObj);
|
|
79399
|
-
if(tagName === undefined) continue;
|
|
79400
|
-
|
|
79401
|
-
let newJPath = "";
|
|
79402
|
-
if (jPath.length === 0) newJPath = tagName
|
|
79403
|
-
else newJPath = `${jPath}.${tagName}`;
|
|
79404
|
-
|
|
79405
|
-
if (tagName === options.textNodeName) {
|
|
79406
|
-
let tagText = tagObj[tagName];
|
|
79407
|
-
if (!isStopNode(newJPath, options)) {
|
|
79408
|
-
tagText = options.tagValueProcessor(tagName, tagText);
|
|
79409
|
-
tagText = replaceEntitiesValue(tagText, options);
|
|
79410
|
-
}
|
|
79411
|
-
if (isPreviousElementTag) {
|
|
79412
|
-
xmlStr += indentation;
|
|
79413
|
-
}
|
|
79414
|
-
xmlStr += tagText;
|
|
79415
|
-
isPreviousElementTag = false;
|
|
79416
|
-
continue;
|
|
79417
|
-
} else if (tagName === options.cdataPropName) {
|
|
79418
|
-
if (isPreviousElementTag) {
|
|
79419
|
-
xmlStr += indentation;
|
|
79420
|
-
}
|
|
79421
|
-
xmlStr += `<![CDATA[${tagObj[tagName][0][options.textNodeName]}]]>`;
|
|
79422
|
-
isPreviousElementTag = false;
|
|
79423
|
-
continue;
|
|
79424
|
-
} else if (tagName === options.commentPropName) {
|
|
79425
|
-
xmlStr += indentation + `<!--${tagObj[tagName][0][options.textNodeName]}-->`;
|
|
79426
|
-
isPreviousElementTag = true;
|
|
79427
|
-
continue;
|
|
79428
|
-
} else if (tagName[0] === "?") {
|
|
79429
|
-
const attStr = attr_to_str(tagObj[":@"], options);
|
|
79430
|
-
const tempInd = tagName === "?xml" ? "" : indentation;
|
|
79431
|
-
let piTextNodeName = tagObj[tagName][0][options.textNodeName];
|
|
79432
|
-
piTextNodeName = piTextNodeName.length !== 0 ? " " + piTextNodeName : ""; //remove extra spacing
|
|
79433
|
-
xmlStr += tempInd + `<${tagName}${piTextNodeName}${attStr}?>`;
|
|
79434
|
-
isPreviousElementTag = true;
|
|
79435
|
-
continue;
|
|
79436
|
-
}
|
|
79437
|
-
let newIdentation = indentation;
|
|
79438
|
-
if (newIdentation !== "") {
|
|
79439
|
-
newIdentation += options.indentBy;
|
|
79440
|
-
}
|
|
79441
|
-
const attStr = attr_to_str(tagObj[":@"], options);
|
|
79442
|
-
const tagStart = indentation + `<${tagName}${attStr}`;
|
|
79443
|
-
const tagValue = arrToStr(tagObj[tagName], options, newJPath, newIdentation);
|
|
79444
|
-
if (options.unpairedTags.indexOf(tagName) !== -1) {
|
|
79445
|
-
if (options.suppressUnpairedNode) xmlStr += tagStart + ">";
|
|
79446
|
-
else xmlStr += tagStart + "/>";
|
|
79447
|
-
} else if ((!tagValue || tagValue.length === 0) && options.suppressEmptyNode) {
|
|
79448
|
-
xmlStr += tagStart + "/>";
|
|
79449
|
-
} else if (tagValue && tagValue.endsWith(">")) {
|
|
79450
|
-
xmlStr += tagStart + `>${tagValue}${indentation}</${tagName}>`;
|
|
79451
|
-
} else {
|
|
79452
|
-
xmlStr += tagStart + ">";
|
|
79453
|
-
if (tagValue && indentation !== "" && (tagValue.includes("/>") || tagValue.includes("</"))) {
|
|
79454
|
-
xmlStr += indentation + options.indentBy + tagValue + indentation;
|
|
79455
|
-
} else {
|
|
79456
|
-
xmlStr += tagValue;
|
|
79457
|
-
}
|
|
79458
|
-
xmlStr += `</${tagName}>`;
|
|
79459
|
-
}
|
|
79460
|
-
isPreviousElementTag = true;
|
|
79461
|
-
}
|
|
79462
|
-
|
|
79463
|
-
return xmlStr;
|
|
79464
|
-
}
|
|
79465
|
-
|
|
79466
|
-
function propName(obj) {
|
|
79467
|
-
const keys = Object.keys(obj);
|
|
79468
|
-
for (let i = 0; i < keys.length; i++) {
|
|
79469
|
-
const key = keys[i];
|
|
79470
|
-
if(!obj.hasOwnProperty(key)) continue;
|
|
79471
|
-
if (key !== ":@") return key;
|
|
79472
|
-
}
|
|
79473
|
-
}
|
|
79474
|
-
|
|
79475
|
-
function attr_to_str(attrMap, options) {
|
|
79476
|
-
let attrStr = "";
|
|
79477
|
-
if (attrMap && !options.ignoreAttributes) {
|
|
79478
|
-
for (let attr in attrMap) {
|
|
79479
|
-
if(!attrMap.hasOwnProperty(attr)) continue;
|
|
79480
|
-
let attrVal = options.attributeValueProcessor(attr, attrMap[attr]);
|
|
79481
|
-
attrVal = replaceEntitiesValue(attrVal, options);
|
|
79482
|
-
if (attrVal === true && options.suppressBooleanAttributes) {
|
|
79483
|
-
attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}`;
|
|
79484
|
-
} else {
|
|
79485
|
-
attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}="${attrVal}"`;
|
|
79486
|
-
}
|
|
79487
|
-
}
|
|
79488
|
-
}
|
|
79489
|
-
return attrStr;
|
|
79490
|
-
}
|
|
79491
|
-
|
|
79492
|
-
function isStopNode(jPath, options) {
|
|
79493
|
-
jPath = jPath.substr(0, jPath.length - options.textNodeName.length - 1);
|
|
79494
|
-
let tagName = jPath.substr(jPath.lastIndexOf(".") + 1);
|
|
79495
|
-
for (let index in options.stopNodes) {
|
|
79496
|
-
if (options.stopNodes[index] === jPath || options.stopNodes[index] === "*." + tagName) return true;
|
|
79497
|
-
}
|
|
79498
|
-
return false;
|
|
79499
|
-
}
|
|
79500
|
-
|
|
79501
|
-
function replaceEntitiesValue(textValue, options) {
|
|
79502
|
-
if (textValue && textValue.length > 0 && options.processEntities) {
|
|
79503
|
-
for (let i = 0; i < options.entities.length; i++) {
|
|
79504
|
-
const entity = options.entities[i];
|
|
79505
|
-
textValue = textValue.replace(entity.regex, entity.val);
|
|
79506
|
-
}
|
|
79507
|
-
}
|
|
79508
|
-
return textValue;
|
|
79509
|
-
}
|
|
79510
|
-
module.exports = toXml;
|
|
78554
|
+
/***/ "./src/util.js":
|
|
78555
|
+
/*!*********************!*\
|
|
78556
|
+
!*** ./src/util.js ***!
|
|
78557
|
+
\*********************/
|
|
78558
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
79511
78559
|
|
|
78560
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ getAllMatches: () => (/* binding */ getAllMatches),\n/* harmony export */ getValue: () => (/* binding */ getValue),\n/* harmony export */ isEmptyObject: () => (/* binding */ isEmptyObject),\n/* harmony export */ isExist: () => (/* binding */ isExist),\n/* harmony export */ isName: () => (/* binding */ isName),\n/* harmony export */ merge: () => (/* binding */ merge),\n/* harmony export */ nameRegexp: () => (/* binding */ nameRegexp)\n/* harmony export */ });\n\n\nconst nameStartChar = ':A-Za-z_\\\\u00C0-\\\\u00D6\\\\u00D8-\\\\u00F6\\\\u00F8-\\\\u02FF\\\\u0370-\\\\u037D\\\\u037F-\\\\u1FFF\\\\u200C-\\\\u200D\\\\u2070-\\\\u218F\\\\u2C00-\\\\u2FEF\\\\u3001-\\\\uD7FF\\\\uF900-\\\\uFDCF\\\\uFDF0-\\\\uFFFD';\nconst nameChar = nameStartChar + '\\\\-.\\\\d\\\\u00B7\\\\u0300-\\\\u036F\\\\u203F-\\\\u2040';\nconst nameRegexp = '[' + nameStartChar + '][' + nameChar + ']*';\nconst regexName = new RegExp('^' + nameRegexp + '$');\n\nfunction getAllMatches(string, regex) {\n const matches = [];\n let match = regex.exec(string);\n while (match) {\n const allmatches = [];\n allmatches.startIndex = regex.lastIndex - match[0].length;\n const len = match.length;\n for (let index = 0; index < len; index++) {\n allmatches.push(match[index]);\n }\n matches.push(allmatches);\n match = regex.exec(string);\n }\n return matches;\n}\n\nconst isName = function(string) {\n const match = regexName.exec(string);\n return !(match === null || typeof match === 'undefined');\n}\n\nfunction isExist(v) {\n return typeof v !== 'undefined';\n}\n\nfunction isEmptyObject(obj) {\n return Object.keys(obj).length === 0;\n}\n\n/**\n * Copy all the properties of a into b.\n * @param {*} target\n * @param {*} a\n */\nfunction merge(target, a, arrayMode) {\n if (a) {\n const keys = Object.keys(a); // will return an array of own properties\n const len = keys.length; //don't make it inline\n for (let i = 0; i < len; i++) {\n if (arrayMode === 'strict') {\n target[keys[i]] = [ a[keys[i]] ];\n } else {\n target[keys[i]] = a[keys[i]];\n }\n }\n }\n}\n/* exports.merge =function (b,a){\n return Object.assign(b,a);\n} */\n\nfunction getValue(v) {\n if (exports.isExist(v)) {\n return v;\n } else {\n return '';\n }\n}\n\n// const fakeCall = function(a) {return a;};\n// const fakeCallNoReturn = function() {};\n\n//# sourceURL=webpack://fast-xml-parser/./src/util.js?");
|
|
79512
78561
|
|
|
79513
78562
|
/***/ }),
|
|
79514
78563
|
|
|
79515
|
-
/***/ "./
|
|
79516
|
-
|
|
79517
|
-
!*** ./
|
|
79518
|
-
|
|
79519
|
-
/***/ ((
|
|
79520
|
-
|
|
79521
|
-
const util = __webpack_require__(/*! ../util */ "./node_modules/fast-xml-parser/src/util.js");
|
|
79522
|
-
|
|
79523
|
-
//TODO: handle comments
|
|
79524
|
-
function readDocType(xmlData, i){
|
|
79525
|
-
|
|
79526
|
-
const entities = {};
|
|
79527
|
-
if( xmlData[i + 3] === 'O' &&
|
|
79528
|
-
xmlData[i + 4] === 'C' &&
|
|
79529
|
-
xmlData[i + 5] === 'T' &&
|
|
79530
|
-
xmlData[i + 6] === 'Y' &&
|
|
79531
|
-
xmlData[i + 7] === 'P' &&
|
|
79532
|
-
xmlData[i + 8] === 'E')
|
|
79533
|
-
{
|
|
79534
|
-
i = i+9;
|
|
79535
|
-
let angleBracketsCount = 1;
|
|
79536
|
-
let hasBody = false, comment = false;
|
|
79537
|
-
let exp = "";
|
|
79538
|
-
for(;i<xmlData.length;i++){
|
|
79539
|
-
if (xmlData[i] === '<' && !comment) { //Determine the tag type
|
|
79540
|
-
if( hasBody && isEntity(xmlData, i)){
|
|
79541
|
-
i += 7;
|
|
79542
|
-
let entityName, val;
|
|
79543
|
-
[entityName, val,i] = readEntityExp(xmlData,i+1);
|
|
79544
|
-
if(val.indexOf("&") === -1) //Parameter entities are not supported
|
|
79545
|
-
entities[ validateEntityName(entityName) ] = {
|
|
79546
|
-
regx : RegExp( `&${entityName};`,"g"),
|
|
79547
|
-
val: val
|
|
79548
|
-
};
|
|
79549
|
-
}
|
|
79550
|
-
else if( hasBody && isElement(xmlData, i)) i += 8;//Not supported
|
|
79551
|
-
else if( hasBody && isAttlist(xmlData, i)) i += 8;//Not supported
|
|
79552
|
-
else if( hasBody && isNotation(xmlData, i)) i += 9;//Not supported
|
|
79553
|
-
else if( isComment) comment = true;
|
|
79554
|
-
else throw new Error("Invalid DOCTYPE");
|
|
79555
|
-
|
|
79556
|
-
angleBracketsCount++;
|
|
79557
|
-
exp = "";
|
|
79558
|
-
} else if (xmlData[i] === '>') { //Read tag content
|
|
79559
|
-
if(comment){
|
|
79560
|
-
if( xmlData[i - 1] === "-" && xmlData[i - 2] === "-"){
|
|
79561
|
-
comment = false;
|
|
79562
|
-
angleBracketsCount--;
|
|
79563
|
-
}
|
|
79564
|
-
}else{
|
|
79565
|
-
angleBracketsCount--;
|
|
79566
|
-
}
|
|
79567
|
-
if (angleBracketsCount === 0) {
|
|
79568
|
-
break;
|
|
79569
|
-
}
|
|
79570
|
-
}else if( xmlData[i] === '['){
|
|
79571
|
-
hasBody = true;
|
|
79572
|
-
}else{
|
|
79573
|
-
exp += xmlData[i];
|
|
79574
|
-
}
|
|
79575
|
-
}
|
|
79576
|
-
if(angleBracketsCount !== 0){
|
|
79577
|
-
throw new Error(`Unclosed DOCTYPE`);
|
|
79578
|
-
}
|
|
79579
|
-
}else{
|
|
79580
|
-
throw new Error(`Invalid Tag instead of DOCTYPE`);
|
|
79581
|
-
}
|
|
79582
|
-
return {entities, i};
|
|
79583
|
-
}
|
|
79584
|
-
|
|
79585
|
-
function readEntityExp(xmlData,i){
|
|
79586
|
-
//External entities are not supported
|
|
79587
|
-
// <!ENTITY ext SYSTEM "http://normal-website.com" >
|
|
79588
|
-
|
|
79589
|
-
//Parameter entities are not supported
|
|
79590
|
-
// <!ENTITY entityname "&anotherElement;">
|
|
79591
|
-
|
|
79592
|
-
//Internal entities are supported
|
|
79593
|
-
// <!ENTITY entityname "replacement text">
|
|
79594
|
-
|
|
79595
|
-
//read EntityName
|
|
79596
|
-
let entityName = "";
|
|
79597
|
-
for (; i < xmlData.length && (xmlData[i] !== "'" && xmlData[i] !== '"' ); i++) {
|
|
79598
|
-
// if(xmlData[i] === " ") continue;
|
|
79599
|
-
// else
|
|
79600
|
-
entityName += xmlData[i];
|
|
79601
|
-
}
|
|
79602
|
-
entityName = entityName.trim();
|
|
79603
|
-
if(entityName.indexOf(" ") !== -1) throw new Error("External entites are not supported");
|
|
79604
|
-
|
|
79605
|
-
//read Entity Value
|
|
79606
|
-
const startChar = xmlData[i++];
|
|
79607
|
-
let val = ""
|
|
79608
|
-
for (; i < xmlData.length && xmlData[i] !== startChar ; i++) {
|
|
79609
|
-
val += xmlData[i];
|
|
79610
|
-
}
|
|
79611
|
-
return [entityName, val, i];
|
|
79612
|
-
}
|
|
79613
|
-
|
|
79614
|
-
function isComment(xmlData, i){
|
|
79615
|
-
if(xmlData[i+1] === '!' &&
|
|
79616
|
-
xmlData[i+2] === '-' &&
|
|
79617
|
-
xmlData[i+3] === '-') return true
|
|
79618
|
-
return false
|
|
79619
|
-
}
|
|
79620
|
-
function isEntity(xmlData, i){
|
|
79621
|
-
if(xmlData[i+1] === '!' &&
|
|
79622
|
-
xmlData[i+2] === 'E' &&
|
|
79623
|
-
xmlData[i+3] === 'N' &&
|
|
79624
|
-
xmlData[i+4] === 'T' &&
|
|
79625
|
-
xmlData[i+5] === 'I' &&
|
|
79626
|
-
xmlData[i+6] === 'T' &&
|
|
79627
|
-
xmlData[i+7] === 'Y') return true
|
|
79628
|
-
return false
|
|
79629
|
-
}
|
|
79630
|
-
function isElement(xmlData, i){
|
|
79631
|
-
if(xmlData[i+1] === '!' &&
|
|
79632
|
-
xmlData[i+2] === 'E' &&
|
|
79633
|
-
xmlData[i+3] === 'L' &&
|
|
79634
|
-
xmlData[i+4] === 'E' &&
|
|
79635
|
-
xmlData[i+5] === 'M' &&
|
|
79636
|
-
xmlData[i+6] === 'E' &&
|
|
79637
|
-
xmlData[i+7] === 'N' &&
|
|
79638
|
-
xmlData[i+8] === 'T') return true
|
|
79639
|
-
return false
|
|
79640
|
-
}
|
|
79641
|
-
|
|
79642
|
-
function isAttlist(xmlData, i){
|
|
79643
|
-
if(xmlData[i+1] === '!' &&
|
|
79644
|
-
xmlData[i+2] === 'A' &&
|
|
79645
|
-
xmlData[i+3] === 'T' &&
|
|
79646
|
-
xmlData[i+4] === 'T' &&
|
|
79647
|
-
xmlData[i+5] === 'L' &&
|
|
79648
|
-
xmlData[i+6] === 'I' &&
|
|
79649
|
-
xmlData[i+7] === 'S' &&
|
|
79650
|
-
xmlData[i+8] === 'T') return true
|
|
79651
|
-
return false
|
|
79652
|
-
}
|
|
79653
|
-
function isNotation(xmlData, i){
|
|
79654
|
-
if(xmlData[i+1] === '!' &&
|
|
79655
|
-
xmlData[i+2] === 'N' &&
|
|
79656
|
-
xmlData[i+3] === 'O' &&
|
|
79657
|
-
xmlData[i+4] === 'T' &&
|
|
79658
|
-
xmlData[i+5] === 'A' &&
|
|
79659
|
-
xmlData[i+6] === 'T' &&
|
|
79660
|
-
xmlData[i+7] === 'I' &&
|
|
79661
|
-
xmlData[i+8] === 'O' &&
|
|
79662
|
-
xmlData[i+9] === 'N') return true
|
|
79663
|
-
return false
|
|
79664
|
-
}
|
|
79665
|
-
|
|
79666
|
-
function validateEntityName(name){
|
|
79667
|
-
if (util.isName(name))
|
|
79668
|
-
return name;
|
|
79669
|
-
else
|
|
79670
|
-
throw new Error(`Invalid entity name ${name}`);
|
|
79671
|
-
}
|
|
79672
|
-
|
|
79673
|
-
module.exports = readDocType;
|
|
78564
|
+
/***/ "./src/validator.js":
|
|
78565
|
+
/*!**************************!*\
|
|
78566
|
+
!*** ./src/validator.js ***!
|
|
78567
|
+
\**************************/
|
|
78568
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
79674
78569
|
|
|
78570
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ validate: () => (/* binding */ validate)\n/* harmony export */ });\n/* harmony import */ var _util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./util.js */ \"./src/util.js\");\n\n\n\n\nconst defaultOptions = {\n allowBooleanAttributes: false, //A tag can have attributes without any value\n unpairedTags: []\n};\n\n//const tagsPattern = new RegExp(\"<\\\\/?([\\\\w:\\\\-_\\.]+)\\\\s*\\/?>\",\"g\");\nfunction validate(xmlData, options) {\n options = Object.assign({}, defaultOptions, options);\n\n //xmlData = xmlData.replace(/(\\r\\n|\\n|\\r)/gm,\"\");//make it single line\n //xmlData = xmlData.replace(/(^\\s*<\\?xml.*?\\?>)/g,\"\");//Remove XML starting tag\n //xmlData = xmlData.replace(/(<!DOCTYPE[\\s\\w\\\"\\.\\/\\-\\:]+(\\[.*\\])*\\s*>)/g,\"\");//Remove DOCTYPE\n const tags = [];\n let tagFound = false;\n\n //indicates that the root tag has been closed (aka. depth 0 has been reached)\n let reachedRoot = false;\n\n if (xmlData[0] === '\\ufeff') {\n // check for byte order mark (BOM)\n xmlData = xmlData.substr(1);\n }\n \n for (let i = 0; i < xmlData.length; i++) {\n\n if (xmlData[i] === '<' && xmlData[i+1] === '?') {\n i+=2;\n i = readPI(xmlData,i);\n if (i.err) return i;\n }else if (xmlData[i] === '<') {\n //starting of tag\n //read until you reach to '>' avoiding any '>' in attribute value\n let tagStartPos = i;\n i++;\n \n if (xmlData[i] === '!') {\n i = readCommentAndCDATA(xmlData, i);\n continue;\n } else {\n let closingTag = false;\n if (xmlData[i] === '/') {\n //closing tag\n closingTag = true;\n i++;\n }\n //read tagname\n let tagName = '';\n for (; i < xmlData.length &&\n xmlData[i] !== '>' &&\n xmlData[i] !== ' ' &&\n xmlData[i] !== '\\t' &&\n xmlData[i] !== '\\n' &&\n xmlData[i] !== '\\r'; i++\n ) {\n tagName += xmlData[i];\n }\n tagName = tagName.trim();\n //console.log(tagName);\n\n if (tagName[tagName.length - 1] === '/') {\n //self closing tag without attributes\n tagName = tagName.substring(0, tagName.length - 1);\n //continue;\n i--;\n }\n if (!validateTagName(tagName)) {\n let msg;\n if (tagName.trim().length === 0) {\n msg = \"Invalid space after '<'.\";\n } else {\n msg = \"Tag '\"+tagName+\"' is an invalid name.\";\n }\n return getErrorObject('InvalidTag', msg, getLineNumberForPosition(xmlData, i));\n }\n\n const result = readAttributeStr(xmlData, i);\n if (result === false) {\n return getErrorObject('InvalidAttr', \"Attributes for '\"+tagName+\"' have open quote.\", getLineNumberForPosition(xmlData, i));\n }\n let attrStr = result.value;\n i = result.index;\n\n if (attrStr[attrStr.length - 1] === '/') {\n //self closing tag\n const attrStrStart = i - attrStr.length;\n attrStr = attrStr.substring(0, attrStr.length - 1);\n const isValid = validateAttributeString(attrStr, options);\n if (isValid === true) {\n tagFound = true;\n //continue; //text may presents after self closing tag\n } else {\n //the result from the nested function returns the position of the error within the attribute\n //in order to get the 'true' error line, we need to calculate the position where the attribute begins (i - attrStr.length) and then add the position within the attribute\n //this gives us the absolute index in the entire xml, which we can use to find the line at last\n return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, attrStrStart + isValid.err.line));\n }\n } else if (closingTag) {\n if (!result.tagClosed) {\n return getErrorObject('InvalidTag', \"Closing tag '\"+tagName+\"' doesn't have proper closing.\", getLineNumberForPosition(xmlData, i));\n } else if (attrStr.trim().length > 0) {\n return getErrorObject('InvalidTag', \"Closing tag '\"+tagName+\"' can't have attributes or invalid starting.\", getLineNumberForPosition(xmlData, tagStartPos));\n } else if (tags.length === 0) {\n return getErrorObject('InvalidTag', \"Closing tag '\"+tagName+\"' has not been opened.\", getLineNumberForPosition(xmlData, tagStartPos));\n } else {\n const otg = tags.pop();\n if (tagName !== otg.tagName) {\n let openPos = getLineNumberForPosition(xmlData, otg.tagStartPos);\n return getErrorObject('InvalidTag',\n \"Expected closing tag '\"+otg.tagName+\"' (opened in line \"+openPos.line+\", col \"+openPos.col+\") instead of closing tag '\"+tagName+\"'.\",\n getLineNumberForPosition(xmlData, tagStartPos));\n }\n\n //when there are no more tags, we reached the root level.\n if (tags.length == 0) {\n reachedRoot = true;\n }\n }\n } else {\n const isValid = validateAttributeString(attrStr, options);\n if (isValid !== true) {\n //the result from the nested function returns the position of the error within the attribute\n //in order to get the 'true' error line, we need to calculate the position where the attribute begins (i - attrStr.length) and then add the position within the attribute\n //this gives us the absolute index in the entire xml, which we can use to find the line at last\n return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, i - attrStr.length + isValid.err.line));\n }\n\n //if the root level has been reached before ...\n if (reachedRoot === true) {\n return getErrorObject('InvalidXml', 'Multiple possible root nodes found.', getLineNumberForPosition(xmlData, i));\n } else if(options.unpairedTags.indexOf(tagName) !== -1){\n //don't push into stack\n } else {\n tags.push({tagName, tagStartPos});\n }\n tagFound = true;\n }\n\n //skip tag text value\n //It may include comments and CDATA value\n for (i++; i < xmlData.length; i++) {\n if (xmlData[i] === '<') {\n if (xmlData[i + 1] === '!') {\n //comment or CADATA\n i++;\n i = readCommentAndCDATA(xmlData, i);\n continue;\n } else if (xmlData[i+1] === '?') {\n i = readPI(xmlData, ++i);\n if (i.err) return i;\n } else{\n break;\n }\n } else if (xmlData[i] === '&') {\n const afterAmp = validateAmpersand(xmlData, i);\n if (afterAmp == -1)\n return getErrorObject('InvalidChar', \"char '&' is not expected.\", getLineNumberForPosition(xmlData, i));\n i = afterAmp;\n }else{\n if (reachedRoot === true && !isWhiteSpace(xmlData[i])) {\n return getErrorObject('InvalidXml', \"Extra text at the end\", getLineNumberForPosition(xmlData, i));\n }\n }\n } //end of reading tag text value\n if (xmlData[i] === '<') {\n i--;\n }\n }\n } else {\n if ( isWhiteSpace(xmlData[i])) {\n continue;\n }\n return getErrorObject('InvalidChar', \"char '\"+xmlData[i]+\"' is not expected.\", getLineNumberForPosition(xmlData, i));\n }\n }\n\n if (!tagFound) {\n return getErrorObject('InvalidXml', 'Start tag expected.', 1);\n }else if (tags.length == 1) {\n return getErrorObject('InvalidTag', \"Unclosed tag '\"+tags[0].tagName+\"'.\", getLineNumberForPosition(xmlData, tags[0].tagStartPos));\n }else if (tags.length > 0) {\n return getErrorObject('InvalidXml', \"Invalid '\"+\n JSON.stringify(tags.map(t => t.tagName), null, 4).replace(/\\r?\\n/g, '')+\n \"' found.\", {line: 1, col: 1});\n }\n\n return true;\n};\n\nfunction isWhiteSpace(char){\n return char === ' ' || char === '\\t' || char === '\\n' || char === '\\r';\n}\n/**\n * Read Processing insstructions and skip\n * @param {*} xmlData\n * @param {*} i\n */\nfunction readPI(xmlData, i) {\n const start = i;\n for (; i < xmlData.length; i++) {\n if (xmlData[i] == '?' || xmlData[i] == ' ') {\n //tagname\n const tagname = xmlData.substr(start, i - start);\n if (i > 5 && tagname === 'xml') {\n return getErrorObject('InvalidXml', 'XML declaration allowed only at the start of the document.', getLineNumberForPosition(xmlData, i));\n } else if (xmlData[i] == '?' && xmlData[i + 1] == '>') {\n //check if valid attribut string\n i++;\n break;\n } else {\n continue;\n }\n }\n }\n return i;\n}\n\nfunction readCommentAndCDATA(xmlData, i) {\n if (xmlData.length > i + 5 && xmlData[i + 1] === '-' && xmlData[i + 2] === '-') {\n //comment\n for (i += 3; i < xmlData.length; i++) {\n if (xmlData[i] === '-' && xmlData[i + 1] === '-' && xmlData[i + 2] === '>') {\n i += 2;\n break;\n }\n }\n } else if (\n xmlData.length > i + 8 &&\n xmlData[i + 1] === 'D' &&\n xmlData[i + 2] === 'O' &&\n xmlData[i + 3] === 'C' &&\n xmlData[i + 4] === 'T' &&\n xmlData[i + 5] === 'Y' &&\n xmlData[i + 6] === 'P' &&\n xmlData[i + 7] === 'E'\n ) {\n let angleBracketsCount = 1;\n for (i += 8; i < xmlData.length; i++) {\n if (xmlData[i] === '<') {\n angleBracketsCount++;\n } else if (xmlData[i] === '>') {\n angleBracketsCount--;\n if (angleBracketsCount === 0) {\n break;\n }\n }\n }\n } else if (\n xmlData.length > i + 9 &&\n xmlData[i + 1] === '[' &&\n xmlData[i + 2] === 'C' &&\n xmlData[i + 3] === 'D' &&\n xmlData[i + 4] === 'A' &&\n xmlData[i + 5] === 'T' &&\n xmlData[i + 6] === 'A' &&\n xmlData[i + 7] === '['\n ) {\n for (i += 8; i < xmlData.length; i++) {\n if (xmlData[i] === ']' && xmlData[i + 1] === ']' && xmlData[i + 2] === '>') {\n i += 2;\n break;\n }\n }\n }\n\n return i;\n}\n\nconst doubleQuote = '\"';\nconst singleQuote = \"'\";\n\n/**\n * Keep reading xmlData until '<' is found outside the attribute value.\n * @param {string} xmlData\n * @param {number} i\n */\nfunction readAttributeStr(xmlData, i) {\n let attrStr = '';\n let startChar = '';\n let tagClosed = false;\n for (; i < xmlData.length; i++) {\n if (xmlData[i] === doubleQuote || xmlData[i] === singleQuote) {\n if (startChar === '') {\n startChar = xmlData[i];\n } else if (startChar !== xmlData[i]) {\n //if vaue is enclosed with double quote then single quotes are allowed inside the value and vice versa\n } else {\n startChar = '';\n }\n } else if (xmlData[i] === '>') {\n if (startChar === '') {\n tagClosed = true;\n break;\n }\n }\n attrStr += xmlData[i];\n }\n if (startChar !== '') {\n return false;\n }\n\n return {\n value: attrStr,\n index: i,\n tagClosed: tagClosed\n };\n}\n\n/**\n * Select all the attributes whether valid or invalid.\n */\nconst validAttrStrRegxp = new RegExp('(\\\\s*)([^\\\\s=]+)(\\\\s*=)?(\\\\s*([\\'\"])(([\\\\s\\\\S])*?)\\\\5)?', 'g');\n\n//attr, =\"sd\", a=\"amit's\", a=\"sd\"b=\"saf\", ab cd=\"\"\n\nfunction validateAttributeString(attrStr, options) {\n //console.log(\"start:\"+attrStr+\":end\");\n\n //if(attrStr.trim().length === 0) return true; //empty string\n\n const matches = (0,_util_js__WEBPACK_IMPORTED_MODULE_0__.getAllMatches)(attrStr, validAttrStrRegxp);\n const attrNames = {};\n\n for (let i = 0; i < matches.length; i++) {\n if (matches[i][1].length === 0) {\n //nospace before attribute name: a=\"sd\"b=\"saf\"\n return getErrorObject('InvalidAttr', \"Attribute '\"+matches[i][2]+\"' has no space in starting.\", getPositionFromMatch(matches[i]))\n } else if (matches[i][3] !== undefined && matches[i][4] === undefined) {\n return getErrorObject('InvalidAttr', \"Attribute '\"+matches[i][2]+\"' is without value.\", getPositionFromMatch(matches[i]));\n } else if (matches[i][3] === undefined && !options.allowBooleanAttributes) {\n //independent attribute: ab\n return getErrorObject('InvalidAttr', \"boolean attribute '\"+matches[i][2]+\"' is not allowed.\", getPositionFromMatch(matches[i]));\n }\n /* else if(matches[i][6] === undefined){//attribute without value: ab=\n return { err: { code:\"InvalidAttr\",msg:\"attribute \" + matches[i][2] + \" has no value assigned.\"}};\n } */\n const attrName = matches[i][2];\n if (!validateAttrName(attrName)) {\n return getErrorObject('InvalidAttr', \"Attribute '\"+attrName+\"' is an invalid name.\", getPositionFromMatch(matches[i]));\n }\n if (!attrNames.hasOwnProperty(attrName)) {\n //check for duplicate attribute.\n attrNames[attrName] = 1;\n } else {\n return getErrorObject('InvalidAttr', \"Attribute '\"+attrName+\"' is repeated.\", getPositionFromMatch(matches[i]));\n }\n }\n\n return true;\n}\n\nfunction validateNumberAmpersand(xmlData, i) {\n let re = /\\d/;\n if (xmlData[i] === 'x') {\n i++;\n re = /[\\da-fA-F]/;\n }\n for (; i < xmlData.length; i++) {\n if (xmlData[i] === ';')\n return i;\n if (!xmlData[i].match(re))\n break;\n }\n return -1;\n}\n\nfunction validateAmpersand(xmlData, i) {\n // https://www.w3.org/TR/xml/#dt-charref\n i++;\n if (xmlData[i] === ';')\n return -1;\n if (xmlData[i] === '#') {\n i++;\n return validateNumberAmpersand(xmlData, i);\n }\n let count = 0;\n for (; i < xmlData.length; i++, count++) {\n if (xmlData[i].match(/\\w/) && count < 20)\n continue;\n if (xmlData[i] === ';')\n break;\n return -1;\n }\n return i;\n}\n\nfunction getErrorObject(code, message, lineNumber) {\n return {\n err: {\n code: code,\n msg: message,\n line: lineNumber.line || lineNumber,\n col: lineNumber.col,\n },\n };\n}\n\nfunction validateAttrName(attrName) {\n return (0,_util_js__WEBPACK_IMPORTED_MODULE_0__.isName)(attrName);\n}\n\n// const startsWithXML = /^xml/i;\n\nfunction validateTagName(tagname) {\n return (0,_util_js__WEBPACK_IMPORTED_MODULE_0__.isName)(tagname) /* && !tagname.match(startsWithXML) */;\n}\n\n//this function returns the line number for the character at the given index\nfunction getLineNumberForPosition(xmlData, index) {\n const lines = xmlData.substring(0, index).split(/\\r?\\n/);\n return {\n line: lines.length,\n\n // column number is last line's length + 1, because column numbering starts at 1:\n col: lines[lines.length - 1].length + 1\n };\n}\n\n//this function returns the position of the first character of match within attrStr\nfunction getPositionFromMatch(match) {\n return match.startIndex + match[1].length;\n}\n\n\n//# sourceURL=webpack://fast-xml-parser/./src/validator.js?");
|
|
79675
78571
|
|
|
79676
78572
|
/***/ }),
|
|
79677
78573
|
|
|
79678
|
-
/***/ "./
|
|
79679
|
-
|
|
79680
|
-
!*** ./
|
|
79681
|
-
|
|
79682
|
-
/***/ ((
|
|
79683
|
-
|
|
79684
|
-
|
|
79685
|
-
const defaultOptions = {
|
|
79686
|
-
preserveOrder: false,
|
|
79687
|
-
attributeNamePrefix: '@_',
|
|
79688
|
-
attributesGroupName: false,
|
|
79689
|
-
textNodeName: '#text',
|
|
79690
|
-
ignoreAttributes: true,
|
|
79691
|
-
removeNSPrefix: false, // remove NS from tag name or attribute name if true
|
|
79692
|
-
allowBooleanAttributes: false, //a tag can have attributes without any value
|
|
79693
|
-
//ignoreRootElement : false,
|
|
79694
|
-
parseTagValue: true,
|
|
79695
|
-
parseAttributeValue: false,
|
|
79696
|
-
trimValues: true, //Trim string values of tag and attributes
|
|
79697
|
-
cdataPropName: false,
|
|
79698
|
-
numberParseOptions: {
|
|
79699
|
-
hex: true,
|
|
79700
|
-
leadingZeros: true,
|
|
79701
|
-
eNotation: true
|
|
79702
|
-
},
|
|
79703
|
-
tagValueProcessor: function(tagName, val) {
|
|
79704
|
-
return val;
|
|
79705
|
-
},
|
|
79706
|
-
attributeValueProcessor: function(attrName, val) {
|
|
79707
|
-
return val;
|
|
79708
|
-
},
|
|
79709
|
-
stopNodes: [], //nested tags will not be parsed even for errors
|
|
79710
|
-
alwaysCreateTextNode: false,
|
|
79711
|
-
isArray: () => false,
|
|
79712
|
-
commentPropName: false,
|
|
79713
|
-
unpairedTags: [],
|
|
79714
|
-
processEntities: true,
|
|
79715
|
-
htmlEntities: false,
|
|
79716
|
-
ignoreDeclaration: false,
|
|
79717
|
-
ignorePiTags: false,
|
|
79718
|
-
transformTagName: false,
|
|
79719
|
-
transformAttributeName: false,
|
|
79720
|
-
updateTag: function(tagName, jPath, attrs){
|
|
79721
|
-
return tagName
|
|
79722
|
-
},
|
|
79723
|
-
// skipEmptyListItem: false
|
|
79724
|
-
};
|
|
79725
|
-
|
|
79726
|
-
const buildOptions = function(options) {
|
|
79727
|
-
return Object.assign({}, defaultOptions, options);
|
|
79728
|
-
};
|
|
78574
|
+
/***/ "./src/xmlbuilder/json2xml.js":
|
|
78575
|
+
/*!************************************!*\
|
|
78576
|
+
!*** ./src/xmlbuilder/json2xml.js ***!
|
|
78577
|
+
\************************************/
|
|
78578
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
79729
78579
|
|
|
79730
|
-
exports.buildOptions = buildOptions;
|
|
79731
|
-
exports.defaultOptions = defaultOptions;
|
|
78580
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ Builder)\n/* harmony export */ });\n/* harmony import */ var _orderedJs2Xml_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./orderedJs2Xml.js */ \"./src/xmlbuilder/orderedJs2Xml.js\");\n/* harmony import */ var _ignoreAttributes_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../ignoreAttributes.js */ \"./src/ignoreAttributes.js\");\n\n//parse Empty Node as self closing node\n\n\n\nconst defaultOptions = {\n attributeNamePrefix: '@_',\n attributesGroupName: false,\n textNodeName: '#text',\n ignoreAttributes: true,\n cdataPropName: false,\n format: false,\n indentBy: ' ',\n suppressEmptyNode: false,\n suppressUnpairedNode: true,\n suppressBooleanAttributes: true,\n tagValueProcessor: function(key, a) {\n return a;\n },\n attributeValueProcessor: function(attrName, a) {\n return a;\n },\n preserveOrder: false,\n commentPropName: false,\n unpairedTags: [],\n entities: [\n { regex: new RegExp(\"&\", \"g\"), val: \"&\" },//it must be on top\n { regex: new RegExp(\">\", \"g\"), val: \">\" },\n { regex: new RegExp(\"<\", \"g\"), val: \"<\" },\n { regex: new RegExp(\"\\'\", \"g\"), val: \"'\" },\n { regex: new RegExp(\"\\\"\", \"g\"), val: \""\" }\n ],\n processEntities: true,\n stopNodes: [],\n // transformTagName: false,\n // transformAttributeName: false,\n oneListGroup: false\n};\n\nfunction Builder(options) {\n this.options = Object.assign({}, defaultOptions, options);\n if (this.options.ignoreAttributes === true || this.options.attributesGroupName) {\n this.isAttribute = function(/*a*/) {\n return false;\n };\n } else {\n this.ignoreAttributesFn = (0,_ignoreAttributes_js__WEBPACK_IMPORTED_MODULE_1__[\"default\"])(this.options.ignoreAttributes)\n this.attrPrefixLen = this.options.attributeNamePrefix.length;\n this.isAttribute = isAttribute;\n }\n\n this.processTextOrObjNode = processTextOrObjNode\n\n if (this.options.format) {\n this.indentate = indentate;\n this.tagEndChar = '>\\n';\n this.newLine = '\\n';\n } else {\n this.indentate = function() {\n return '';\n };\n this.tagEndChar = '>';\n this.newLine = '';\n }\n}\n\nBuilder.prototype.build = function(jObj) {\n if(this.options.preserveOrder){\n return (0,_orderedJs2Xml_js__WEBPACK_IMPORTED_MODULE_0__[\"default\"])(jObj, this.options);\n }else {\n if(Array.isArray(jObj) && this.options.arrayNodeName && this.options.arrayNodeName.length > 1){\n jObj = {\n [this.options.arrayNodeName] : jObj\n }\n }\n return this.j2x(jObj, 0, []).val;\n }\n};\n\nBuilder.prototype.j2x = function(jObj, level, ajPath) {\n let attrStr = '';\n let val = '';\n const jPath = ajPath.join('.')\n for (let key in jObj) {\n if(!Object.prototype.hasOwnProperty.call(jObj, key)) continue;\n if (typeof jObj[key] === 'undefined') {\n // supress undefined node only if it is not an attribute\n if (this.isAttribute(key)) {\n val += '';\n }\n } else if (jObj[key] === null) {\n // null attribute should be ignored by the attribute list, but should not cause the tag closing\n if (this.isAttribute(key)) {\n val += '';\n } else if (key === this.options.cdataPropName) {\n val += '';\n } else if (key[0] === '?') {\n val += this.indentate(level) + '<' + key + '?' + this.tagEndChar;\n } else {\n val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;\n }\n // val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;\n } else if (jObj[key] instanceof Date) {\n val += this.buildTextValNode(jObj[key], key, '', level);\n } else if (typeof jObj[key] !== 'object') {\n //premitive type\n const attr = this.isAttribute(key);\n if (attr && !this.ignoreAttributesFn(attr, jPath)) {\n attrStr += this.buildAttrPairStr(attr, '' + jObj[key]);\n } else if (!attr) {\n //tag value\n if (key === this.options.textNodeName) {\n let newval = this.options.tagValueProcessor(key, '' + jObj[key]);\n val += this.replaceEntitiesValue(newval);\n } else {\n val += this.buildTextValNode(jObj[key], key, '', level);\n }\n }\n } else if (Array.isArray(jObj[key])) {\n //repeated nodes\n const arrLen = jObj[key].length;\n let listTagVal = \"\";\n let listTagAttr = \"\";\n for (let j = 0; j < arrLen; j++) {\n const item = jObj[key][j];\n if (typeof item === 'undefined') {\n // supress undefined node\n } else if (item === null) {\n if(key[0] === \"?\") val += this.indentate(level) + '<' + key + '?' + this.tagEndChar;\n else val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;\n // val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;\n } else if (typeof item === 'object') {\n if(this.options.oneListGroup){\n const result = this.j2x(item, level + 1, ajPath.concat(key));\n listTagVal += result.val;\n if (this.options.attributesGroupName && item.hasOwnProperty(this.options.attributesGroupName)) {\n listTagAttr += result.attrStr\n }\n }else{\n listTagVal += this.processTextOrObjNode(item, key, level, ajPath)\n }\n } else {\n if (this.options.oneListGroup) {\n let textValue = this.options.tagValueProcessor(key, item);\n textValue = this.replaceEntitiesValue(textValue);\n listTagVal += textValue;\n } else {\n listTagVal += this.buildTextValNode(item, key, '', level);\n }\n }\n }\n if(this.options.oneListGroup){\n listTagVal = this.buildObjectNode(listTagVal, key, listTagAttr, level);\n }\n val += listTagVal;\n } else {\n //nested node\n if (this.options.attributesGroupName && key === this.options.attributesGroupName) {\n const Ks = Object.keys(jObj[key]);\n const L = Ks.length;\n for (let j = 0; j < L; j++) {\n attrStr += this.buildAttrPairStr(Ks[j], '' + jObj[key][Ks[j]]);\n }\n } else {\n val += this.processTextOrObjNode(jObj[key], key, level, ajPath)\n }\n }\n }\n return {attrStr: attrStr, val: val};\n};\n\nBuilder.prototype.buildAttrPairStr = function(attrName, val){\n val = this.options.attributeValueProcessor(attrName, '' + val);\n val = this.replaceEntitiesValue(val);\n if (this.options.suppressBooleanAttributes && val === \"true\") {\n return ' ' + attrName;\n } else return ' ' + attrName + '=\"' + val + '\"';\n}\n\nfunction processTextOrObjNode (object, key, level, ajPath) {\n const result = this.j2x(object, level + 1, ajPath.concat(key));\n if (object[this.options.textNodeName] !== undefined && Object.keys(object).length === 1) {\n return this.buildTextValNode(object[this.options.textNodeName], key, result.attrStr, level);\n } else {\n return this.buildObjectNode(result.val, key, result.attrStr, level);\n }\n}\n\nBuilder.prototype.buildObjectNode = function(val, key, attrStr, level) {\n if(val === \"\"){\n if(key[0] === \"?\") return this.indentate(level) + '<' + key + attrStr+ '?' + this.tagEndChar;\n else {\n return this.indentate(level) + '<' + key + attrStr + this.closeTag(key) + this.tagEndChar;\n }\n }else{\n\n let tagEndExp = '</' + key + this.tagEndChar;\n let piClosingChar = \"\";\n \n if(key[0] === \"?\") {\n piClosingChar = \"?\";\n tagEndExp = \"\";\n }\n \n // attrStr is an empty string in case the attribute came as undefined or null\n if ((attrStr || attrStr === '') && val.indexOf('<') === -1) {\n return ( this.indentate(level) + '<' + key + attrStr + piClosingChar + '>' + val + tagEndExp );\n } else if (this.options.commentPropName !== false && key === this.options.commentPropName && piClosingChar.length === 0) {\n return this.indentate(level) + `<!--${val}-->` + this.newLine;\n }else {\n return (\n this.indentate(level) + '<' + key + attrStr + piClosingChar + this.tagEndChar +\n val +\n this.indentate(level) + tagEndExp );\n }\n }\n}\n\nBuilder.prototype.closeTag = function(key){\n let closeTag = \"\";\n if(this.options.unpairedTags.indexOf(key) !== -1){ //unpaired\n if(!this.options.suppressUnpairedNode) closeTag = \"/\"\n }else if(this.options.suppressEmptyNode){ //empty\n closeTag = \"/\";\n }else{\n closeTag = `></${key}`\n }\n return closeTag;\n}\n\nfunction buildEmptyObjNode(val, key, attrStr, level) {\n if (val !== '') {\n return this.buildObjectNode(val, key, attrStr, level);\n } else {\n if(key[0] === \"?\") return this.indentate(level) + '<' + key + attrStr+ '?' + this.tagEndChar;\n else {\n return this.indentate(level) + '<' + key + attrStr + '/' + this.tagEndChar;\n // return this.buildTagStr(level,key, attrStr);\n }\n }\n}\n\nBuilder.prototype.buildTextValNode = function(val, key, attrStr, level) {\n if (this.options.cdataPropName !== false && key === this.options.cdataPropName) {\n return this.indentate(level) + `<![CDATA[${val}]]>` + this.newLine;\n }else if (this.options.commentPropName !== false && key === this.options.commentPropName) {\n return this.indentate(level) + `<!--${val}-->` + this.newLine;\n }else if(key[0] === \"?\") {//PI tag\n return this.indentate(level) + '<' + key + attrStr+ '?' + this.tagEndChar; \n }else{\n let textValue = this.options.tagValueProcessor(key, val);\n textValue = this.replaceEntitiesValue(textValue);\n \n if( textValue === ''){\n return this.indentate(level) + '<' + key + attrStr + this.closeTag(key) + this.tagEndChar;\n }else{\n return this.indentate(level) + '<' + key + attrStr + '>' +\n textValue +\n '</' + key + this.tagEndChar;\n }\n }\n}\n\nBuilder.prototype.replaceEntitiesValue = function(textValue){\n if(textValue && textValue.length > 0 && this.options.processEntities){\n for (let i=0; i<this.options.entities.length; i++) {\n const entity = this.options.entities[i];\n textValue = textValue.replace(entity.regex, entity.val);\n }\n }\n return textValue;\n}\n\nfunction indentate(level) {\n return this.options.indentBy.repeat(level);\n}\n\nfunction isAttribute(name /*, options*/) {\n if (name.startsWith(this.options.attributeNamePrefix) && name !== this.options.textNodeName) {\n return name.substr(this.attrPrefixLen);\n } else {\n return false;\n }\n}\n\n\n\n//# sourceURL=webpack://fast-xml-parser/./src/xmlbuilder/json2xml.js?");
|
|
79732
78581
|
|
|
79733
78582
|
/***/ }),
|
|
79734
78583
|
|
|
79735
|
-
/***/ "./
|
|
79736
|
-
|
|
79737
|
-
!*** ./
|
|
79738
|
-
|
|
79739
|
-
/***/ ((
|
|
79740
|
-
|
|
79741
|
-
"use strict";
|
|
79742
|
-
|
|
79743
|
-
///@ts-check
|
|
79744
|
-
|
|
79745
|
-
const util = __webpack_require__(/*! ../util */ "./node_modules/fast-xml-parser/src/util.js");
|
|
79746
|
-
const xmlNode = __webpack_require__(/*! ./xmlNode */ "./node_modules/fast-xml-parser/src/xmlparser/xmlNode.js");
|
|
79747
|
-
const readDocType = __webpack_require__(/*! ./DocTypeReader */ "./node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js");
|
|
79748
|
-
const toNumber = __webpack_require__(/*! strnum */ "./node_modules/strnum/strnum.js");
|
|
79749
|
-
const getIgnoreAttributesFn = __webpack_require__(/*! ../ignoreAttributes */ "./node_modules/fast-xml-parser/src/ignoreAttributes.js")
|
|
79750
|
-
|
|
79751
|
-
// const regx =
|
|
79752
|
-
// '<((!\\[CDATA\\[([\\s\\S]*?)(]]>))|((NAME:)?(NAME))([^>]*)>|((\\/)(NAME)\\s*>))([^<]*)'
|
|
79753
|
-
// .replace(/NAME/g, util.nameRegexp);
|
|
79754
|
-
|
|
79755
|
-
//const tagsRegx = new RegExp("<(\\/?[\\w:\\-\._]+)([^>]*)>(\\s*"+cdataRegx+")*([^<]+)?","g");
|
|
79756
|
-
//const tagsRegx = new RegExp("<(\\/?)((\\w*:)?([\\w:\\-\._]+))([^>]*)>([^<]*)("+cdataRegx+"([^<]*))*([^<]+)?","g");
|
|
79757
|
-
|
|
79758
|
-
class OrderedObjParser{
|
|
79759
|
-
constructor(options){
|
|
79760
|
-
this.options = options;
|
|
79761
|
-
this.currentNode = null;
|
|
79762
|
-
this.tagsNodeStack = [];
|
|
79763
|
-
this.docTypeEntities = {};
|
|
79764
|
-
this.lastEntities = {
|
|
79765
|
-
"apos" : { regex: /&(apos|#39|#x27);/g, val : "'"},
|
|
79766
|
-
"gt" : { regex: /&(gt|#62|#x3E);/g, val : ">"},
|
|
79767
|
-
"lt" : { regex: /&(lt|#60|#x3C);/g, val : "<"},
|
|
79768
|
-
"quot" : { regex: /&(quot|#34|#x22);/g, val : "\""},
|
|
79769
|
-
};
|
|
79770
|
-
this.ampEntity = { regex: /&(amp|#38|#x26);/g, val : "&"};
|
|
79771
|
-
this.htmlEntities = {
|
|
79772
|
-
"space": { regex: /&(nbsp|#160);/g, val: " " },
|
|
79773
|
-
// "lt" : { regex: /&(lt|#60);/g, val: "<" },
|
|
79774
|
-
// "gt" : { regex: /&(gt|#62);/g, val: ">" },
|
|
79775
|
-
// "amp" : { regex: /&(amp|#38);/g, val: "&" },
|
|
79776
|
-
// "quot" : { regex: /&(quot|#34);/g, val: "\"" },
|
|
79777
|
-
// "apos" : { regex: /&(apos|#39);/g, val: "'" },
|
|
79778
|
-
"cent" : { regex: /&(cent|#162);/g, val: "¢" },
|
|
79779
|
-
"pound" : { regex: /&(pound|#163);/g, val: "£" },
|
|
79780
|
-
"yen" : { regex: /&(yen|#165);/g, val: "¥" },
|
|
79781
|
-
"euro" : { regex: /&(euro|#8364);/g, val: "€" },
|
|
79782
|
-
"copyright" : { regex: /&(copy|#169);/g, val: "©" },
|
|
79783
|
-
"reg" : { regex: /&(reg|#174);/g, val: "®" },
|
|
79784
|
-
"inr" : { regex: /&(inr|#8377);/g, val: "₹" },
|
|
79785
|
-
"num_dec": { regex: /&#([0-9]{1,7});/g, val : (_, str) => String.fromCharCode(Number.parseInt(str, 10)) },
|
|
79786
|
-
"num_hex": { regex: /&#x([0-9a-fA-F]{1,6});/g, val : (_, str) => String.fromCharCode(Number.parseInt(str, 16)) },
|
|
79787
|
-
};
|
|
79788
|
-
this.addExternalEntities = addExternalEntities;
|
|
79789
|
-
this.parseXml = parseXml;
|
|
79790
|
-
this.parseTextData = parseTextData;
|
|
79791
|
-
this.resolveNameSpace = resolveNameSpace;
|
|
79792
|
-
this.buildAttributesMap = buildAttributesMap;
|
|
79793
|
-
this.isItStopNode = isItStopNode;
|
|
79794
|
-
this.replaceEntitiesValue = replaceEntitiesValue;
|
|
79795
|
-
this.readStopNodeData = readStopNodeData;
|
|
79796
|
-
this.saveTextToParentTag = saveTextToParentTag;
|
|
79797
|
-
this.addChild = addChild;
|
|
79798
|
-
this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes)
|
|
79799
|
-
}
|
|
79800
|
-
|
|
79801
|
-
}
|
|
79802
|
-
|
|
79803
|
-
function addExternalEntities(externalEntities){
|
|
79804
|
-
const entKeys = Object.keys(externalEntities);
|
|
79805
|
-
for (let i = 0; i < entKeys.length; i++) {
|
|
79806
|
-
const ent = entKeys[i];
|
|
79807
|
-
this.lastEntities[ent] = {
|
|
79808
|
-
regex: new RegExp("&"+ent+";","g"),
|
|
79809
|
-
val : externalEntities[ent]
|
|
79810
|
-
}
|
|
79811
|
-
}
|
|
79812
|
-
}
|
|
79813
|
-
|
|
79814
|
-
/**
|
|
79815
|
-
* @param {string} val
|
|
79816
|
-
* @param {string} tagName
|
|
79817
|
-
* @param {string} jPath
|
|
79818
|
-
* @param {boolean} dontTrim
|
|
79819
|
-
* @param {boolean} hasAttributes
|
|
79820
|
-
* @param {boolean} isLeafNode
|
|
79821
|
-
* @param {boolean} escapeEntities
|
|
79822
|
-
*/
|
|
79823
|
-
function parseTextData(val, tagName, jPath, dontTrim, hasAttributes, isLeafNode, escapeEntities) {
|
|
79824
|
-
if (val !== undefined) {
|
|
79825
|
-
if (this.options.trimValues && !dontTrim) {
|
|
79826
|
-
val = val.trim();
|
|
79827
|
-
}
|
|
79828
|
-
if(val.length > 0){
|
|
79829
|
-
if(!escapeEntities) val = this.replaceEntitiesValue(val);
|
|
79830
|
-
|
|
79831
|
-
const newval = this.options.tagValueProcessor(tagName, val, jPath, hasAttributes, isLeafNode);
|
|
79832
|
-
if(newval === null || newval === undefined){
|
|
79833
|
-
//don't parse
|
|
79834
|
-
return val;
|
|
79835
|
-
}else if(typeof newval !== typeof val || newval !== val){
|
|
79836
|
-
//overwrite
|
|
79837
|
-
return newval;
|
|
79838
|
-
}else if(this.options.trimValues){
|
|
79839
|
-
return parseValue(val, this.options.parseTagValue, this.options.numberParseOptions);
|
|
79840
|
-
}else{
|
|
79841
|
-
const trimmedVal = val.trim();
|
|
79842
|
-
if(trimmedVal === val){
|
|
79843
|
-
return parseValue(val, this.options.parseTagValue, this.options.numberParseOptions);
|
|
79844
|
-
}else{
|
|
79845
|
-
return val;
|
|
79846
|
-
}
|
|
79847
|
-
}
|
|
79848
|
-
}
|
|
79849
|
-
}
|
|
79850
|
-
}
|
|
79851
|
-
|
|
79852
|
-
function resolveNameSpace(tagname) {
|
|
79853
|
-
if (this.options.removeNSPrefix) {
|
|
79854
|
-
const tags = tagname.split(':');
|
|
79855
|
-
const prefix = tagname.charAt(0) === '/' ? '/' : '';
|
|
79856
|
-
if (tags[0] === 'xmlns') {
|
|
79857
|
-
return '';
|
|
79858
|
-
}
|
|
79859
|
-
if (tags.length === 2) {
|
|
79860
|
-
tagname = prefix + tags[1];
|
|
79861
|
-
}
|
|
79862
|
-
}
|
|
79863
|
-
return tagname;
|
|
79864
|
-
}
|
|
79865
|
-
|
|
79866
|
-
//TODO: change regex to capture NS
|
|
79867
|
-
//const attrsRegx = new RegExp("([\\w\\-\\.\\:]+)\\s*=\\s*(['\"])((.|\n)*?)\\2","gm");
|
|
79868
|
-
const attrsRegx = new RegExp('([^\\s=]+)\\s*(=\\s*([\'"])([\\s\\S]*?)\\3)?', 'gm');
|
|
79869
|
-
|
|
79870
|
-
function buildAttributesMap(attrStr, jPath, tagName) {
|
|
79871
|
-
if (this.options.ignoreAttributes !== true && typeof attrStr === 'string') {
|
|
79872
|
-
// attrStr = attrStr.replace(/\r?\n/g, ' ');
|
|
79873
|
-
//attrStr = attrStr || attrStr.trim();
|
|
79874
|
-
|
|
79875
|
-
const matches = util.getAllMatches(attrStr, attrsRegx);
|
|
79876
|
-
const len = matches.length; //don't make it inline
|
|
79877
|
-
const attrs = {};
|
|
79878
|
-
for (let i = 0; i < len; i++) {
|
|
79879
|
-
const attrName = this.resolveNameSpace(matches[i][1]);
|
|
79880
|
-
if (this.ignoreAttributesFn(attrName, jPath)) {
|
|
79881
|
-
continue
|
|
79882
|
-
}
|
|
79883
|
-
let oldVal = matches[i][4];
|
|
79884
|
-
let aName = this.options.attributeNamePrefix + attrName;
|
|
79885
|
-
if (attrName.length) {
|
|
79886
|
-
if (this.options.transformAttributeName) {
|
|
79887
|
-
aName = this.options.transformAttributeName(aName);
|
|
79888
|
-
}
|
|
79889
|
-
if(aName === "__proto__") aName = "#__proto__";
|
|
79890
|
-
if (oldVal !== undefined) {
|
|
79891
|
-
if (this.options.trimValues) {
|
|
79892
|
-
oldVal = oldVal.trim();
|
|
79893
|
-
}
|
|
79894
|
-
oldVal = this.replaceEntitiesValue(oldVal);
|
|
79895
|
-
const newVal = this.options.attributeValueProcessor(attrName, oldVal, jPath);
|
|
79896
|
-
if(newVal === null || newVal === undefined){
|
|
79897
|
-
//don't parse
|
|
79898
|
-
attrs[aName] = oldVal;
|
|
79899
|
-
}else if(typeof newVal !== typeof oldVal || newVal !== oldVal){
|
|
79900
|
-
//overwrite
|
|
79901
|
-
attrs[aName] = newVal;
|
|
79902
|
-
}else{
|
|
79903
|
-
//parse
|
|
79904
|
-
attrs[aName] = parseValue(
|
|
79905
|
-
oldVal,
|
|
79906
|
-
this.options.parseAttributeValue,
|
|
79907
|
-
this.options.numberParseOptions
|
|
79908
|
-
);
|
|
79909
|
-
}
|
|
79910
|
-
} else if (this.options.allowBooleanAttributes) {
|
|
79911
|
-
attrs[aName] = true;
|
|
79912
|
-
}
|
|
79913
|
-
}
|
|
79914
|
-
}
|
|
79915
|
-
if (!Object.keys(attrs).length) {
|
|
79916
|
-
return;
|
|
79917
|
-
}
|
|
79918
|
-
if (this.options.attributesGroupName) {
|
|
79919
|
-
const attrCollection = {};
|
|
79920
|
-
attrCollection[this.options.attributesGroupName] = attrs;
|
|
79921
|
-
return attrCollection;
|
|
79922
|
-
}
|
|
79923
|
-
return attrs
|
|
79924
|
-
}
|
|
79925
|
-
}
|
|
79926
|
-
|
|
79927
|
-
const parseXml = function(xmlData) {
|
|
79928
|
-
xmlData = xmlData.replace(/\r\n?/g, "\n"); //TODO: remove this line
|
|
79929
|
-
const xmlObj = new xmlNode('!xml');
|
|
79930
|
-
let currentNode = xmlObj;
|
|
79931
|
-
let textData = "";
|
|
79932
|
-
let jPath = "";
|
|
79933
|
-
for(let i=0; i< xmlData.length; i++){//for each char in XML data
|
|
79934
|
-
const ch = xmlData[i];
|
|
79935
|
-
if(ch === '<'){
|
|
79936
|
-
// const nextIndex = i+1;
|
|
79937
|
-
// const _2ndChar = xmlData[nextIndex];
|
|
79938
|
-
if( xmlData[i+1] === '/') {//Closing Tag
|
|
79939
|
-
const closeIndex = findClosingIndex(xmlData, ">", i, "Closing Tag is not closed.")
|
|
79940
|
-
let tagName = xmlData.substring(i+2,closeIndex).trim();
|
|
79941
|
-
|
|
79942
|
-
if(this.options.removeNSPrefix){
|
|
79943
|
-
const colonIndex = tagName.indexOf(":");
|
|
79944
|
-
if(colonIndex !== -1){
|
|
79945
|
-
tagName = tagName.substr(colonIndex+1);
|
|
79946
|
-
}
|
|
79947
|
-
}
|
|
79948
|
-
|
|
79949
|
-
if(this.options.transformTagName) {
|
|
79950
|
-
tagName = this.options.transformTagName(tagName);
|
|
79951
|
-
}
|
|
79952
|
-
|
|
79953
|
-
if(currentNode){
|
|
79954
|
-
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
79955
|
-
}
|
|
79956
|
-
|
|
79957
|
-
//check if last tag of nested tag was unpaired tag
|
|
79958
|
-
const lastTagName = jPath.substring(jPath.lastIndexOf(".")+1);
|
|
79959
|
-
if(tagName && this.options.unpairedTags.indexOf(tagName) !== -1 ){
|
|
79960
|
-
throw new Error(`Unpaired tag can not be used as closing tag: </${tagName}>`);
|
|
79961
|
-
}
|
|
79962
|
-
let propIndex = 0
|
|
79963
|
-
if(lastTagName && this.options.unpairedTags.indexOf(lastTagName) !== -1 ){
|
|
79964
|
-
propIndex = jPath.lastIndexOf('.', jPath.lastIndexOf('.')-1)
|
|
79965
|
-
this.tagsNodeStack.pop();
|
|
79966
|
-
}else{
|
|
79967
|
-
propIndex = jPath.lastIndexOf(".");
|
|
79968
|
-
}
|
|
79969
|
-
jPath = jPath.substring(0, propIndex);
|
|
79970
|
-
|
|
79971
|
-
currentNode = this.tagsNodeStack.pop();//avoid recursion, set the parent tag scope
|
|
79972
|
-
textData = "";
|
|
79973
|
-
i = closeIndex;
|
|
79974
|
-
} else if( xmlData[i+1] === '?') {
|
|
79975
|
-
|
|
79976
|
-
let tagData = readTagExp(xmlData,i, false, "?>");
|
|
79977
|
-
if(!tagData) throw new Error("Pi Tag is not closed.");
|
|
79978
|
-
|
|
79979
|
-
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
79980
|
-
if( (this.options.ignoreDeclaration && tagData.tagName === "?xml") || this.options.ignorePiTags){
|
|
79981
|
-
|
|
79982
|
-
}else{
|
|
79983
|
-
|
|
79984
|
-
const childNode = new xmlNode(tagData.tagName);
|
|
79985
|
-
childNode.add(this.options.textNodeName, "");
|
|
79986
|
-
|
|
79987
|
-
if(tagData.tagName !== tagData.tagExp && tagData.attrExpPresent){
|
|
79988
|
-
childNode[":@"] = this.buildAttributesMap(tagData.tagExp, jPath, tagData.tagName);
|
|
79989
|
-
}
|
|
79990
|
-
this.addChild(currentNode, childNode, jPath)
|
|
79991
|
-
|
|
79992
|
-
}
|
|
79993
|
-
|
|
79994
|
-
|
|
79995
|
-
i = tagData.closeIndex + 1;
|
|
79996
|
-
} else if(xmlData.substr(i + 1, 3) === '!--') {
|
|
79997
|
-
const endIndex = findClosingIndex(xmlData, "-->", i+4, "Comment is not closed.")
|
|
79998
|
-
if(this.options.commentPropName){
|
|
79999
|
-
const comment = xmlData.substring(i + 4, endIndex - 2);
|
|
80000
|
-
|
|
80001
|
-
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
80002
|
-
|
|
80003
|
-
currentNode.add(this.options.commentPropName, [ { [this.options.textNodeName] : comment } ]);
|
|
80004
|
-
}
|
|
80005
|
-
i = endIndex;
|
|
80006
|
-
} else if( xmlData.substr(i + 1, 2) === '!D') {
|
|
80007
|
-
const result = readDocType(xmlData, i);
|
|
80008
|
-
this.docTypeEntities = result.entities;
|
|
80009
|
-
i = result.i;
|
|
80010
|
-
}else if(xmlData.substr(i + 1, 2) === '![') {
|
|
80011
|
-
const closeIndex = findClosingIndex(xmlData, "]]>", i, "CDATA is not closed.") - 2;
|
|
80012
|
-
const tagExp = xmlData.substring(i + 9,closeIndex);
|
|
80013
|
-
|
|
80014
|
-
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
80015
|
-
|
|
80016
|
-
let val = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true, true);
|
|
80017
|
-
if(val == undefined) val = "";
|
|
80018
|
-
|
|
80019
|
-
//cdata should be set even if it is 0 length string
|
|
80020
|
-
if(this.options.cdataPropName){
|
|
80021
|
-
currentNode.add(this.options.cdataPropName, [ { [this.options.textNodeName] : tagExp } ]);
|
|
80022
|
-
}else{
|
|
80023
|
-
currentNode.add(this.options.textNodeName, val);
|
|
80024
|
-
}
|
|
80025
|
-
|
|
80026
|
-
i = closeIndex + 2;
|
|
80027
|
-
}else {//Opening tag
|
|
80028
|
-
let result = readTagExp(xmlData,i, this.options.removeNSPrefix);
|
|
80029
|
-
let tagName= result.tagName;
|
|
80030
|
-
const rawTagName = result.rawTagName;
|
|
80031
|
-
let tagExp = result.tagExp;
|
|
80032
|
-
let attrExpPresent = result.attrExpPresent;
|
|
80033
|
-
let closeIndex = result.closeIndex;
|
|
80034
|
-
|
|
80035
|
-
if (this.options.transformTagName) {
|
|
80036
|
-
tagName = this.options.transformTagName(tagName);
|
|
80037
|
-
}
|
|
80038
|
-
|
|
80039
|
-
//save text as child node
|
|
80040
|
-
if (currentNode && textData) {
|
|
80041
|
-
if(currentNode.tagname !== '!xml'){
|
|
80042
|
-
//when nested tag is found
|
|
80043
|
-
textData = this.saveTextToParentTag(textData, currentNode, jPath, false);
|
|
80044
|
-
}
|
|
80045
|
-
}
|
|
80046
|
-
|
|
80047
|
-
//check if last tag was unpaired tag
|
|
80048
|
-
const lastTag = currentNode;
|
|
80049
|
-
if(lastTag && this.options.unpairedTags.indexOf(lastTag.tagname) !== -1 ){
|
|
80050
|
-
currentNode = this.tagsNodeStack.pop();
|
|
80051
|
-
jPath = jPath.substring(0, jPath.lastIndexOf("."));
|
|
80052
|
-
}
|
|
80053
|
-
if(tagName !== xmlObj.tagname){
|
|
80054
|
-
jPath += jPath ? "." + tagName : tagName;
|
|
80055
|
-
}
|
|
80056
|
-
if (this.isItStopNode(this.options.stopNodes, jPath, tagName)) {
|
|
80057
|
-
let tagContent = "";
|
|
80058
|
-
//self-closing tag
|
|
80059
|
-
if(tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1){
|
|
80060
|
-
if(tagName[tagName.length - 1] === "/"){ //remove trailing '/'
|
|
80061
|
-
tagName = tagName.substr(0, tagName.length - 1);
|
|
80062
|
-
jPath = jPath.substr(0, jPath.length - 1);
|
|
80063
|
-
tagExp = tagName;
|
|
80064
|
-
}else{
|
|
80065
|
-
tagExp = tagExp.substr(0, tagExp.length - 1);
|
|
80066
|
-
}
|
|
80067
|
-
i = result.closeIndex;
|
|
80068
|
-
}
|
|
80069
|
-
//unpaired tag
|
|
80070
|
-
else if(this.options.unpairedTags.indexOf(tagName) !== -1){
|
|
80071
|
-
|
|
80072
|
-
i = result.closeIndex;
|
|
80073
|
-
}
|
|
80074
|
-
//normal tag
|
|
80075
|
-
else{
|
|
80076
|
-
//read until closing tag is found
|
|
80077
|
-
const result = this.readStopNodeData(xmlData, rawTagName, closeIndex + 1);
|
|
80078
|
-
if(!result) throw new Error(`Unexpected end of ${rawTagName}`);
|
|
80079
|
-
i = result.i;
|
|
80080
|
-
tagContent = result.tagContent;
|
|
80081
|
-
}
|
|
80082
|
-
|
|
80083
|
-
const childNode = new xmlNode(tagName);
|
|
80084
|
-
if(tagName !== tagExp && attrExpPresent){
|
|
80085
|
-
childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
|
|
80086
|
-
}
|
|
80087
|
-
if(tagContent) {
|
|
80088
|
-
tagContent = this.parseTextData(tagContent, tagName, jPath, true, attrExpPresent, true, true);
|
|
80089
|
-
}
|
|
80090
|
-
|
|
80091
|
-
jPath = jPath.substr(0, jPath.lastIndexOf("."));
|
|
80092
|
-
childNode.add(this.options.textNodeName, tagContent);
|
|
80093
|
-
|
|
80094
|
-
this.addChild(currentNode, childNode, jPath)
|
|
80095
|
-
}else{
|
|
80096
|
-
//selfClosing tag
|
|
80097
|
-
if(tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1){
|
|
80098
|
-
if(tagName[tagName.length - 1] === "/"){ //remove trailing '/'
|
|
80099
|
-
tagName = tagName.substr(0, tagName.length - 1);
|
|
80100
|
-
jPath = jPath.substr(0, jPath.length - 1);
|
|
80101
|
-
tagExp = tagName;
|
|
80102
|
-
}else{
|
|
80103
|
-
tagExp = tagExp.substr(0, tagExp.length - 1);
|
|
80104
|
-
}
|
|
80105
|
-
|
|
80106
|
-
if(this.options.transformTagName) {
|
|
80107
|
-
tagName = this.options.transformTagName(tagName);
|
|
80108
|
-
}
|
|
80109
|
-
|
|
80110
|
-
const childNode = new xmlNode(tagName);
|
|
80111
|
-
if(tagName !== tagExp && attrExpPresent){
|
|
80112
|
-
childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
|
|
80113
|
-
}
|
|
80114
|
-
this.addChild(currentNode, childNode, jPath)
|
|
80115
|
-
jPath = jPath.substr(0, jPath.lastIndexOf("."));
|
|
80116
|
-
}
|
|
80117
|
-
//opening tag
|
|
80118
|
-
else{
|
|
80119
|
-
const childNode = new xmlNode( tagName);
|
|
80120
|
-
this.tagsNodeStack.push(currentNode);
|
|
80121
|
-
|
|
80122
|
-
if(tagName !== tagExp && attrExpPresent){
|
|
80123
|
-
childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
|
|
80124
|
-
}
|
|
80125
|
-
this.addChild(currentNode, childNode, jPath)
|
|
80126
|
-
currentNode = childNode;
|
|
80127
|
-
}
|
|
80128
|
-
textData = "";
|
|
80129
|
-
i = closeIndex;
|
|
80130
|
-
}
|
|
80131
|
-
}
|
|
80132
|
-
}else{
|
|
80133
|
-
textData += xmlData[i];
|
|
80134
|
-
}
|
|
80135
|
-
}
|
|
80136
|
-
return xmlObj.child;
|
|
80137
|
-
}
|
|
80138
|
-
|
|
80139
|
-
function addChild(currentNode, childNode, jPath){
|
|
80140
|
-
const result = this.options.updateTag(childNode.tagname, jPath, childNode[":@"])
|
|
80141
|
-
if(result === false){
|
|
80142
|
-
}else if(typeof result === "string"){
|
|
80143
|
-
childNode.tagname = result
|
|
80144
|
-
currentNode.addChild(childNode);
|
|
80145
|
-
}else{
|
|
80146
|
-
currentNode.addChild(childNode);
|
|
80147
|
-
}
|
|
80148
|
-
}
|
|
80149
|
-
|
|
80150
|
-
const replaceEntitiesValue = function(val){
|
|
80151
|
-
|
|
80152
|
-
if(this.options.processEntities){
|
|
80153
|
-
for(let entityName in this.docTypeEntities){
|
|
80154
|
-
const entity = this.docTypeEntities[entityName];
|
|
80155
|
-
val = val.replace( entity.regx, entity.val);
|
|
80156
|
-
}
|
|
80157
|
-
for(let entityName in this.lastEntities){
|
|
80158
|
-
const entity = this.lastEntities[entityName];
|
|
80159
|
-
val = val.replace( entity.regex, entity.val);
|
|
80160
|
-
}
|
|
80161
|
-
if(this.options.htmlEntities){
|
|
80162
|
-
for(let entityName in this.htmlEntities){
|
|
80163
|
-
const entity = this.htmlEntities[entityName];
|
|
80164
|
-
val = val.replace( entity.regex, entity.val);
|
|
80165
|
-
}
|
|
80166
|
-
}
|
|
80167
|
-
val = val.replace( this.ampEntity.regex, this.ampEntity.val);
|
|
80168
|
-
}
|
|
80169
|
-
return val;
|
|
80170
|
-
}
|
|
80171
|
-
function saveTextToParentTag(textData, currentNode, jPath, isLeafNode) {
|
|
80172
|
-
if (textData) { //store previously collected data as textNode
|
|
80173
|
-
if(isLeafNode === undefined) isLeafNode = currentNode.child.length === 0
|
|
80174
|
-
|
|
80175
|
-
textData = this.parseTextData(textData,
|
|
80176
|
-
currentNode.tagname,
|
|
80177
|
-
jPath,
|
|
80178
|
-
false,
|
|
80179
|
-
currentNode[":@"] ? Object.keys(currentNode[":@"]).length !== 0 : false,
|
|
80180
|
-
isLeafNode);
|
|
80181
|
-
|
|
80182
|
-
if (textData !== undefined && textData !== "")
|
|
80183
|
-
currentNode.add(this.options.textNodeName, textData);
|
|
80184
|
-
textData = "";
|
|
80185
|
-
}
|
|
80186
|
-
return textData;
|
|
80187
|
-
}
|
|
80188
|
-
|
|
80189
|
-
//TODO: use jPath to simplify the logic
|
|
80190
|
-
/**
|
|
80191
|
-
*
|
|
80192
|
-
* @param {string[]} stopNodes
|
|
80193
|
-
* @param {string} jPath
|
|
80194
|
-
* @param {string} currentTagName
|
|
80195
|
-
*/
|
|
80196
|
-
function isItStopNode(stopNodes, jPath, currentTagName){
|
|
80197
|
-
const allNodesExp = "*." + currentTagName;
|
|
80198
|
-
for (const stopNodePath in stopNodes) {
|
|
80199
|
-
const stopNodeExp = stopNodes[stopNodePath];
|
|
80200
|
-
if( allNodesExp === stopNodeExp || jPath === stopNodeExp ) return true;
|
|
80201
|
-
}
|
|
80202
|
-
return false;
|
|
80203
|
-
}
|
|
80204
|
-
|
|
80205
|
-
/**
|
|
80206
|
-
* Returns the tag Expression and where it is ending handling single-double quotes situation
|
|
80207
|
-
* @param {string} xmlData
|
|
80208
|
-
* @param {number} i starting index
|
|
80209
|
-
* @returns
|
|
80210
|
-
*/
|
|
80211
|
-
function tagExpWithClosingIndex(xmlData, i, closingChar = ">"){
|
|
80212
|
-
let attrBoundary;
|
|
80213
|
-
let tagExp = "";
|
|
80214
|
-
for (let index = i; index < xmlData.length; index++) {
|
|
80215
|
-
let ch = xmlData[index];
|
|
80216
|
-
if (attrBoundary) {
|
|
80217
|
-
if (ch === attrBoundary) attrBoundary = "";//reset
|
|
80218
|
-
} else if (ch === '"' || ch === "'") {
|
|
80219
|
-
attrBoundary = ch;
|
|
80220
|
-
} else if (ch === closingChar[0]) {
|
|
80221
|
-
if(closingChar[1]){
|
|
80222
|
-
if(xmlData[index + 1] === closingChar[1]){
|
|
80223
|
-
return {
|
|
80224
|
-
data: tagExp,
|
|
80225
|
-
index: index
|
|
80226
|
-
}
|
|
80227
|
-
}
|
|
80228
|
-
}else{
|
|
80229
|
-
return {
|
|
80230
|
-
data: tagExp,
|
|
80231
|
-
index: index
|
|
80232
|
-
}
|
|
80233
|
-
}
|
|
80234
|
-
} else if (ch === '\t') {
|
|
80235
|
-
ch = " "
|
|
80236
|
-
}
|
|
80237
|
-
tagExp += ch;
|
|
80238
|
-
}
|
|
80239
|
-
}
|
|
80240
|
-
|
|
80241
|
-
function findClosingIndex(xmlData, str, i, errMsg){
|
|
80242
|
-
const closingIndex = xmlData.indexOf(str, i);
|
|
80243
|
-
if(closingIndex === -1){
|
|
80244
|
-
throw new Error(errMsg)
|
|
80245
|
-
}else{
|
|
80246
|
-
return closingIndex + str.length - 1;
|
|
80247
|
-
}
|
|
80248
|
-
}
|
|
80249
|
-
|
|
80250
|
-
function readTagExp(xmlData,i, removeNSPrefix, closingChar = ">"){
|
|
80251
|
-
const result = tagExpWithClosingIndex(xmlData, i+1, closingChar);
|
|
80252
|
-
if(!result) return;
|
|
80253
|
-
let tagExp = result.data;
|
|
80254
|
-
const closeIndex = result.index;
|
|
80255
|
-
const separatorIndex = tagExp.search(/\s/);
|
|
80256
|
-
let tagName = tagExp;
|
|
80257
|
-
let attrExpPresent = true;
|
|
80258
|
-
if(separatorIndex !== -1){//separate tag name and attributes expression
|
|
80259
|
-
tagName = tagExp.substring(0, separatorIndex);
|
|
80260
|
-
tagExp = tagExp.substring(separatorIndex + 1).trimStart();
|
|
80261
|
-
}
|
|
80262
|
-
|
|
80263
|
-
const rawTagName = tagName;
|
|
80264
|
-
if(removeNSPrefix){
|
|
80265
|
-
const colonIndex = tagName.indexOf(":");
|
|
80266
|
-
if(colonIndex !== -1){
|
|
80267
|
-
tagName = tagName.substr(colonIndex+1);
|
|
80268
|
-
attrExpPresent = tagName !== result.data.substr(colonIndex + 1);
|
|
80269
|
-
}
|
|
80270
|
-
}
|
|
80271
|
-
|
|
80272
|
-
return {
|
|
80273
|
-
tagName: tagName,
|
|
80274
|
-
tagExp: tagExp,
|
|
80275
|
-
closeIndex: closeIndex,
|
|
80276
|
-
attrExpPresent: attrExpPresent,
|
|
80277
|
-
rawTagName: rawTagName,
|
|
80278
|
-
}
|
|
80279
|
-
}
|
|
80280
|
-
/**
|
|
80281
|
-
* find paired tag for a stop node
|
|
80282
|
-
* @param {string} xmlData
|
|
80283
|
-
* @param {string} tagName
|
|
80284
|
-
* @param {number} i
|
|
80285
|
-
*/
|
|
80286
|
-
function readStopNodeData(xmlData, tagName, i){
|
|
80287
|
-
const startIndex = i;
|
|
80288
|
-
// Starting at 1 since we already have an open tag
|
|
80289
|
-
let openTagCount = 1;
|
|
80290
|
-
|
|
80291
|
-
for (; i < xmlData.length; i++) {
|
|
80292
|
-
if( xmlData[i] === "<"){
|
|
80293
|
-
if (xmlData[i+1] === "/") {//close tag
|
|
80294
|
-
const closeIndex = findClosingIndex(xmlData, ">", i, `${tagName} is not closed`);
|
|
80295
|
-
let closeTagName = xmlData.substring(i+2,closeIndex).trim();
|
|
80296
|
-
if(closeTagName === tagName){
|
|
80297
|
-
openTagCount--;
|
|
80298
|
-
if (openTagCount === 0) {
|
|
80299
|
-
return {
|
|
80300
|
-
tagContent: xmlData.substring(startIndex, i),
|
|
80301
|
-
i : closeIndex
|
|
80302
|
-
}
|
|
80303
|
-
}
|
|
80304
|
-
}
|
|
80305
|
-
i=closeIndex;
|
|
80306
|
-
} else if(xmlData[i+1] === '?') {
|
|
80307
|
-
const closeIndex = findClosingIndex(xmlData, "?>", i+1, "StopNode is not closed.")
|
|
80308
|
-
i=closeIndex;
|
|
80309
|
-
} else if(xmlData.substr(i + 1, 3) === '!--') {
|
|
80310
|
-
const closeIndex = findClosingIndex(xmlData, "-->", i+3, "StopNode is not closed.")
|
|
80311
|
-
i=closeIndex;
|
|
80312
|
-
} else if(xmlData.substr(i + 1, 2) === '![') {
|
|
80313
|
-
const closeIndex = findClosingIndex(xmlData, "]]>", i, "StopNode is not closed.") - 2;
|
|
80314
|
-
i=closeIndex;
|
|
80315
|
-
} else {
|
|
80316
|
-
const tagData = readTagExp(xmlData, i, '>')
|
|
80317
|
-
|
|
80318
|
-
if (tagData) {
|
|
80319
|
-
const openTagName = tagData && tagData.tagName;
|
|
80320
|
-
if (openTagName === tagName && tagData.tagExp[tagData.tagExp.length-1] !== "/") {
|
|
80321
|
-
openTagCount++;
|
|
80322
|
-
}
|
|
80323
|
-
i=tagData.closeIndex;
|
|
80324
|
-
}
|
|
80325
|
-
}
|
|
80326
|
-
}
|
|
80327
|
-
}//end for loop
|
|
80328
|
-
}
|
|
80329
|
-
|
|
80330
|
-
function parseValue(val, shouldParse, options) {
|
|
80331
|
-
if (shouldParse && typeof val === 'string') {
|
|
80332
|
-
//console.log(options)
|
|
80333
|
-
const newval = val.trim();
|
|
80334
|
-
if(newval === 'true' ) return true;
|
|
80335
|
-
else if(newval === 'false' ) return false;
|
|
80336
|
-
else return toNumber(val, options);
|
|
80337
|
-
} else {
|
|
80338
|
-
if (util.isExist(val)) {
|
|
80339
|
-
return val;
|
|
80340
|
-
} else {
|
|
80341
|
-
return '';
|
|
80342
|
-
}
|
|
80343
|
-
}
|
|
80344
|
-
}
|
|
80345
|
-
|
|
80346
|
-
|
|
80347
|
-
module.exports = OrderedObjParser;
|
|
78584
|
+
/***/ "./src/xmlbuilder/orderedJs2Xml.js":
|
|
78585
|
+
/*!*****************************************!*\
|
|
78586
|
+
!*** ./src/xmlbuilder/orderedJs2Xml.js ***!
|
|
78587
|
+
\*****************************************/
|
|
78588
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
80348
78589
|
|
|
78590
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ toXml)\n/* harmony export */ });\nconst EOL = \"\\n\";\n\n/**\n * \n * @param {array} jArray \n * @param {any} options \n * @returns \n */\nfunction toXml(jArray, options) {\n let indentation = \"\";\n if (options.format && options.indentBy.length > 0) {\n indentation = EOL;\n }\n return arrToStr(jArray, options, \"\", indentation);\n}\n\nfunction arrToStr(arr, options, jPath, indentation) {\n let xmlStr = \"\";\n let isPreviousElementTag = false;\n\n for (let i = 0; i < arr.length; i++) {\n const tagObj = arr[i];\n const tagName = propName(tagObj);\n if(tagName === undefined) continue;\n\n let newJPath = \"\";\n if (jPath.length === 0) newJPath = tagName\n else newJPath = `${jPath}.${tagName}`;\n\n if (tagName === options.textNodeName) {\n let tagText = tagObj[tagName];\n if (!isStopNode(newJPath, options)) {\n tagText = options.tagValueProcessor(tagName, tagText);\n tagText = replaceEntitiesValue(tagText, options);\n }\n if (isPreviousElementTag) {\n xmlStr += indentation;\n }\n xmlStr += tagText;\n isPreviousElementTag = false;\n continue;\n } else if (tagName === options.cdataPropName) {\n if (isPreviousElementTag) {\n xmlStr += indentation;\n }\n xmlStr += `<![CDATA[${tagObj[tagName][0][options.textNodeName]}]]>`;\n isPreviousElementTag = false;\n continue;\n } else if (tagName === options.commentPropName) {\n xmlStr += indentation + `<!--${tagObj[tagName][0][options.textNodeName]}-->`;\n isPreviousElementTag = true;\n continue;\n } else if (tagName[0] === \"?\") {\n const attStr = attr_to_str(tagObj[\":@\"], options);\n const tempInd = tagName === \"?xml\" ? \"\" : indentation;\n let piTextNodeName = tagObj[tagName][0][options.textNodeName];\n piTextNodeName = piTextNodeName.length !== 0 ? \" \" + piTextNodeName : \"\"; //remove extra spacing\n xmlStr += tempInd + `<${tagName}${piTextNodeName}${attStr}?>`;\n isPreviousElementTag = true;\n continue;\n }\n let newIdentation = indentation;\n if (newIdentation !== \"\") {\n newIdentation += options.indentBy;\n }\n const attStr = attr_to_str(tagObj[\":@\"], options);\n const tagStart = indentation + `<${tagName}${attStr}`;\n const tagValue = arrToStr(tagObj[tagName], options, newJPath, newIdentation);\n if (options.unpairedTags.indexOf(tagName) !== -1) {\n if (options.suppressUnpairedNode) xmlStr += tagStart + \">\";\n else xmlStr += tagStart + \"/>\";\n } else if ((!tagValue || tagValue.length === 0) && options.suppressEmptyNode) {\n xmlStr += tagStart + \"/>\";\n } else if (tagValue && tagValue.endsWith(\">\")) {\n xmlStr += tagStart + `>${tagValue}${indentation}</${tagName}>`;\n } else {\n xmlStr += tagStart + \">\";\n if (tagValue && indentation !== \"\" && (tagValue.includes(\"/>\") || tagValue.includes(\"</\"))) {\n xmlStr += indentation + options.indentBy + tagValue + indentation;\n } else {\n xmlStr += tagValue;\n }\n xmlStr += `</${tagName}>`;\n }\n isPreviousElementTag = true;\n }\n\n return xmlStr;\n}\n\nfunction propName(obj) {\n const keys = Object.keys(obj);\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n if(!obj.hasOwnProperty(key)) continue;\n if (key !== \":@\") return key;\n }\n}\n\nfunction attr_to_str(attrMap, options) {\n let attrStr = \"\";\n if (attrMap && !options.ignoreAttributes) {\n for (let attr in attrMap) {\n if(!attrMap.hasOwnProperty(attr)) continue;\n let attrVal = options.attributeValueProcessor(attr, attrMap[attr]);\n attrVal = replaceEntitiesValue(attrVal, options);\n if (attrVal === true && options.suppressBooleanAttributes) {\n attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}`;\n } else {\n attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}=\"${attrVal}\"`;\n }\n }\n }\n return attrStr;\n}\n\nfunction isStopNode(jPath, options) {\n jPath = jPath.substr(0, jPath.length - options.textNodeName.length - 1);\n let tagName = jPath.substr(jPath.lastIndexOf(\".\") + 1);\n for (let index in options.stopNodes) {\n if (options.stopNodes[index] === jPath || options.stopNodes[index] === \"*.\" + tagName) return true;\n }\n return false;\n}\n\nfunction replaceEntitiesValue(textValue, options) {\n if (textValue && textValue.length > 0 && options.processEntities) {\n for (let i = 0; i < options.entities.length; i++) {\n const entity = options.entities[i];\n textValue = textValue.replace(entity.regex, entity.val);\n }\n }\n return textValue;\n}\n\n\n//# sourceURL=webpack://fast-xml-parser/./src/xmlbuilder/orderedJs2Xml.js?");
|
|
80349
78591
|
|
|
80350
78592
|
/***/ }),
|
|
80351
78593
|
|
|
80352
|
-
/***/ "./
|
|
80353
|
-
|
|
80354
|
-
!*** ./
|
|
80355
|
-
|
|
80356
|
-
/***/ ((
|
|
80357
|
-
|
|
80358
|
-
const { buildOptions} = __webpack_require__(/*! ./OptionsBuilder */ "./node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js");
|
|
80359
|
-
const OrderedObjParser = __webpack_require__(/*! ./OrderedObjParser */ "./node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js");
|
|
80360
|
-
const { prettify} = __webpack_require__(/*! ./node2json */ "./node_modules/fast-xml-parser/src/xmlparser/node2json.js");
|
|
80361
|
-
const validator = __webpack_require__(/*! ../validator */ "./node_modules/fast-xml-parser/src/validator.js");
|
|
80362
|
-
|
|
80363
|
-
class XMLParser{
|
|
80364
|
-
|
|
80365
|
-
constructor(options){
|
|
80366
|
-
this.externalEntities = {};
|
|
80367
|
-
this.options = buildOptions(options);
|
|
80368
|
-
|
|
80369
|
-
}
|
|
80370
|
-
/**
|
|
80371
|
-
* Parse XML dats to JS object
|
|
80372
|
-
* @param {string|Buffer} xmlData
|
|
80373
|
-
* @param {boolean|Object} validationOption
|
|
80374
|
-
*/
|
|
80375
|
-
parse(xmlData,validationOption){
|
|
80376
|
-
if(typeof xmlData === "string"){
|
|
80377
|
-
}else if( xmlData.toString){
|
|
80378
|
-
xmlData = xmlData.toString();
|
|
80379
|
-
}else{
|
|
80380
|
-
throw new Error("XML data is accepted in String or Bytes[] form.")
|
|
80381
|
-
}
|
|
80382
|
-
if( validationOption){
|
|
80383
|
-
if(validationOption === true) validationOption = {}; //validate with default options
|
|
80384
|
-
|
|
80385
|
-
const result = validator.validate(xmlData, validationOption);
|
|
80386
|
-
if (result !== true) {
|
|
80387
|
-
throw Error( `${result.err.msg}:${result.err.line}:${result.err.col}` )
|
|
80388
|
-
}
|
|
80389
|
-
}
|
|
80390
|
-
const orderedObjParser = new OrderedObjParser(this.options);
|
|
80391
|
-
orderedObjParser.addExternalEntities(this.externalEntities);
|
|
80392
|
-
const orderedResult = orderedObjParser.parseXml(xmlData);
|
|
80393
|
-
if(this.options.preserveOrder || orderedResult === undefined) return orderedResult;
|
|
80394
|
-
else return prettify(orderedResult, this.options);
|
|
80395
|
-
}
|
|
80396
|
-
|
|
80397
|
-
/**
|
|
80398
|
-
* Add Entity which is not by default supported by this library
|
|
80399
|
-
* @param {string} key
|
|
80400
|
-
* @param {string} value
|
|
80401
|
-
*/
|
|
80402
|
-
addEntity(key, value){
|
|
80403
|
-
if(value.indexOf("&") !== -1){
|
|
80404
|
-
throw new Error("Entity value can't have '&'")
|
|
80405
|
-
}else if(key.indexOf("&") !== -1 || key.indexOf(";") !== -1){
|
|
80406
|
-
throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '
'")
|
|
80407
|
-
}else if(value === "&"){
|
|
80408
|
-
throw new Error("An entity with value '&' is not permitted");
|
|
80409
|
-
}else{
|
|
80410
|
-
this.externalEntities[key] = value;
|
|
80411
|
-
}
|
|
80412
|
-
}
|
|
80413
|
-
}
|
|
78594
|
+
/***/ "./src/xmlparser/DocTypeReader.js":
|
|
78595
|
+
/*!****************************************!*\
|
|
78596
|
+
!*** ./src/xmlparser/DocTypeReader.js ***!
|
|
78597
|
+
\****************************************/
|
|
78598
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
80414
78599
|
|
|
80415
|
-
|
|
78600
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ readDocType)\n/* harmony export */ });\n/* harmony import */ var _util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../util.js */ \"./src/util.js\");\n\n\n//TODO: handle comments\nfunction readDocType(xmlData, i){\n \n const entities = {};\n if( xmlData[i + 3] === 'O' &&\n xmlData[i + 4] === 'C' &&\n xmlData[i + 5] === 'T' &&\n xmlData[i + 6] === 'Y' &&\n xmlData[i + 7] === 'P' &&\n xmlData[i + 8] === 'E')\n { \n i = i+9;\n let angleBracketsCount = 1;\n let hasBody = false, comment = false;\n let exp = \"\";\n for(;i<xmlData.length;i++){\n if (xmlData[i] === '<' && !comment) { //Determine the tag type\n if( hasBody && isEntity(xmlData, i)){\n i += 7; \n let entityName, val;\n [entityName, val,i] = readEntityExp(xmlData,i+1);\n if(val.indexOf(\"&\") === -1) //Parameter entities are not supported\n entities[ validateEntityName(entityName) ] = {\n regx : RegExp( `&${entityName};`,\"g\"),\n val: val\n };\n }\n else if( hasBody && isElement(xmlData, i)) i += 8;//Not supported\n else if( hasBody && isAttlist(xmlData, i)) i += 8;//Not supported\n else if( hasBody && isNotation(xmlData, i)) i += 9;//Not supported\n else if( isComment) comment = true;\n else throw new Error(\"Invalid DOCTYPE\");\n\n angleBracketsCount++;\n exp = \"\";\n } else if (xmlData[i] === '>') { //Read tag content\n if(comment){\n if( xmlData[i - 1] === \"-\" && xmlData[i - 2] === \"-\"){\n comment = false;\n angleBracketsCount--;\n }\n }else{\n angleBracketsCount--;\n }\n if (angleBracketsCount === 0) {\n break;\n }\n }else if( xmlData[i] === '['){\n hasBody = true;\n }else{\n exp += xmlData[i];\n }\n }\n if(angleBracketsCount !== 0){\n throw new Error(`Unclosed DOCTYPE`);\n }\n }else{\n throw new Error(`Invalid Tag instead of DOCTYPE`);\n }\n return {entities, i};\n}\n\nfunction readEntityExp(xmlData,i){\n //External entities are not supported\n // <!ENTITY ext SYSTEM \"http://normal-website.com\" >\n\n //Parameter entities are not supported\n // <!ENTITY entityname \"&anotherElement;\">\n\n //Internal entities are supported\n // <!ENTITY entityname \"replacement text\">\n \n //read EntityName\n let entityName = \"\";\n for (; i < xmlData.length && (xmlData[i] !== \"'\" && xmlData[i] !== '\"' ); i++) {\n // if(xmlData[i] === \" \") continue;\n // else \n entityName += xmlData[i];\n }\n entityName = entityName.trim();\n if(entityName.indexOf(\" \") !== -1) throw new Error(\"External entites are not supported\");\n\n //read Entity Value\n const startChar = xmlData[i++];\n let val = \"\"\n for (; i < xmlData.length && xmlData[i] !== startChar ; i++) {\n val += xmlData[i];\n }\n return [entityName, val, i];\n}\n\nfunction isComment(xmlData, i){\n if(xmlData[i+1] === '!' &&\n xmlData[i+2] === '-' &&\n xmlData[i+3] === '-') return true\n return false\n}\nfunction isEntity(xmlData, i){\n if(xmlData[i+1] === '!' &&\n xmlData[i+2] === 'E' &&\n xmlData[i+3] === 'N' &&\n xmlData[i+4] === 'T' &&\n xmlData[i+5] === 'I' &&\n xmlData[i+6] === 'T' &&\n xmlData[i+7] === 'Y') return true\n return false\n}\nfunction isElement(xmlData, i){\n if(xmlData[i+1] === '!' &&\n xmlData[i+2] === 'E' &&\n xmlData[i+3] === 'L' &&\n xmlData[i+4] === 'E' &&\n xmlData[i+5] === 'M' &&\n xmlData[i+6] === 'E' &&\n xmlData[i+7] === 'N' &&\n xmlData[i+8] === 'T') return true\n return false\n}\n\nfunction isAttlist(xmlData, i){\n if(xmlData[i+1] === '!' &&\n xmlData[i+2] === 'A' &&\n xmlData[i+3] === 'T' &&\n xmlData[i+4] === 'T' &&\n xmlData[i+5] === 'L' &&\n xmlData[i+6] === 'I' &&\n xmlData[i+7] === 'S' &&\n xmlData[i+8] === 'T') return true\n return false\n}\nfunction isNotation(xmlData, i){\n if(xmlData[i+1] === '!' &&\n xmlData[i+2] === 'N' &&\n xmlData[i+3] === 'O' &&\n xmlData[i+4] === 'T' &&\n xmlData[i+5] === 'A' &&\n xmlData[i+6] === 'T' &&\n xmlData[i+7] === 'I' &&\n xmlData[i+8] === 'O' &&\n xmlData[i+9] === 'N') return true\n return false\n}\n\nfunction validateEntityName(name){\n if ((0,_util_js__WEBPACK_IMPORTED_MODULE_0__.isName)(name))\n\treturn name;\n else\n throw new Error(`Invalid entity name ${name}`);\n}\n\n\n//# sourceURL=webpack://fast-xml-parser/./src/xmlparser/DocTypeReader.js?");
|
|
80416
78601
|
|
|
80417
78602
|
/***/ }),
|
|
80418
78603
|
|
|
80419
|
-
/***/ "./
|
|
80420
|
-
|
|
80421
|
-
!*** ./
|
|
80422
|
-
|
|
80423
|
-
/***/ ((
|
|
78604
|
+
/***/ "./src/xmlparser/OptionsBuilder.js":
|
|
78605
|
+
/*!*****************************************!*\
|
|
78606
|
+
!*** ./src/xmlparser/OptionsBuilder.js ***!
|
|
78607
|
+
\*****************************************/
|
|
78608
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
80424
78609
|
|
|
80425
|
-
"
|
|
78610
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ buildOptions: () => (/* binding */ buildOptions),\n/* harmony export */ defaultOptions: () => (/* binding */ defaultOptions)\n/* harmony export */ });\n\nconst defaultOptions = {\n preserveOrder: false,\n attributeNamePrefix: '@_',\n attributesGroupName: false,\n textNodeName: '#text',\n ignoreAttributes: true,\n removeNSPrefix: false, // remove NS from tag name or attribute name if true\n allowBooleanAttributes: false, //a tag can have attributes without any value\n //ignoreRootElement : false,\n parseTagValue: true,\n parseAttributeValue: false,\n trimValues: true, //Trim string values of tag and attributes\n cdataPropName: false,\n numberParseOptions: {\n hex: true,\n leadingZeros: true,\n eNotation: true\n },\n tagValueProcessor: function(tagName, val) {\n return val;\n },\n attributeValueProcessor: function(attrName, val) {\n return val;\n },\n stopNodes: [], //nested tags will not be parsed even for errors\n alwaysCreateTextNode: false,\n isArray: () => false,\n commentPropName: false,\n unpairedTags: [],\n processEntities: true,\n htmlEntities: false,\n ignoreDeclaration: false,\n ignorePiTags: false,\n transformTagName: false,\n transformAttributeName: false,\n updateTag: function(tagName, jPath, attrs){\n return tagName\n },\n // skipEmptyListItem: false\n};\n \nconst buildOptions = function(options) {\n return Object.assign({}, defaultOptions, options);\n};\n\n\n//# sourceURL=webpack://fast-xml-parser/./src/xmlparser/OptionsBuilder.js?");
|
|
80426
78611
|
|
|
78612
|
+
/***/ }),
|
|
80427
78613
|
|
|
80428
|
-
|
|
80429
|
-
|
|
80430
|
-
|
|
80431
|
-
|
|
80432
|
-
|
|
80433
|
-
*/
|
|
80434
|
-
function prettify(node, options){
|
|
80435
|
-
return compress( node, options);
|
|
80436
|
-
}
|
|
78614
|
+
/***/ "./src/xmlparser/OrderedObjParser.js":
|
|
78615
|
+
/*!*******************************************!*\
|
|
78616
|
+
!*** ./src/xmlparser/OrderedObjParser.js ***!
|
|
78617
|
+
\*******************************************/
|
|
78618
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
80437
78619
|
|
|
80438
|
-
/**
|
|
80439
|
-
*
|
|
80440
|
-
* @param {array} arr
|
|
80441
|
-
* @param {object} options
|
|
80442
|
-
* @param {string} jPath
|
|
80443
|
-
* @returns object
|
|
80444
|
-
*/
|
|
80445
|
-
function compress(arr, options, jPath){
|
|
80446
|
-
let text;
|
|
80447
|
-
const compressedObj = {};
|
|
80448
|
-
for (let i = 0; i < arr.length; i++) {
|
|
80449
|
-
const tagObj = arr[i];
|
|
80450
|
-
const property = propName(tagObj);
|
|
80451
|
-
let newJpath = "";
|
|
80452
|
-
if(jPath === undefined) newJpath = property;
|
|
80453
|
-
else newJpath = jPath + "." + property;
|
|
80454
|
-
|
|
80455
|
-
if(property === options.textNodeName){
|
|
80456
|
-
if(text === undefined) text = tagObj[property];
|
|
80457
|
-
else text += "" + tagObj[property];
|
|
80458
|
-
}else if(property === undefined){
|
|
80459
|
-
continue;
|
|
80460
|
-
}else if(tagObj[property]){
|
|
80461
|
-
|
|
80462
|
-
let val = compress(tagObj[property], options, newJpath);
|
|
80463
|
-
const isLeaf = isLeafTag(val, options);
|
|
80464
|
-
|
|
80465
|
-
if(tagObj[":@"]){
|
|
80466
|
-
assignAttributes( val, tagObj[":@"], newJpath, options);
|
|
80467
|
-
}else if(Object.keys(val).length === 1 && val[options.textNodeName] !== undefined && !options.alwaysCreateTextNode){
|
|
80468
|
-
val = val[options.textNodeName];
|
|
80469
|
-
}else if(Object.keys(val).length === 0){
|
|
80470
|
-
if(options.alwaysCreateTextNode) val[options.textNodeName] = "";
|
|
80471
|
-
else val = "";
|
|
80472
|
-
}
|
|
78620
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ OrderedObjParser)\n/* harmony export */ });\n/* harmony import */ var _util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../util.js */ \"./src/util.js\");\n/* harmony import */ var _xmlNode_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./xmlNode.js */ \"./src/xmlparser/xmlNode.js\");\n/* harmony import */ var _DocTypeReader_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./DocTypeReader.js */ \"./src/xmlparser/DocTypeReader.js\");\n/* harmony import */ var strnum__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! strnum */ \"./node_modules/strnum/strnum.js\");\n/* harmony import */ var _ignoreAttributes_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../ignoreAttributes.js */ \"./src/ignoreAttributes.js\");\n\n///@ts-check\n\n\n\n\n\n\n\n// const regx =\n// '<((!\\\\[CDATA\\\\[([\\\\s\\\\S]*?)(]]>))|((NAME:)?(NAME))([^>]*)>|((\\\\/)(NAME)\\\\s*>))([^<]*)'\n// .replace(/NAME/g, util.nameRegexp);\n\n//const tagsRegx = new RegExp(\"<(\\\\/?[\\\\w:\\\\-\\._]+)([^>]*)>(\\\\s*\"+cdataRegx+\")*([^<]+)?\",\"g\");\n//const tagsRegx = new RegExp(\"<(\\\\/?)((\\\\w*:)?([\\\\w:\\\\-\\._]+))([^>]*)>([^<]*)(\"+cdataRegx+\"([^<]*))*([^<]+)?\",\"g\");\n\nclass OrderedObjParser{\n constructor(options){\n this.options = options;\n this.currentNode = null;\n this.tagsNodeStack = [];\n this.docTypeEntities = {};\n this.lastEntities = {\n \"apos\" : { regex: /&(apos|#39|#x27);/g, val : \"'\"},\n \"gt\" : { regex: /&(gt|#62|#x3E);/g, val : \">\"},\n \"lt\" : { regex: /&(lt|#60|#x3C);/g, val : \"<\"},\n \"quot\" : { regex: /&(quot|#34|#x22);/g, val : \"\\\"\"},\n };\n this.ampEntity = { regex: /&(amp|#38|#x26);/g, val : \"&\"};\n this.htmlEntities = {\n \"space\": { regex: /&(nbsp|#160);/g, val: \" \" },\n // \"lt\" : { regex: /&(lt|#60);/g, val: \"<\" },\n // \"gt\" : { regex: /&(gt|#62);/g, val: \">\" },\n // \"amp\" : { regex: /&(amp|#38);/g, val: \"&\" },\n // \"quot\" : { regex: /&(quot|#34);/g, val: \"\\\"\" },\n // \"apos\" : { regex: /&(apos|#39);/g, val: \"'\" },\n \"cent\" : { regex: /&(cent|#162);/g, val: \"¢\" },\n \"pound\" : { regex: /&(pound|#163);/g, val: \"£\" },\n \"yen\" : { regex: /&(yen|#165);/g, val: \"¥\" },\n \"euro\" : { regex: /&(euro|#8364);/g, val: \"€\" },\n \"copyright\" : { regex: /&(copy|#169);/g, val: \"©\" },\n \"reg\" : { regex: /&(reg|#174);/g, val: \"®\" },\n \"inr\" : { regex: /&(inr|#8377);/g, val: \"₹\" },\n \"num_dec\": { regex: /&#([0-9]{1,7});/g, val : (_, str) => String.fromCodePoint(Number.parseInt(str, 10)) },\n \"num_hex\": { regex: /&#x([0-9a-fA-F]{1,6});/g, val : (_, str) => String.fromCodePoint(Number.parseInt(str, 16)) },\n };\n this.addExternalEntities = addExternalEntities;\n this.parseXml = parseXml;\n this.parseTextData = parseTextData;\n this.resolveNameSpace = resolveNameSpace;\n this.buildAttributesMap = buildAttributesMap;\n this.isItStopNode = isItStopNode;\n this.replaceEntitiesValue = replaceEntitiesValue;\n this.readStopNodeData = readStopNodeData;\n this.saveTextToParentTag = saveTextToParentTag;\n this.addChild = addChild;\n this.ignoreAttributesFn = (0,_ignoreAttributes_js__WEBPACK_IMPORTED_MODULE_4__[\"default\"])(this.options.ignoreAttributes)\n }\n\n}\n\nfunction addExternalEntities(externalEntities){\n const entKeys = Object.keys(externalEntities);\n for (let i = 0; i < entKeys.length; i++) {\n const ent = entKeys[i];\n this.lastEntities[ent] = {\n regex: new RegExp(\"&\"+ent+\";\",\"g\"),\n val : externalEntities[ent]\n }\n }\n}\n\n/**\n * @param {string} val\n * @param {string} tagName\n * @param {string} jPath\n * @param {boolean} dontTrim\n * @param {boolean} hasAttributes\n * @param {boolean} isLeafNode\n * @param {boolean} escapeEntities\n */\nfunction parseTextData(val, tagName, jPath, dontTrim, hasAttributes, isLeafNode, escapeEntities) {\n if (val !== undefined) {\n if (this.options.trimValues && !dontTrim) {\n val = val.trim();\n }\n if(val.length > 0){\n if(!escapeEntities) val = this.replaceEntitiesValue(val);\n \n const newval = this.options.tagValueProcessor(tagName, val, jPath, hasAttributes, isLeafNode);\n if(newval === null || newval === undefined){\n //don't parse\n return val;\n }else if(typeof newval !== typeof val || newval !== val){\n //overwrite\n return newval;\n }else if(this.options.trimValues){\n return parseValue(val, this.options.parseTagValue, this.options.numberParseOptions);\n }else{\n const trimmedVal = val.trim();\n if(trimmedVal === val){\n return parseValue(val, this.options.parseTagValue, this.options.numberParseOptions);\n }else{\n return val;\n }\n }\n }\n }\n}\n\nfunction resolveNameSpace(tagname) {\n if (this.options.removeNSPrefix) {\n const tags = tagname.split(':');\n const prefix = tagname.charAt(0) === '/' ? '/' : '';\n if (tags[0] === 'xmlns') {\n return '';\n }\n if (tags.length === 2) {\n tagname = prefix + tags[1];\n }\n }\n return tagname;\n}\n\n//TODO: change regex to capture NS\n//const attrsRegx = new RegExp(\"([\\\\w\\\\-\\\\.\\\\:]+)\\\\s*=\\\\s*(['\\\"])((.|\\n)*?)\\\\2\",\"gm\");\nconst attrsRegx = new RegExp('([^\\\\s=]+)\\\\s*(=\\\\s*([\\'\"])([\\\\s\\\\S]*?)\\\\3)?', 'gm');\n\nfunction buildAttributesMap(attrStr, jPath, tagName) {\n if (this.options.ignoreAttributes !== true && typeof attrStr === 'string') {\n // attrStr = attrStr.replace(/\\r?\\n/g, ' ');\n //attrStr = attrStr || attrStr.trim();\n\n const matches = (0,_util_js__WEBPACK_IMPORTED_MODULE_0__.getAllMatches)(attrStr, attrsRegx);\n const len = matches.length; //don't make it inline\n const attrs = {};\n for (let i = 0; i < len; i++) {\n const attrName = this.resolveNameSpace(matches[i][1]);\n if (this.ignoreAttributesFn(attrName, jPath)) {\n continue\n }\n let oldVal = matches[i][4];\n let aName = this.options.attributeNamePrefix + attrName;\n if (attrName.length) {\n if (this.options.transformAttributeName) {\n aName = this.options.transformAttributeName(aName);\n }\n if(aName === \"__proto__\") aName = \"#__proto__\";\n if (oldVal !== undefined) {\n if (this.options.trimValues) {\n oldVal = oldVal.trim();\n }\n oldVal = this.replaceEntitiesValue(oldVal);\n const newVal = this.options.attributeValueProcessor(attrName, oldVal, jPath);\n if(newVal === null || newVal === undefined){\n //don't parse\n attrs[aName] = oldVal;\n }else if(typeof newVal !== typeof oldVal || newVal !== oldVal){\n //overwrite\n attrs[aName] = newVal;\n }else{\n //parse\n attrs[aName] = parseValue(\n oldVal,\n this.options.parseAttributeValue,\n this.options.numberParseOptions\n );\n }\n } else if (this.options.allowBooleanAttributes) {\n attrs[aName] = true;\n }\n }\n }\n if (!Object.keys(attrs).length) {\n return;\n }\n if (this.options.attributesGroupName) {\n const attrCollection = {};\n attrCollection[this.options.attributesGroupName] = attrs;\n return attrCollection;\n }\n return attrs\n }\n}\n\nconst parseXml = function(xmlData) {\n xmlData = xmlData.replace(/\\r\\n?/g, \"\\n\"); //TODO: remove this line\n const xmlObj = new _xmlNode_js__WEBPACK_IMPORTED_MODULE_1__[\"default\"]('!xml');\n let currentNode = xmlObj;\n let textData = \"\";\n let jPath = \"\";\n for(let i=0; i< xmlData.length; i++){//for each char in XML data\n const ch = xmlData[i];\n if(ch === '<'){\n // const nextIndex = i+1;\n // const _2ndChar = xmlData[nextIndex];\n if( xmlData[i+1] === '/') {//Closing Tag\n const closeIndex = findClosingIndex(xmlData, \">\", i, \"Closing Tag is not closed.\")\n let tagName = xmlData.substring(i+2,closeIndex).trim();\n\n if(this.options.removeNSPrefix){\n const colonIndex = tagName.indexOf(\":\");\n if(colonIndex !== -1){\n tagName = tagName.substr(colonIndex+1);\n }\n }\n\n if(this.options.transformTagName) {\n tagName = this.options.transformTagName(tagName);\n }\n\n if(currentNode){\n textData = this.saveTextToParentTag(textData, currentNode, jPath);\n }\n\n //check if last tag of nested tag was unpaired tag\n const lastTagName = jPath.substring(jPath.lastIndexOf(\".\")+1);\n if(tagName && this.options.unpairedTags.indexOf(tagName) !== -1 ){\n throw new Error(`Unpaired tag can not be used as closing tag: </${tagName}>`);\n }\n let propIndex = 0\n if(lastTagName && this.options.unpairedTags.indexOf(lastTagName) !== -1 ){\n propIndex = jPath.lastIndexOf('.', jPath.lastIndexOf('.')-1)\n this.tagsNodeStack.pop();\n }else{\n propIndex = jPath.lastIndexOf(\".\");\n }\n jPath = jPath.substring(0, propIndex);\n\n currentNode = this.tagsNodeStack.pop();//avoid recursion, set the parent tag scope\n textData = \"\";\n i = closeIndex;\n } else if( xmlData[i+1] === '?') {\n\n let tagData = readTagExp(xmlData,i, false, \"?>\");\n if(!tagData) throw new Error(\"Pi Tag is not closed.\");\n\n textData = this.saveTextToParentTag(textData, currentNode, jPath);\n if( (this.options.ignoreDeclaration && tagData.tagName === \"?xml\") || this.options.ignorePiTags){\n\n }else{\n \n const childNode = new _xmlNode_js__WEBPACK_IMPORTED_MODULE_1__[\"default\"](tagData.tagName);\n childNode.add(this.options.textNodeName, \"\");\n \n if(tagData.tagName !== tagData.tagExp && tagData.attrExpPresent){\n childNode[\":@\"] = this.buildAttributesMap(tagData.tagExp, jPath, tagData.tagName);\n }\n this.addChild(currentNode, childNode, jPath)\n\n }\n\n\n i = tagData.closeIndex + 1;\n } else if(xmlData.substr(i + 1, 3) === '!--') {\n const endIndex = findClosingIndex(xmlData, \"-->\", i+4, \"Comment is not closed.\")\n if(this.options.commentPropName){\n const comment = xmlData.substring(i + 4, endIndex - 2);\n\n textData = this.saveTextToParentTag(textData, currentNode, jPath);\n\n currentNode.add(this.options.commentPropName, [ { [this.options.textNodeName] : comment } ]);\n }\n i = endIndex;\n } else if( xmlData.substr(i + 1, 2) === '!D') {\n const result = (0,_DocTypeReader_js__WEBPACK_IMPORTED_MODULE_2__[\"default\"])(xmlData, i);\n this.docTypeEntities = result.entities;\n i = result.i;\n }else if(xmlData.substr(i + 1, 2) === '![') {\n const closeIndex = findClosingIndex(xmlData, \"]]>\", i, \"CDATA is not closed.\") - 2;\n const tagExp = xmlData.substring(i + 9,closeIndex);\n\n textData = this.saveTextToParentTag(textData, currentNode, jPath);\n\n let val = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true, true);\n if(val == undefined) val = \"\";\n\n //cdata should be set even if it is 0 length string\n if(this.options.cdataPropName){\n currentNode.add(this.options.cdataPropName, [ { [this.options.textNodeName] : tagExp } ]);\n }else{\n currentNode.add(this.options.textNodeName, val);\n }\n \n i = closeIndex + 2;\n }else {//Opening tag\n let result = readTagExp(xmlData,i, this.options.removeNSPrefix);\n let tagName= result.tagName;\n const rawTagName = result.rawTagName;\n let tagExp = result.tagExp;\n let attrExpPresent = result.attrExpPresent;\n let closeIndex = result.closeIndex;\n\n if (this.options.transformTagName) {\n tagName = this.options.transformTagName(tagName);\n }\n \n //save text as child node\n if (currentNode && textData) {\n if(currentNode.tagname !== '!xml'){\n //when nested tag is found\n textData = this.saveTextToParentTag(textData, currentNode, jPath, false);\n }\n }\n\n //check if last tag was unpaired tag\n const lastTag = currentNode;\n if(lastTag && this.options.unpairedTags.indexOf(lastTag.tagname) !== -1 ){\n currentNode = this.tagsNodeStack.pop();\n jPath = jPath.substring(0, jPath.lastIndexOf(\".\"));\n }\n if(tagName !== xmlObj.tagname){\n jPath += jPath ? \".\" + tagName : tagName;\n }\n if (this.isItStopNode(this.options.stopNodes, jPath, tagName)) {\n let tagContent = \"\";\n //self-closing tag\n if(tagExp.length > 0 && tagExp.lastIndexOf(\"/\") === tagExp.length - 1){\n if(tagName[tagName.length - 1] === \"/\"){ //remove trailing '/'\n tagName = tagName.substr(0, tagName.length - 1);\n jPath = jPath.substr(0, jPath.length - 1);\n tagExp = tagName;\n }else{\n tagExp = tagExp.substr(0, tagExp.length - 1);\n }\n i = result.closeIndex;\n }\n //unpaired tag\n else if(this.options.unpairedTags.indexOf(tagName) !== -1){\n \n i = result.closeIndex;\n }\n //normal tag\n else{\n //read until closing tag is found\n const result = this.readStopNodeData(xmlData, rawTagName, closeIndex + 1);\n if(!result) throw new Error(`Unexpected end of ${rawTagName}`);\n i = result.i;\n tagContent = result.tagContent;\n }\n\n const childNode = new _xmlNode_js__WEBPACK_IMPORTED_MODULE_1__[\"default\"](tagName);\n if(tagName !== tagExp && attrExpPresent){\n childNode[\":@\"] = this.buildAttributesMap(tagExp, jPath, tagName);\n }\n if(tagContent) {\n tagContent = this.parseTextData(tagContent, tagName, jPath, true, attrExpPresent, true, true);\n }\n \n jPath = jPath.substr(0, jPath.lastIndexOf(\".\"));\n childNode.add(this.options.textNodeName, tagContent);\n \n this.addChild(currentNode, childNode, jPath)\n }else{\n //selfClosing tag\n if(tagExp.length > 0 && tagExp.lastIndexOf(\"/\") === tagExp.length - 1){\n if(tagName[tagName.length - 1] === \"/\"){ //remove trailing '/'\n tagName = tagName.substr(0, tagName.length - 1);\n jPath = jPath.substr(0, jPath.length - 1);\n tagExp = tagName;\n }else{\n tagExp = tagExp.substr(0, tagExp.length - 1);\n }\n \n if(this.options.transformTagName) {\n tagName = this.options.transformTagName(tagName);\n }\n\n const childNode = new _xmlNode_js__WEBPACK_IMPORTED_MODULE_1__[\"default\"](tagName);\n if(tagName !== tagExp && attrExpPresent){\n childNode[\":@\"] = this.buildAttributesMap(tagExp, jPath, tagName);\n }\n this.addChild(currentNode, childNode, jPath)\n jPath = jPath.substr(0, jPath.lastIndexOf(\".\"));\n }\n //opening tag\n else{\n const childNode = new _xmlNode_js__WEBPACK_IMPORTED_MODULE_1__[\"default\"]( tagName);\n this.tagsNodeStack.push(currentNode);\n \n if(tagName !== tagExp && attrExpPresent){\n childNode[\":@\"] = this.buildAttributesMap(tagExp, jPath, tagName);\n }\n this.addChild(currentNode, childNode, jPath)\n currentNode = childNode;\n }\n textData = \"\";\n i = closeIndex;\n }\n }\n }else{\n textData += xmlData[i];\n }\n }\n return xmlObj.child;\n}\n\nfunction addChild(currentNode, childNode, jPath){\n const result = this.options.updateTag(childNode.tagname, jPath, childNode[\":@\"])\n if(result === false){\n }else if(typeof result === \"string\"){\n childNode.tagname = result\n currentNode.addChild(childNode);\n }else{\n currentNode.addChild(childNode);\n }\n}\n\nconst replaceEntitiesValue = function(val){\n\n if(this.options.processEntities){\n for(let entityName in this.docTypeEntities){\n const entity = this.docTypeEntities[entityName];\n val = val.replace( entity.regx, entity.val);\n }\n for(let entityName in this.lastEntities){\n const entity = this.lastEntities[entityName];\n val = val.replace( entity.regex, entity.val);\n }\n if(this.options.htmlEntities){\n for(let entityName in this.htmlEntities){\n const entity = this.htmlEntities[entityName];\n val = val.replace( entity.regex, entity.val);\n }\n }\n val = val.replace( this.ampEntity.regex, this.ampEntity.val);\n }\n return val;\n}\nfunction saveTextToParentTag(textData, currentNode, jPath, isLeafNode) {\n if (textData) { //store previously collected data as textNode\n if(isLeafNode === undefined) isLeafNode = currentNode.child.length === 0\n \n textData = this.parseTextData(textData,\n currentNode.tagname,\n jPath,\n false,\n currentNode[\":@\"] ? Object.keys(currentNode[\":@\"]).length !== 0 : false,\n isLeafNode);\n\n if (textData !== undefined && textData !== \"\")\n currentNode.add(this.options.textNodeName, textData);\n textData = \"\";\n }\n return textData;\n}\n\n//TODO: use jPath to simplify the logic\n/**\n * \n * @param {string[]} stopNodes \n * @param {string} jPath\n * @param {string} currentTagName \n */\nfunction isItStopNode(stopNodes, jPath, currentTagName){\n const allNodesExp = \"*.\" + currentTagName;\n for (const stopNodePath in stopNodes) {\n const stopNodeExp = stopNodes[stopNodePath];\n if( allNodesExp === stopNodeExp || jPath === stopNodeExp ) return true;\n }\n return false;\n}\n\n/**\n * Returns the tag Expression and where it is ending handling single-double quotes situation\n * @param {string} xmlData \n * @param {number} i starting index\n * @returns \n */\nfunction tagExpWithClosingIndex(xmlData, i, closingChar = \">\"){\n let attrBoundary;\n let tagExp = \"\";\n for (let index = i; index < xmlData.length; index++) {\n let ch = xmlData[index];\n if (attrBoundary) {\n if (ch === attrBoundary) attrBoundary = \"\";//reset\n } else if (ch === '\"' || ch === \"'\") {\n attrBoundary = ch;\n } else if (ch === closingChar[0]) {\n if(closingChar[1]){\n if(xmlData[index + 1] === closingChar[1]){\n return {\n data: tagExp,\n index: index\n }\n }\n }else{\n return {\n data: tagExp,\n index: index\n }\n }\n } else if (ch === '\\t') {\n ch = \" \"\n }\n tagExp += ch;\n }\n}\n\nfunction findClosingIndex(xmlData, str, i, errMsg){\n const closingIndex = xmlData.indexOf(str, i);\n if(closingIndex === -1){\n throw new Error(errMsg)\n }else{\n return closingIndex + str.length - 1;\n }\n}\n\nfunction readTagExp(xmlData,i, removeNSPrefix, closingChar = \">\"){\n const result = tagExpWithClosingIndex(xmlData, i+1, closingChar);\n if(!result) return;\n let tagExp = result.data;\n const closeIndex = result.index;\n const separatorIndex = tagExp.search(/\\s/);\n let tagName = tagExp;\n let attrExpPresent = true;\n if(separatorIndex !== -1){//separate tag name and attributes expression\n tagName = tagExp.substring(0, separatorIndex);\n tagExp = tagExp.substring(separatorIndex + 1).trimStart();\n }\n\n const rawTagName = tagName;\n if(removeNSPrefix){\n const colonIndex = tagName.indexOf(\":\");\n if(colonIndex !== -1){\n tagName = tagName.substr(colonIndex+1);\n attrExpPresent = tagName !== result.data.substr(colonIndex + 1);\n }\n }\n\n return {\n tagName: tagName,\n tagExp: tagExp,\n closeIndex: closeIndex,\n attrExpPresent: attrExpPresent,\n rawTagName: rawTagName,\n }\n}\n/**\n * find paired tag for a stop node\n * @param {string} xmlData \n * @param {string} tagName \n * @param {number} i \n */\nfunction readStopNodeData(xmlData, tagName, i){\n const startIndex = i;\n // Starting at 1 since we already have an open tag\n let openTagCount = 1;\n\n for (; i < xmlData.length; i++) {\n if( xmlData[i] === \"<\"){ \n if (xmlData[i+1] === \"/\") {//close tag\n const closeIndex = findClosingIndex(xmlData, \">\", i, `${tagName} is not closed`);\n let closeTagName = xmlData.substring(i+2,closeIndex).trim();\n if(closeTagName === tagName){\n openTagCount--;\n if (openTagCount === 0) {\n return {\n tagContent: xmlData.substring(startIndex, i),\n i : closeIndex\n }\n }\n }\n i=closeIndex;\n } else if(xmlData[i+1] === '?') { \n const closeIndex = findClosingIndex(xmlData, \"?>\", i+1, \"StopNode is not closed.\")\n i=closeIndex;\n } else if(xmlData.substr(i + 1, 3) === '!--') { \n const closeIndex = findClosingIndex(xmlData, \"-->\", i+3, \"StopNode is not closed.\")\n i=closeIndex;\n } else if(xmlData.substr(i + 1, 2) === '![') { \n const closeIndex = findClosingIndex(xmlData, \"]]>\", i, \"StopNode is not closed.\") - 2;\n i=closeIndex;\n } else {\n const tagData = readTagExp(xmlData, i, '>')\n\n if (tagData) {\n const openTagName = tagData && tagData.tagName;\n if (openTagName === tagName && tagData.tagExp[tagData.tagExp.length-1] !== \"/\") {\n openTagCount++;\n }\n i=tagData.closeIndex;\n }\n }\n }\n }//end for loop\n}\n\nfunction parseValue(val, shouldParse, options) {\n if (shouldParse && typeof val === 'string') {\n //console.log(options)\n const newval = val.trim();\n if(newval === 'true' ) return true;\n else if(newval === 'false' ) return false;\n else return (0,strnum__WEBPACK_IMPORTED_MODULE_3__[\"default\"])(val, options);\n } else {\n if ((0,_util_js__WEBPACK_IMPORTED_MODULE_0__.isExist)(val)) {\n return val;\n } else {\n return '';\n }\n }\n}\n\n\n//# sourceURL=webpack://fast-xml-parser/./src/xmlparser/OrderedObjParser.js?");
|
|
80473
78621
|
|
|
80474
|
-
|
|
80475
|
-
if(!Array.isArray(compressedObj[property])) {
|
|
80476
|
-
compressedObj[property] = [ compressedObj[property] ];
|
|
80477
|
-
}
|
|
80478
|
-
compressedObj[property].push(val);
|
|
80479
|
-
}else{
|
|
80480
|
-
//TODO: if a node is not an array, then check if it should be an array
|
|
80481
|
-
//also determine if it is a leaf node
|
|
80482
|
-
if (options.isArray(property, newJpath, isLeaf )) {
|
|
80483
|
-
compressedObj[property] = [val];
|
|
80484
|
-
}else{
|
|
80485
|
-
compressedObj[property] = val;
|
|
80486
|
-
}
|
|
80487
|
-
}
|
|
80488
|
-
}
|
|
80489
|
-
|
|
80490
|
-
}
|
|
80491
|
-
// if(text && text.length > 0) compressedObj[options.textNodeName] = text;
|
|
80492
|
-
if(typeof text === "string"){
|
|
80493
|
-
if(text.length > 0) compressedObj[options.textNodeName] = text;
|
|
80494
|
-
}else if(text !== undefined) compressedObj[options.textNodeName] = text;
|
|
80495
|
-
return compressedObj;
|
|
80496
|
-
}
|
|
80497
|
-
|
|
80498
|
-
function propName(obj){
|
|
80499
|
-
const keys = Object.keys(obj);
|
|
80500
|
-
for (let i = 0; i < keys.length; i++) {
|
|
80501
|
-
const key = keys[i];
|
|
80502
|
-
if(key !== ":@") return key;
|
|
80503
|
-
}
|
|
80504
|
-
}
|
|
78622
|
+
/***/ }),
|
|
80505
78623
|
|
|
80506
|
-
|
|
80507
|
-
|
|
80508
|
-
|
|
80509
|
-
|
|
80510
|
-
|
|
80511
|
-
const atrrName = keys[i];
|
|
80512
|
-
if (options.isArray(atrrName, jpath + "." + atrrName, true, true)) {
|
|
80513
|
-
obj[atrrName] = [ attrMap[atrrName] ];
|
|
80514
|
-
} else {
|
|
80515
|
-
obj[atrrName] = attrMap[atrrName];
|
|
80516
|
-
}
|
|
80517
|
-
}
|
|
80518
|
-
}
|
|
80519
|
-
}
|
|
78624
|
+
/***/ "./src/xmlparser/XMLParser.js":
|
|
78625
|
+
/*!************************************!*\
|
|
78626
|
+
!*** ./src/xmlparser/XMLParser.js ***!
|
|
78627
|
+
\************************************/
|
|
78628
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
80520
78629
|
|
|
80521
|
-
|
|
80522
|
-
const { textNodeName } = options;
|
|
80523
|
-
const propCount = Object.keys(obj).length;
|
|
80524
|
-
|
|
80525
|
-
if (propCount === 0) {
|
|
80526
|
-
return true;
|
|
80527
|
-
}
|
|
78630
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ XMLParser)\n/* harmony export */ });\n/* harmony import */ var _OptionsBuilder_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./OptionsBuilder.js */ \"./src/xmlparser/OptionsBuilder.js\");\n/* harmony import */ var _OrderedObjParser_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./OrderedObjParser.js */ \"./src/xmlparser/OrderedObjParser.js\");\n/* harmony import */ var _node2json_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./node2json.js */ \"./src/xmlparser/node2json.js\");\n/* harmony import */ var _validator_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../validator.js */ \"./src/validator.js\");\n\n\n\n\n\nclass XMLParser{\n \n constructor(options){\n this.externalEntities = {};\n this.options = (0,_OptionsBuilder_js__WEBPACK_IMPORTED_MODULE_0__.buildOptions)(options);\n \n }\n /**\n * Parse XML dats to JS object \n * @param {string|Buffer} xmlData \n * @param {boolean|Object} validationOption \n */\n parse(xmlData,validationOption){\n if(typeof xmlData === \"string\"){\n }else if( xmlData.toString){\n xmlData = xmlData.toString();\n }else{\n throw new Error(\"XML data is accepted in String or Bytes[] form.\")\n }\n if( validationOption){\n if(validationOption === true) validationOption = {}; //validate with default options\n \n const result = (0,_validator_js__WEBPACK_IMPORTED_MODULE_3__.validate)(xmlData, validationOption);\n if (result !== true) {\n throw Error( `${result.err.msg}:${result.err.line}:${result.err.col}` )\n }\n }\n const orderedObjParser = new _OrderedObjParser_js__WEBPACK_IMPORTED_MODULE_1__[\"default\"](this.options);\n orderedObjParser.addExternalEntities(this.externalEntities);\n const orderedResult = orderedObjParser.parseXml(xmlData);\n if(this.options.preserveOrder || orderedResult === undefined) return orderedResult;\n else return (0,_node2json_js__WEBPACK_IMPORTED_MODULE_2__[\"default\"])(orderedResult, this.options);\n }\n\n /**\n * Add Entity which is not by default supported by this library\n * @param {string} key \n * @param {string} value \n */\n addEntity(key, value){\n if(value.indexOf(\"&\") !== -1){\n throw new Error(\"Entity value can't have '&'\")\n }else if(key.indexOf(\"&\") !== -1 || key.indexOf(\";\") !== -1){\n throw new Error(\"An entity must be set without '&' and ';'. Eg. use '#xD' for '
'\")\n }else if(value === \"&\"){\n throw new Error(\"An entity with value '&' is not permitted\");\n }else{\n this.externalEntities[key] = value;\n }\n }\n}\n\n//# sourceURL=webpack://fast-xml-parser/./src/xmlparser/XMLParser.js?");
|
|
80528
78631
|
|
|
80529
|
-
|
|
80530
|
-
propCount === 1 &&
|
|
80531
|
-
(obj[textNodeName] || typeof obj[textNodeName] === "boolean" || obj[textNodeName] === 0)
|
|
80532
|
-
) {
|
|
80533
|
-
return true;
|
|
80534
|
-
}
|
|
78632
|
+
/***/ }),
|
|
80535
78633
|
|
|
80536
|
-
|
|
80537
|
-
|
|
80538
|
-
|
|
78634
|
+
/***/ "./src/xmlparser/node2json.js":
|
|
78635
|
+
/*!************************************!*\
|
|
78636
|
+
!*** ./src/xmlparser/node2json.js ***!
|
|
78637
|
+
\************************************/
|
|
78638
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
80539
78639
|
|
|
78640
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ prettify)\n/* harmony export */ });\n\n\n/**\n * \n * @param {array} node \n * @param {any} options \n * @returns \n */\nfunction prettify(node, options){\n return compress( node, options);\n}\n\n/**\n * \n * @param {array} arr \n * @param {object} options \n * @param {string} jPath \n * @returns object\n */\nfunction compress(arr, options, jPath){\n let text;\n const compressedObj = {};\n for (let i = 0; i < arr.length; i++) {\n const tagObj = arr[i];\n const property = propName(tagObj);\n let newJpath = \"\";\n if(jPath === undefined) newJpath = property;\n else newJpath = jPath + \".\" + property;\n\n if(property === options.textNodeName){\n if(text === undefined) text = tagObj[property];\n else text += \"\" + tagObj[property];\n }else if(property === undefined){\n continue;\n }else if(tagObj[property]){\n \n let val = compress(tagObj[property], options, newJpath);\n const isLeaf = isLeafTag(val, options);\n\n if(tagObj[\":@\"]){\n assignAttributes( val, tagObj[\":@\"], newJpath, options);\n }else if(Object.keys(val).length === 1 && val[options.textNodeName] !== undefined && !options.alwaysCreateTextNode){\n val = val[options.textNodeName];\n }else if(Object.keys(val).length === 0){\n if(options.alwaysCreateTextNode) val[options.textNodeName] = \"\";\n else val = \"\";\n }\n\n if(compressedObj[property] !== undefined && compressedObj.hasOwnProperty(property)) {\n if(!Array.isArray(compressedObj[property])) {\n compressedObj[property] = [ compressedObj[property] ];\n }\n compressedObj[property].push(val);\n }else{\n //TODO: if a node is not an array, then check if it should be an array\n //also determine if it is a leaf node\n if (options.isArray(property, newJpath, isLeaf )) {\n compressedObj[property] = [val];\n }else{\n compressedObj[property] = val;\n }\n }\n }\n \n }\n // if(text && text.length > 0) compressedObj[options.textNodeName] = text;\n if(typeof text === \"string\"){\n if(text.length > 0) compressedObj[options.textNodeName] = text;\n }else if(text !== undefined) compressedObj[options.textNodeName] = text;\n return compressedObj;\n}\n\nfunction propName(obj){\n const keys = Object.keys(obj);\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n if(key !== \":@\") return key;\n }\n}\n\nfunction assignAttributes(obj, attrMap, jpath, options){\n if (attrMap) {\n const keys = Object.keys(attrMap);\n const len = keys.length; //don't make it inline\n for (let i = 0; i < len; i++) {\n const atrrName = keys[i];\n if (options.isArray(atrrName, jpath + \".\" + atrrName, true, true)) {\n obj[atrrName] = [ attrMap[atrrName] ];\n } else {\n obj[atrrName] = attrMap[atrrName];\n }\n }\n }\n}\n\nfunction isLeafTag(obj, options){\n const { textNodeName } = options;\n const propCount = Object.keys(obj).length;\n \n if (propCount === 0) {\n return true;\n }\n\n if (\n propCount === 1 &&\n (obj[textNodeName] || typeof obj[textNodeName] === \"boolean\" || obj[textNodeName] === 0)\n ) {\n return true;\n }\n\n return false;\n}\n\n\n//# sourceURL=webpack://fast-xml-parser/./src/xmlparser/node2json.js?");
|
|
80540
78641
|
|
|
80541
78642
|
/***/ }),
|
|
80542
78643
|
|
|
80543
|
-
/***/ "./
|
|
80544
|
-
|
|
80545
|
-
!*** ./
|
|
80546
|
-
|
|
80547
|
-
/***/ ((
|
|
80548
|
-
|
|
80549
|
-
"use strict";
|
|
80550
|
-
|
|
78644
|
+
/***/ "./src/xmlparser/xmlNode.js":
|
|
78645
|
+
/*!**********************************!*\
|
|
78646
|
+
!*** ./src/xmlparser/xmlNode.js ***!
|
|
78647
|
+
\**********************************/
|
|
78648
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
80551
78649
|
|
|
80552
|
-
|
|
80553
|
-
constructor(tagname) {
|
|
80554
|
-
this.tagname = tagname;
|
|
80555
|
-
this.child = []; //nested tags, text, cdata, comments in order
|
|
80556
|
-
this[":@"] = {}; //attributes map
|
|
80557
|
-
}
|
|
80558
|
-
add(key,val){
|
|
80559
|
-
// this.child.push( {name : key, val: val, isCdata: isCdata });
|
|
80560
|
-
if(key === "__proto__") key = "#__proto__";
|
|
80561
|
-
this.child.push( {[key]: val });
|
|
80562
|
-
}
|
|
80563
|
-
addChild(node) {
|
|
80564
|
-
if(node.tagname === "__proto__") node.tagname = "#__proto__";
|
|
80565
|
-
if(node[":@"] && Object.keys(node[":@"]).length > 0){
|
|
80566
|
-
this.child.push( { [node.tagname]: node.child, [":@"]: node[":@"] });
|
|
80567
|
-
}else{
|
|
80568
|
-
this.child.push( { [node.tagname]: node.child });
|
|
80569
|
-
}
|
|
80570
|
-
};
|
|
80571
|
-
};
|
|
78650
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ XmlNode)\n/* harmony export */ });\n\n\nclass XmlNode{\n constructor(tagname) {\n this.tagname = tagname;\n this.child = []; //nested tags, text, cdata, comments in order\n this[\":@\"] = {}; //attributes map\n }\n add(key,val){\n // this.child.push( {name : key, val: val, isCdata: isCdata });\n if(key === \"__proto__\") key = \"#__proto__\";\n this.child.push( {[key]: val });\n }\n addChild(node) {\n if(node.tagname === \"__proto__\") node.tagname = \"#__proto__\";\n if(node[\":@\"] && Object.keys(node[\":@\"]).length > 0){\n this.child.push( { [node.tagname]: node.child, [\":@\"]: node[\":@\"] });\n }else{\n this.child.push( { [node.tagname]: node.child });\n }\n }\n}\n\n\n//# sourceURL=webpack://fast-xml-parser/./src/xmlparser/xmlNode.js?");
|
|
80572
78651
|
|
|
78652
|
+
/***/ })
|
|
80573
78653
|
|
|
80574
|
-
|
|
78654
|
+
/******/ });
|
|
78655
|
+
/************************************************************************/
|
|
78656
|
+
/******/ // The module cache
|
|
78657
|
+
/******/ var __webpack_module_cache__ = {};
|
|
78658
|
+
/******/
|
|
78659
|
+
/******/ // The require function
|
|
78660
|
+
/******/ function __nested_webpack_require_83014__(moduleId) {
|
|
78661
|
+
/******/ // Check if module is in cache
|
|
78662
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
78663
|
+
/******/ if (cachedModule !== undefined) {
|
|
78664
|
+
/******/ return cachedModule.exports;
|
|
78665
|
+
/******/ }
|
|
78666
|
+
/******/ // Create a new module (and put it into the cache)
|
|
78667
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
78668
|
+
/******/ // no module.id needed
|
|
78669
|
+
/******/ // no module.loaded needed
|
|
78670
|
+
/******/ exports: {}
|
|
78671
|
+
/******/ };
|
|
78672
|
+
/******/
|
|
78673
|
+
/******/ // Execute the module function
|
|
78674
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __nested_webpack_require_83014__);
|
|
78675
|
+
/******/
|
|
78676
|
+
/******/ // Return the exports of the module
|
|
78677
|
+
/******/ return module.exports;
|
|
78678
|
+
/******/ }
|
|
78679
|
+
/******/
|
|
78680
|
+
/************************************************************************/
|
|
78681
|
+
/******/ /* webpack/runtime/define property getters */
|
|
78682
|
+
/******/ (() => {
|
|
78683
|
+
/******/ // define getter functions for harmony exports
|
|
78684
|
+
/******/ __nested_webpack_require_83014__.d = (exports, definition) => {
|
|
78685
|
+
/******/ for(var key in definition) {
|
|
78686
|
+
/******/ if(__nested_webpack_require_83014__.o(definition, key) && !__nested_webpack_require_83014__.o(exports, key)) {
|
|
78687
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
78688
|
+
/******/ }
|
|
78689
|
+
/******/ }
|
|
78690
|
+
/******/ };
|
|
78691
|
+
/******/ })();
|
|
78692
|
+
/******/
|
|
78693
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
78694
|
+
/******/ (() => {
|
|
78695
|
+
/******/ __nested_webpack_require_83014__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
78696
|
+
/******/ })();
|
|
78697
|
+
/******/
|
|
78698
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
78699
|
+
/******/ (() => {
|
|
78700
|
+
/******/ // define __esModule on exports
|
|
78701
|
+
/******/ __nested_webpack_require_83014__.r = (exports) => {
|
|
78702
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
78703
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
78704
|
+
/******/ }
|
|
78705
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
78706
|
+
/******/ };
|
|
78707
|
+
/******/ })();
|
|
78708
|
+
/******/
|
|
78709
|
+
/************************************************************************/
|
|
78710
|
+
/******/
|
|
78711
|
+
/******/ // startup
|
|
78712
|
+
/******/ // Load entry module and return exports
|
|
78713
|
+
/******/ // This entry module can't be inlined because the eval devtool is used.
|
|
78714
|
+
/******/ var __nested_webpack_exports__ = __nested_webpack_require_83014__("./src/fxp.js");
|
|
78715
|
+
/******/ module.exports = __nested_webpack_exports__;
|
|
78716
|
+
/******/
|
|
78717
|
+
/******/ })()
|
|
78718
|
+
;
|
|
80575
78719
|
|
|
80576
78720
|
/***/ }),
|
|
80577
78721
|
|
|
@@ -87213,126 +85357,6 @@ ProgressBar.prototype.terminate = function () {
|
|
|
87213
85357
|
})( false ? 0 : exports)
|
|
87214
85358
|
|
|
87215
85359
|
|
|
87216
|
-
/***/ }),
|
|
87217
|
-
|
|
87218
|
-
/***/ "./node_modules/strnum/strnum.js":
|
|
87219
|
-
/*!***************************************!*\
|
|
87220
|
-
!*** ./node_modules/strnum/strnum.js ***!
|
|
87221
|
-
\***************************************/
|
|
87222
|
-
/***/ ((module) => {
|
|
87223
|
-
|
|
87224
|
-
const hexRegex = /^[-+]?0x[a-fA-F0-9]+$/;
|
|
87225
|
-
const numRegex = /^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/;
|
|
87226
|
-
// const octRegex = /^0x[a-z0-9]+/;
|
|
87227
|
-
// const binRegex = /0x[a-z0-9]+/;
|
|
87228
|
-
|
|
87229
|
-
|
|
87230
|
-
const consider = {
|
|
87231
|
-
hex : true,
|
|
87232
|
-
// oct: false,
|
|
87233
|
-
leadingZeros: true,
|
|
87234
|
-
decimalPoint: "\.",
|
|
87235
|
-
eNotation: true,
|
|
87236
|
-
//skipLike: /regex/
|
|
87237
|
-
};
|
|
87238
|
-
|
|
87239
|
-
function toNumber(str, options = {}){
|
|
87240
|
-
options = Object.assign({}, consider, options );
|
|
87241
|
-
if(!str || typeof str !== "string" ) return str;
|
|
87242
|
-
|
|
87243
|
-
let trimmedStr = str.trim();
|
|
87244
|
-
|
|
87245
|
-
if(options.skipLike !== undefined && options.skipLike.test(trimmedStr)) return str;
|
|
87246
|
-
else if(str==="0") return 0;
|
|
87247
|
-
else if (options.hex && hexRegex.test(trimmedStr)) {
|
|
87248
|
-
return parse_int(trimmedStr, 16);
|
|
87249
|
-
// }else if (options.oct && octRegex.test(str)) {
|
|
87250
|
-
// return Number.parseInt(val, 8);
|
|
87251
|
-
}else if (trimmedStr.search(/[eE]/)!== -1) { //eNotation
|
|
87252
|
-
const notation = trimmedStr.match(/^([-\+])?(0*)([0-9]*(\.[0-9]*)?[eE][-\+]?[0-9]+)$/);
|
|
87253
|
-
// +00.123 => [ , '+', '00', '.123', ..
|
|
87254
|
-
if(notation){
|
|
87255
|
-
// console.log(notation)
|
|
87256
|
-
if(options.leadingZeros){ //accept with leading zeros
|
|
87257
|
-
trimmedStr = (notation[1] || "") + notation[3];
|
|
87258
|
-
}else{
|
|
87259
|
-
if(notation[2] === "0" && notation[3][0]=== "."){ //valid number
|
|
87260
|
-
}else{
|
|
87261
|
-
return str;
|
|
87262
|
-
}
|
|
87263
|
-
}
|
|
87264
|
-
return options.eNotation ? Number(trimmedStr) : str;
|
|
87265
|
-
}else{
|
|
87266
|
-
return str;
|
|
87267
|
-
}
|
|
87268
|
-
// }else if (options.parseBin && binRegex.test(str)) {
|
|
87269
|
-
// return Number.parseInt(val, 2);
|
|
87270
|
-
}else{
|
|
87271
|
-
//separate negative sign, leading zeros, and rest number
|
|
87272
|
-
const match = numRegex.exec(trimmedStr);
|
|
87273
|
-
// +00.123 => [ , '+', '00', '.123', ..
|
|
87274
|
-
if(match){
|
|
87275
|
-
const sign = match[1];
|
|
87276
|
-
const leadingZeros = match[2];
|
|
87277
|
-
let numTrimmedByZeros = trimZeros(match[3]); //complete num without leading zeros
|
|
87278
|
-
//trim ending zeros for floating number
|
|
87279
|
-
|
|
87280
|
-
if(!options.leadingZeros && leadingZeros.length > 0 && sign && trimmedStr[2] !== ".") return str; //-0123
|
|
87281
|
-
else if(!options.leadingZeros && leadingZeros.length > 0 && !sign && trimmedStr[1] !== ".") return str; //0123
|
|
87282
|
-
else if(options.leadingZeros && leadingZeros===str) return 0; //00
|
|
87283
|
-
|
|
87284
|
-
else{//no leading zeros or leading zeros are allowed
|
|
87285
|
-
const num = Number(trimmedStr);
|
|
87286
|
-
const numStr = "" + num;
|
|
87287
|
-
|
|
87288
|
-
if(numStr.search(/[eE]/) !== -1){ //given number is long and parsed to eNotation
|
|
87289
|
-
if(options.eNotation) return num;
|
|
87290
|
-
else return str;
|
|
87291
|
-
}else if(trimmedStr.indexOf(".") !== -1){ //floating number
|
|
87292
|
-
if(numStr === "0" && (numTrimmedByZeros === "") ) return num; //0.0
|
|
87293
|
-
else if(numStr === numTrimmedByZeros) return num; //0.456. 0.79000
|
|
87294
|
-
else if( sign && numStr === "-"+numTrimmedByZeros) return num;
|
|
87295
|
-
else return str;
|
|
87296
|
-
}
|
|
87297
|
-
|
|
87298
|
-
if(leadingZeros){
|
|
87299
|
-
return (numTrimmedByZeros === numStr) || (sign+numTrimmedByZeros === numStr) ? num : str
|
|
87300
|
-
}else {
|
|
87301
|
-
return (trimmedStr === numStr) || (trimmedStr === sign+numStr) ? num : str
|
|
87302
|
-
}
|
|
87303
|
-
}
|
|
87304
|
-
}else{ //non-numeric string
|
|
87305
|
-
return str;
|
|
87306
|
-
}
|
|
87307
|
-
}
|
|
87308
|
-
}
|
|
87309
|
-
|
|
87310
|
-
/**
|
|
87311
|
-
*
|
|
87312
|
-
* @param {string} numStr without leading zeros
|
|
87313
|
-
* @returns
|
|
87314
|
-
*/
|
|
87315
|
-
function trimZeros(numStr){
|
|
87316
|
-
if(numStr && numStr.indexOf(".") !== -1){//float
|
|
87317
|
-
numStr = numStr.replace(/0+$/, ""); //remove ending zeros
|
|
87318
|
-
if(numStr === ".") numStr = "0";
|
|
87319
|
-
else if(numStr[0] === ".") numStr = "0"+numStr;
|
|
87320
|
-
else if(numStr[numStr.length-1] === ".") numStr = numStr.substr(0,numStr.length-1);
|
|
87321
|
-
return numStr;
|
|
87322
|
-
}
|
|
87323
|
-
return numStr;
|
|
87324
|
-
}
|
|
87325
|
-
|
|
87326
|
-
function parse_int(numStr, base){
|
|
87327
|
-
//polyfill
|
|
87328
|
-
if(parseInt) return parseInt(numStr, base);
|
|
87329
|
-
else if(Number.parseInt) return Number.parseInt(numStr, base);
|
|
87330
|
-
else if(window && window.parseInt) return window.parseInt(numStr, base);
|
|
87331
|
-
else throw new Error("parseInt, Number.parseInt, window.parseInt are not supported")
|
|
87332
|
-
}
|
|
87333
|
-
|
|
87334
|
-
module.exports = toNumber;
|
|
87335
|
-
|
|
87336
85360
|
/***/ }),
|
|
87337
85361
|
|
|
87338
85362
|
/***/ "./node_modules/vscode-languageserver-types/lib/umd sync recursive":
|