@nextcloud/files 3.10.0 → 3.10.2
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/dist/chunks/{dav-DxfiR0wZ.mjs → dav-Co9y-hkg.mjs} +15 -9
- package/dist/chunks/dav-Co9y-hkg.mjs.map +1 -0
- package/dist/chunks/{dav-BBwoJ8WE.cjs → dav-CtqjqS4O.cjs} +15 -9
- package/dist/chunks/dav-CtqjqS4O.cjs.map +1 -0
- package/dist/dav/dav.d.ts +55 -0
- package/dist/dav/davPermissions.d.ts +6 -0
- package/dist/dav/davProperties.d.ts +57 -0
- package/dist/dav/index.d.ts +13 -0
- package/dist/dav.cjs +1 -1
- package/dist/dav.mjs +1 -1
- package/dist/fileAction.d.ts +83 -0
- package/dist/fileListAction.d.ts +41 -0
- package/dist/fileListFilters.d.ts +100 -0
- package/dist/fileListHeaders.d.ts +26 -0
- package/dist/files/file.d.ts +13 -0
- package/dist/files/fileType.d.ts +8 -0
- package/dist/files/folder.d.ts +17 -0
- package/dist/files/node.d.ts +177 -0
- package/dist/files/nodeData.d.ts +53 -0
- package/dist/index.cjs +1956 -1805
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +118 -1099
- package/dist/index.mjs +1957 -1806
- package/dist/index.mjs.map +1 -1
- package/dist/navigation/column.d.ts +27 -0
- package/dist/navigation/index.d.ts +7 -0
- package/dist/navigation/navigation.d.ts +73 -0
- package/dist/navigation/view.d.ts +91 -0
- package/dist/newFileMenu.d.ts +65 -0
- package/dist/permissions.d.ts +16 -0
- package/dist/utils/fileSize.d.ts +25 -0
- package/dist/utils/fileSorting.d.ts +34 -0
- package/dist/utils/filename-validation.d.ts +51 -0
- package/dist/utils/filename.d.ts +24 -0
- package/dist/utils/logger.d.ts +2 -0
- package/dist/utils/sorting.d.ts +12 -0
- package/dist/vendor.LICENSE.txt +1 -1
- package/package.json +14 -14
- package/dist/chunks/dav-BBwoJ8WE.cjs.map +0 -1
- package/dist/chunks/dav-DxfiR0wZ.mjs.map +0 -1
- package/dist/dav.d.ts +0 -370
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const dav = require("./chunks/dav-
|
|
3
|
+
const dav = require("./chunks/dav-CtqjqS4O.cjs");
|
|
4
4
|
const capabilities = require("@nextcloud/capabilities");
|
|
5
5
|
const path = require("path");
|
|
6
6
|
const l10n = require("@nextcloud/l10n");
|
|
@@ -212,7 +212,7 @@ class FileListAction {
|
|
|
212
212
|
if (!action.displayName || typeof action.displayName !== "function") {
|
|
213
213
|
throw new Error("Invalid displayName function");
|
|
214
214
|
}
|
|
215
|
-
if (
|
|
215
|
+
if ("iconSvgInline" in action && typeof action.iconSvgInline !== "function") {
|
|
216
216
|
throw new Error("Invalid iconSvgInline function");
|
|
217
217
|
}
|
|
218
218
|
if ("order" in action && typeof action.order !== "number") {
|
|
@@ -604,1604 +604,1688 @@ const isValidColumn = function(column) {
|
|
|
604
604
|
function getDefaultExportFromCjs(x) {
|
|
605
605
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
606
606
|
}
|
|
607
|
-
var validator
|
|
608
|
-
var util
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
const
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
allmatches
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
return matches;
|
|
628
|
-
};
|
|
629
|
-
const isName = function(string) {
|
|
630
|
-
const match = regexName.exec(string);
|
|
631
|
-
return !(match === null || typeof match === "undefined");
|
|
632
|
-
};
|
|
633
|
-
exports2.isExist = function(v) {
|
|
634
|
-
return typeof v !== "undefined";
|
|
635
|
-
};
|
|
636
|
-
exports2.isEmptyObject = function(obj) {
|
|
637
|
-
return Object.keys(obj).length === 0;
|
|
638
|
-
};
|
|
639
|
-
exports2.merge = function(target, a, arrayMode) {
|
|
640
|
-
if (a) {
|
|
641
|
-
const keys = Object.keys(a);
|
|
642
|
-
const len = keys.length;
|
|
643
|
-
for (let i = 0; i < len; i++) {
|
|
644
|
-
if (arrayMode === "strict") {
|
|
645
|
-
target[keys[i]] = [a[keys[i]]];
|
|
646
|
-
} else {
|
|
647
|
-
target[keys[i]] = a[keys[i]];
|
|
607
|
+
var validator = {};
|
|
608
|
+
var util = {};
|
|
609
|
+
var hasRequiredUtil;
|
|
610
|
+
function requireUtil() {
|
|
611
|
+
if (hasRequiredUtil) return util;
|
|
612
|
+
hasRequiredUtil = 1;
|
|
613
|
+
(function(exports2) {
|
|
614
|
+
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";
|
|
615
|
+
const nameChar = nameStartChar + "\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
|
|
616
|
+
const nameRegexp = "[" + nameStartChar + "][" + nameChar + "]*";
|
|
617
|
+
const regexName = new RegExp("^" + nameRegexp + "$");
|
|
618
|
+
const getAllMatches = function(string, regex) {
|
|
619
|
+
const matches = [];
|
|
620
|
+
let match = regex.exec(string);
|
|
621
|
+
while (match) {
|
|
622
|
+
const allmatches = [];
|
|
623
|
+
allmatches.startIndex = regex.lastIndex - match[0].length;
|
|
624
|
+
const len = match.length;
|
|
625
|
+
for (let index = 0; index < len; index++) {
|
|
626
|
+
allmatches.push(match[index]);
|
|
648
627
|
}
|
|
628
|
+
matches.push(allmatches);
|
|
629
|
+
match = regex.exec(string);
|
|
649
630
|
}
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
return
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
const
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
validator$2.validate = function(xmlData, options) {
|
|
670
|
-
options = Object.assign({}, defaultOptions$2, options);
|
|
671
|
-
const tags = [];
|
|
672
|
-
let tagFound = false;
|
|
673
|
-
let reachedRoot = false;
|
|
674
|
-
if (xmlData[0] === "\uFEFF") {
|
|
675
|
-
xmlData = xmlData.substr(1);
|
|
676
|
-
}
|
|
677
|
-
for (let i = 0; i < xmlData.length; i++) {
|
|
678
|
-
if (xmlData[i] === "<" && xmlData[i + 1] === "?") {
|
|
679
|
-
i += 2;
|
|
680
|
-
i = readPI(xmlData, i);
|
|
681
|
-
if (i.err) return i;
|
|
682
|
-
} else if (xmlData[i] === "<") {
|
|
683
|
-
let tagStartPos = i;
|
|
684
|
-
i++;
|
|
685
|
-
if (xmlData[i] === "!") {
|
|
686
|
-
i = readCommentAndCDATA(xmlData, i);
|
|
687
|
-
continue;
|
|
688
|
-
} else {
|
|
689
|
-
let closingTag = false;
|
|
690
|
-
if (xmlData[i] === "/") {
|
|
691
|
-
closingTag = true;
|
|
692
|
-
i++;
|
|
693
|
-
}
|
|
694
|
-
let tagName = "";
|
|
695
|
-
for (; i < xmlData.length && xmlData[i] !== ">" && xmlData[i] !== " " && xmlData[i] !== " " && xmlData[i] !== "\n" && xmlData[i] !== "\r"; i++) {
|
|
696
|
-
tagName += xmlData[i];
|
|
697
|
-
}
|
|
698
|
-
tagName = tagName.trim();
|
|
699
|
-
if (tagName[tagName.length - 1] === "/") {
|
|
700
|
-
tagName = tagName.substring(0, tagName.length - 1);
|
|
701
|
-
i--;
|
|
702
|
-
}
|
|
703
|
-
if (!validateTagName(tagName)) {
|
|
704
|
-
let msg;
|
|
705
|
-
if (tagName.trim().length === 0) {
|
|
706
|
-
msg = "Invalid space after '<'.";
|
|
631
|
+
return matches;
|
|
632
|
+
};
|
|
633
|
+
const isName = function(string) {
|
|
634
|
+
const match = regexName.exec(string);
|
|
635
|
+
return !(match === null || typeof match === "undefined");
|
|
636
|
+
};
|
|
637
|
+
exports2.isExist = function(v) {
|
|
638
|
+
return typeof v !== "undefined";
|
|
639
|
+
};
|
|
640
|
+
exports2.isEmptyObject = function(obj) {
|
|
641
|
+
return Object.keys(obj).length === 0;
|
|
642
|
+
};
|
|
643
|
+
exports2.merge = function(target, a, arrayMode) {
|
|
644
|
+
if (a) {
|
|
645
|
+
const keys = Object.keys(a);
|
|
646
|
+
const len = keys.length;
|
|
647
|
+
for (let i = 0; i < len; i++) {
|
|
648
|
+
if (arrayMode === "strict") {
|
|
649
|
+
target[keys[i]] = [a[keys[i]]];
|
|
707
650
|
} else {
|
|
708
|
-
|
|
651
|
+
target[keys[i]] = a[keys[i]];
|
|
709
652
|
}
|
|
710
|
-
return getErrorObject("InvalidTag", msg, getLineNumberForPosition(xmlData, i));
|
|
711
|
-
}
|
|
712
|
-
const result = readAttributeStr(xmlData, i);
|
|
713
|
-
if (result === false) {
|
|
714
|
-
return getErrorObject("InvalidAttr", "Attributes for '" + tagName + "' have open quote.", getLineNumberForPosition(xmlData, i));
|
|
715
653
|
}
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
exports2.getValue = function(v) {
|
|
657
|
+
if (exports2.isExist(v)) {
|
|
658
|
+
return v;
|
|
659
|
+
} else {
|
|
660
|
+
return "";
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
exports2.isName = isName;
|
|
664
|
+
exports2.getAllMatches = getAllMatches;
|
|
665
|
+
exports2.nameRegexp = nameRegexp;
|
|
666
|
+
})(util);
|
|
667
|
+
return util;
|
|
668
|
+
}
|
|
669
|
+
var hasRequiredValidator;
|
|
670
|
+
function requireValidator() {
|
|
671
|
+
if (hasRequiredValidator) return validator;
|
|
672
|
+
hasRequiredValidator = 1;
|
|
673
|
+
const util2 = requireUtil();
|
|
674
|
+
const defaultOptions = {
|
|
675
|
+
allowBooleanAttributes: false,
|
|
676
|
+
//A tag can have attributes without any value
|
|
677
|
+
unpairedTags: []
|
|
678
|
+
};
|
|
679
|
+
validator.validate = function(xmlData, options) {
|
|
680
|
+
options = Object.assign({}, defaultOptions, options);
|
|
681
|
+
const tags = [];
|
|
682
|
+
let tagFound = false;
|
|
683
|
+
let reachedRoot = false;
|
|
684
|
+
if (xmlData[0] === "\uFEFF") {
|
|
685
|
+
xmlData = xmlData.substr(1);
|
|
686
|
+
}
|
|
687
|
+
for (let i = 0; i < xmlData.length; i++) {
|
|
688
|
+
if (xmlData[i] === "<" && xmlData[i + 1] === "?") {
|
|
689
|
+
i += 2;
|
|
690
|
+
i = readPI(xmlData, i);
|
|
691
|
+
if (i.err) return i;
|
|
692
|
+
} else if (xmlData[i] === "<") {
|
|
693
|
+
let tagStartPos = i;
|
|
694
|
+
i++;
|
|
695
|
+
if (xmlData[i] === "!") {
|
|
696
|
+
i = readCommentAndCDATA(xmlData, i);
|
|
697
|
+
continue;
|
|
698
|
+
} else {
|
|
699
|
+
let closingTag = false;
|
|
700
|
+
if (xmlData[i] === "/") {
|
|
701
|
+
closingTag = true;
|
|
702
|
+
i++;
|
|
726
703
|
}
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
} else if (attrStr.trim().length > 0) {
|
|
731
|
-
return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' can't have attributes or invalid starting.", getLineNumberForPosition(xmlData, tagStartPos));
|
|
732
|
-
} else if (tags.length === 0) {
|
|
733
|
-
return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' has not been opened.", getLineNumberForPosition(xmlData, tagStartPos));
|
|
734
|
-
} else {
|
|
735
|
-
const otg = tags.pop();
|
|
736
|
-
if (tagName !== otg.tagName) {
|
|
737
|
-
let openPos = getLineNumberForPosition(xmlData, otg.tagStartPos);
|
|
738
|
-
return getErrorObject(
|
|
739
|
-
"InvalidTag",
|
|
740
|
-
"Expected closing tag '" + otg.tagName + "' (opened in line " + openPos.line + ", col " + openPos.col + ") instead of closing tag '" + tagName + "'.",
|
|
741
|
-
getLineNumberForPosition(xmlData, tagStartPos)
|
|
742
|
-
);
|
|
743
|
-
}
|
|
744
|
-
if (tags.length == 0) {
|
|
745
|
-
reachedRoot = true;
|
|
746
|
-
}
|
|
704
|
+
let tagName = "";
|
|
705
|
+
for (; i < xmlData.length && xmlData[i] !== ">" && xmlData[i] !== " " && xmlData[i] !== " " && xmlData[i] !== "\n" && xmlData[i] !== "\r"; i++) {
|
|
706
|
+
tagName += xmlData[i];
|
|
747
707
|
}
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
708
|
+
tagName = tagName.trim();
|
|
709
|
+
if (tagName[tagName.length - 1] === "/") {
|
|
710
|
+
tagName = tagName.substring(0, tagName.length - 1);
|
|
711
|
+
i--;
|
|
752
712
|
}
|
|
753
|
-
if (
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
713
|
+
if (!validateTagName(tagName)) {
|
|
714
|
+
let msg;
|
|
715
|
+
if (tagName.trim().length === 0) {
|
|
716
|
+
msg = "Invalid space after '<'.";
|
|
717
|
+
} else {
|
|
718
|
+
msg = "Tag '" + tagName + "' is an invalid name.";
|
|
719
|
+
}
|
|
720
|
+
return getErrorObject("InvalidTag", msg, getLineNumberForPosition(xmlData, i));
|
|
758
721
|
}
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
722
|
+
const result = readAttributeStr(xmlData, i);
|
|
723
|
+
if (result === false) {
|
|
724
|
+
return getErrorObject("InvalidAttr", "Attributes for '" + tagName + "' have open quote.", getLineNumberForPosition(xmlData, i));
|
|
725
|
+
}
|
|
726
|
+
let attrStr = result.value;
|
|
727
|
+
i = result.index;
|
|
728
|
+
if (attrStr[attrStr.length - 1] === "/") {
|
|
729
|
+
const attrStrStart = i - attrStr.length;
|
|
730
|
+
attrStr = attrStr.substring(0, attrStr.length - 1);
|
|
731
|
+
const isValid = validateAttributeString(attrStr, options);
|
|
732
|
+
if (isValid === true) {
|
|
733
|
+
tagFound = true;
|
|
770
734
|
} else {
|
|
771
|
-
|
|
735
|
+
return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, attrStrStart + isValid.err.line));
|
|
736
|
+
}
|
|
737
|
+
} else if (closingTag) {
|
|
738
|
+
if (!result.tagClosed) {
|
|
739
|
+
return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' doesn't have proper closing.", getLineNumberForPosition(xmlData, i));
|
|
740
|
+
} else if (attrStr.trim().length > 0) {
|
|
741
|
+
return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' can't have attributes or invalid starting.", getLineNumberForPosition(xmlData, tagStartPos));
|
|
742
|
+
} else if (tags.length === 0) {
|
|
743
|
+
return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' has not been opened.", getLineNumberForPosition(xmlData, tagStartPos));
|
|
744
|
+
} else {
|
|
745
|
+
const otg = tags.pop();
|
|
746
|
+
if (tagName !== otg.tagName) {
|
|
747
|
+
let openPos = getLineNumberForPosition(xmlData, otg.tagStartPos);
|
|
748
|
+
return getErrorObject(
|
|
749
|
+
"InvalidTag",
|
|
750
|
+
"Expected closing tag '" + otg.tagName + "' (opened in line " + openPos.line + ", col " + openPos.col + ") instead of closing tag '" + tagName + "'.",
|
|
751
|
+
getLineNumberForPosition(xmlData, tagStartPos)
|
|
752
|
+
);
|
|
753
|
+
}
|
|
754
|
+
if (tags.length == 0) {
|
|
755
|
+
reachedRoot = true;
|
|
756
|
+
}
|
|
772
757
|
}
|
|
773
|
-
} else if (xmlData[i] === "&") {
|
|
774
|
-
const afterAmp = validateAmpersand(xmlData, i);
|
|
775
|
-
if (afterAmp == -1)
|
|
776
|
-
return getErrorObject("InvalidChar", "char '&' is not expected.", getLineNumberForPosition(xmlData, i));
|
|
777
|
-
i = afterAmp;
|
|
778
758
|
} else {
|
|
779
|
-
|
|
780
|
-
|
|
759
|
+
const isValid = validateAttributeString(attrStr, options);
|
|
760
|
+
if (isValid !== true) {
|
|
761
|
+
return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, i - attrStr.length + isValid.err.line));
|
|
762
|
+
}
|
|
763
|
+
if (reachedRoot === true) {
|
|
764
|
+
return getErrorObject("InvalidXml", "Multiple possible root nodes found.", getLineNumberForPosition(xmlData, i));
|
|
765
|
+
} else if (options.unpairedTags.indexOf(tagName) !== -1) ;
|
|
766
|
+
else {
|
|
767
|
+
tags.push({ tagName, tagStartPos });
|
|
768
|
+
}
|
|
769
|
+
tagFound = true;
|
|
770
|
+
}
|
|
771
|
+
for (i++; i < xmlData.length; i++) {
|
|
772
|
+
if (xmlData[i] === "<") {
|
|
773
|
+
if (xmlData[i + 1] === "!") {
|
|
774
|
+
i++;
|
|
775
|
+
i = readCommentAndCDATA(xmlData, i);
|
|
776
|
+
continue;
|
|
777
|
+
} else if (xmlData[i + 1] === "?") {
|
|
778
|
+
i = readPI(xmlData, ++i);
|
|
779
|
+
if (i.err) return i;
|
|
780
|
+
} else {
|
|
781
|
+
break;
|
|
782
|
+
}
|
|
783
|
+
} else if (xmlData[i] === "&") {
|
|
784
|
+
const afterAmp = validateAmpersand(xmlData, i);
|
|
785
|
+
if (afterAmp == -1)
|
|
786
|
+
return getErrorObject("InvalidChar", "char '&' is not expected.", getLineNumberForPosition(xmlData, i));
|
|
787
|
+
i = afterAmp;
|
|
788
|
+
} else {
|
|
789
|
+
if (reachedRoot === true && !isWhiteSpace(xmlData[i])) {
|
|
790
|
+
return getErrorObject("InvalidXml", "Extra text at the end", getLineNumberForPosition(xmlData, i));
|
|
791
|
+
}
|
|
781
792
|
}
|
|
782
793
|
}
|
|
794
|
+
if (xmlData[i] === "<") {
|
|
795
|
+
i--;
|
|
796
|
+
}
|
|
783
797
|
}
|
|
784
|
-
|
|
785
|
-
|
|
798
|
+
} else {
|
|
799
|
+
if (isWhiteSpace(xmlData[i])) {
|
|
800
|
+
continue;
|
|
786
801
|
}
|
|
802
|
+
return getErrorObject("InvalidChar", "char '" + xmlData[i] + "' is not expected.", getLineNumberForPosition(xmlData, i));
|
|
787
803
|
}
|
|
788
|
-
} else {
|
|
789
|
-
if (isWhiteSpace(xmlData[i])) {
|
|
790
|
-
continue;
|
|
791
|
-
}
|
|
792
|
-
return getErrorObject("InvalidChar", "char '" + xmlData[i] + "' is not expected.", getLineNumberForPosition(xmlData, i));
|
|
793
804
|
}
|
|
805
|
+
if (!tagFound) {
|
|
806
|
+
return getErrorObject("InvalidXml", "Start tag expected.", 1);
|
|
807
|
+
} else if (tags.length == 1) {
|
|
808
|
+
return getErrorObject("InvalidTag", "Unclosed tag '" + tags[0].tagName + "'.", getLineNumberForPosition(xmlData, tags[0].tagStartPos));
|
|
809
|
+
} else if (tags.length > 0) {
|
|
810
|
+
return getErrorObject("InvalidXml", "Invalid '" + JSON.stringify(tags.map((t) => t.tagName), null, 4).replace(/\r?\n/g, "") + "' found.", { line: 1, col: 1 });
|
|
811
|
+
}
|
|
812
|
+
return true;
|
|
813
|
+
};
|
|
814
|
+
function isWhiteSpace(char) {
|
|
815
|
+
return char === " " || char === " " || char === "\n" || char === "\r";
|
|
794
816
|
}
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
const start = i;
|
|
809
|
-
for (; i < xmlData.length; i++) {
|
|
810
|
-
if (xmlData[i] == "?" || xmlData[i] == " ") {
|
|
811
|
-
const tagname = xmlData.substr(start, i - start);
|
|
812
|
-
if (i > 5 && tagname === "xml") {
|
|
813
|
-
return getErrorObject("InvalidXml", "XML declaration allowed only at the start of the document.", getLineNumberForPosition(xmlData, i));
|
|
814
|
-
} else if (xmlData[i] == "?" && xmlData[i + 1] == ">") {
|
|
815
|
-
i++;
|
|
816
|
-
break;
|
|
817
|
-
} else {
|
|
818
|
-
continue;
|
|
817
|
+
function readPI(xmlData, i) {
|
|
818
|
+
const start = i;
|
|
819
|
+
for (; i < xmlData.length; i++) {
|
|
820
|
+
if (xmlData[i] == "?" || xmlData[i] == " ") {
|
|
821
|
+
const tagname = xmlData.substr(start, i - start);
|
|
822
|
+
if (i > 5 && tagname === "xml") {
|
|
823
|
+
return getErrorObject("InvalidXml", "XML declaration allowed only at the start of the document.", getLineNumberForPosition(xmlData, i));
|
|
824
|
+
} else if (xmlData[i] == "?" && xmlData[i + 1] == ">") {
|
|
825
|
+
i++;
|
|
826
|
+
break;
|
|
827
|
+
} else {
|
|
828
|
+
continue;
|
|
829
|
+
}
|
|
819
830
|
}
|
|
820
831
|
}
|
|
832
|
+
return i;
|
|
821
833
|
}
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
834
|
+
function readCommentAndCDATA(xmlData, i) {
|
|
835
|
+
if (xmlData.length > i + 5 && xmlData[i + 1] === "-" && xmlData[i + 2] === "-") {
|
|
836
|
+
for (i += 3; i < xmlData.length; i++) {
|
|
837
|
+
if (xmlData[i] === "-" && xmlData[i + 1] === "-" && xmlData[i + 2] === ">") {
|
|
838
|
+
i += 2;
|
|
839
|
+
break;
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
} else if (xmlData.length > i + 8 && xmlData[i + 1] === "D" && xmlData[i + 2] === "O" && xmlData[i + 3] === "C" && xmlData[i + 4] === "T" && xmlData[i + 5] === "Y" && xmlData[i + 6] === "P" && xmlData[i + 7] === "E") {
|
|
843
|
+
let angleBracketsCount = 1;
|
|
844
|
+
for (i += 8; i < xmlData.length; i++) {
|
|
845
|
+
if (xmlData[i] === "<") {
|
|
846
|
+
angleBracketsCount++;
|
|
847
|
+
} else if (xmlData[i] === ">") {
|
|
848
|
+
angleBracketsCount--;
|
|
849
|
+
if (angleBracketsCount === 0) {
|
|
850
|
+
break;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
} else if (xmlData.length > i + 9 && xmlData[i + 1] === "[" && xmlData[i + 2] === "C" && xmlData[i + 3] === "D" && xmlData[i + 4] === "A" && xmlData[i + 5] === "T" && xmlData[i + 6] === "A" && xmlData[i + 7] === "[") {
|
|
855
|
+
for (i += 8; i < xmlData.length; i++) {
|
|
856
|
+
if (xmlData[i] === "]" && xmlData[i + 1] === "]" && xmlData[i + 2] === ">") {
|
|
857
|
+
i += 2;
|
|
858
|
+
break;
|
|
859
|
+
}
|
|
830
860
|
}
|
|
831
861
|
}
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
862
|
+
return i;
|
|
863
|
+
}
|
|
864
|
+
const doubleQuote = '"';
|
|
865
|
+
const singleQuote = "'";
|
|
866
|
+
function readAttributeStr(xmlData, i) {
|
|
867
|
+
let attrStr = "";
|
|
868
|
+
let startChar = "";
|
|
869
|
+
let tagClosed = false;
|
|
870
|
+
for (; i < xmlData.length; i++) {
|
|
871
|
+
if (xmlData[i] === doubleQuote || xmlData[i] === singleQuote) {
|
|
872
|
+
if (startChar === "") {
|
|
873
|
+
startChar = xmlData[i];
|
|
874
|
+
} else if (startChar !== xmlData[i]) ;
|
|
875
|
+
else {
|
|
876
|
+
startChar = "";
|
|
877
|
+
}
|
|
837
878
|
} else if (xmlData[i] === ">") {
|
|
838
|
-
|
|
839
|
-
|
|
879
|
+
if (startChar === "") {
|
|
880
|
+
tagClosed = true;
|
|
840
881
|
break;
|
|
841
882
|
}
|
|
842
883
|
}
|
|
884
|
+
attrStr += xmlData[i];
|
|
843
885
|
}
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
if (xmlData[i] === "]" && xmlData[i + 1] === "]" && xmlData[i + 2] === ">") {
|
|
847
|
-
i += 2;
|
|
848
|
-
break;
|
|
849
|
-
}
|
|
886
|
+
if (startChar !== "") {
|
|
887
|
+
return false;
|
|
850
888
|
}
|
|
889
|
+
return {
|
|
890
|
+
value: attrStr,
|
|
891
|
+
index: i,
|
|
892
|
+
tagClosed
|
|
893
|
+
};
|
|
851
894
|
}
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
const
|
|
855
|
-
const
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
startChar = xmlData[i];
|
|
864
|
-
} else if (startChar !== xmlData[i]) ;
|
|
865
|
-
else {
|
|
866
|
-
startChar = "";
|
|
895
|
+
const validAttrStrRegxp = new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`, "g");
|
|
896
|
+
function validateAttributeString(attrStr, options) {
|
|
897
|
+
const matches = util2.getAllMatches(attrStr, validAttrStrRegxp);
|
|
898
|
+
const attrNames = {};
|
|
899
|
+
for (let i = 0; i < matches.length; i++) {
|
|
900
|
+
if (matches[i][1].length === 0) {
|
|
901
|
+
return getErrorObject("InvalidAttr", "Attribute '" + matches[i][2] + "' has no space in starting.", getPositionFromMatch(matches[i]));
|
|
902
|
+
} else if (matches[i][3] !== void 0 && matches[i][4] === void 0) {
|
|
903
|
+
return getErrorObject("InvalidAttr", "Attribute '" + matches[i][2] + "' is without value.", getPositionFromMatch(matches[i]));
|
|
904
|
+
} else if (matches[i][3] === void 0 && !options.allowBooleanAttributes) {
|
|
905
|
+
return getErrorObject("InvalidAttr", "boolean attribute '" + matches[i][2] + "' is not allowed.", getPositionFromMatch(matches[i]));
|
|
867
906
|
}
|
|
868
|
-
|
|
869
|
-
if (
|
|
870
|
-
|
|
871
|
-
|
|
907
|
+
const attrName = matches[i][2];
|
|
908
|
+
if (!validateAttrName(attrName)) {
|
|
909
|
+
return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is an invalid name.", getPositionFromMatch(matches[i]));
|
|
910
|
+
}
|
|
911
|
+
if (!attrNames.hasOwnProperty(attrName)) {
|
|
912
|
+
attrNames[attrName] = 1;
|
|
913
|
+
} else {
|
|
914
|
+
return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is repeated.", getPositionFromMatch(matches[i]));
|
|
872
915
|
}
|
|
873
916
|
}
|
|
874
|
-
|
|
875
|
-
}
|
|
876
|
-
if (startChar !== "") {
|
|
877
|
-
return false;
|
|
917
|
+
return true;
|
|
878
918
|
}
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
if (matches[i][1].length === 0) {
|
|
891
|
-
return getErrorObject("InvalidAttr", "Attribute '" + matches[i][2] + "' has no space in starting.", getPositionFromMatch(matches[i]));
|
|
892
|
-
} else if (matches[i][3] !== void 0 && matches[i][4] === void 0) {
|
|
893
|
-
return getErrorObject("InvalidAttr", "Attribute '" + matches[i][2] + "' is without value.", getPositionFromMatch(matches[i]));
|
|
894
|
-
} else if (matches[i][3] === void 0 && !options.allowBooleanAttributes) {
|
|
895
|
-
return getErrorObject("InvalidAttr", "boolean attribute '" + matches[i][2] + "' is not allowed.", getPositionFromMatch(matches[i]));
|
|
896
|
-
}
|
|
897
|
-
const attrName = matches[i][2];
|
|
898
|
-
if (!validateAttrName(attrName)) {
|
|
899
|
-
return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is an invalid name.", getPositionFromMatch(matches[i]));
|
|
900
|
-
}
|
|
901
|
-
if (!attrNames.hasOwnProperty(attrName)) {
|
|
902
|
-
attrNames[attrName] = 1;
|
|
903
|
-
} else {
|
|
904
|
-
return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is repeated.", getPositionFromMatch(matches[i]));
|
|
919
|
+
function validateNumberAmpersand(xmlData, i) {
|
|
920
|
+
let re2 = /\d/;
|
|
921
|
+
if (xmlData[i] === "x") {
|
|
922
|
+
i++;
|
|
923
|
+
re2 = /[\da-fA-F]/;
|
|
924
|
+
}
|
|
925
|
+
for (; i < xmlData.length; i++) {
|
|
926
|
+
if (xmlData[i] === ";")
|
|
927
|
+
return i;
|
|
928
|
+
if (!xmlData[i].match(re2))
|
|
929
|
+
break;
|
|
905
930
|
}
|
|
931
|
+
return -1;
|
|
906
932
|
}
|
|
907
|
-
|
|
908
|
-
}
|
|
909
|
-
function validateNumberAmpersand(xmlData, i) {
|
|
910
|
-
let re2 = /\d/;
|
|
911
|
-
if (xmlData[i] === "x") {
|
|
933
|
+
function validateAmpersand(xmlData, i) {
|
|
912
934
|
i++;
|
|
913
|
-
re2 = /[\da-fA-F]/;
|
|
914
|
-
}
|
|
915
|
-
for (; i < xmlData.length; i++) {
|
|
916
935
|
if (xmlData[i] === ";")
|
|
917
|
-
return
|
|
918
|
-
if (
|
|
919
|
-
|
|
936
|
+
return -1;
|
|
937
|
+
if (xmlData[i] === "#") {
|
|
938
|
+
i++;
|
|
939
|
+
return validateNumberAmpersand(xmlData, i);
|
|
940
|
+
}
|
|
941
|
+
let count = 0;
|
|
942
|
+
for (; i < xmlData.length; i++, count++) {
|
|
943
|
+
if (xmlData[i].match(/\w/) && count < 20)
|
|
944
|
+
continue;
|
|
945
|
+
if (xmlData[i] === ";")
|
|
946
|
+
break;
|
|
947
|
+
return -1;
|
|
948
|
+
}
|
|
949
|
+
return i;
|
|
920
950
|
}
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
951
|
+
function getErrorObject(code, message, lineNumber) {
|
|
952
|
+
return {
|
|
953
|
+
err: {
|
|
954
|
+
code,
|
|
955
|
+
msg: message,
|
|
956
|
+
line: lineNumber.line || lineNumber,
|
|
957
|
+
col: lineNumber.col
|
|
958
|
+
}
|
|
959
|
+
};
|
|
930
960
|
}
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
961
|
+
function validateAttrName(attrName) {
|
|
962
|
+
return util2.isName(attrName);
|
|
963
|
+
}
|
|
964
|
+
function validateTagName(tagname) {
|
|
965
|
+
return util2.isName(tagname);
|
|
966
|
+
}
|
|
967
|
+
function getLineNumberForPosition(xmlData, index) {
|
|
968
|
+
const lines = xmlData.substring(0, index).split(/\r?\n/);
|
|
969
|
+
return {
|
|
970
|
+
line: lines.length,
|
|
971
|
+
// column number is last line's length + 1, because column numbering starts at 1:
|
|
972
|
+
col: lines[lines.length - 1].length + 1
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
function getPositionFromMatch(match) {
|
|
976
|
+
return match.startIndex + match[1].length;
|
|
938
977
|
}
|
|
939
|
-
return
|
|
978
|
+
return validator;
|
|
940
979
|
}
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
980
|
+
var OptionsBuilder = {};
|
|
981
|
+
var hasRequiredOptionsBuilder;
|
|
982
|
+
function requireOptionsBuilder() {
|
|
983
|
+
if (hasRequiredOptionsBuilder) return OptionsBuilder;
|
|
984
|
+
hasRequiredOptionsBuilder = 1;
|
|
985
|
+
const defaultOptions = {
|
|
986
|
+
preserveOrder: false,
|
|
987
|
+
attributeNamePrefix: "@_",
|
|
988
|
+
attributesGroupName: false,
|
|
989
|
+
textNodeName: "#text",
|
|
990
|
+
ignoreAttributes: true,
|
|
991
|
+
removeNSPrefix: false,
|
|
992
|
+
// remove NS from tag name or attribute name if true
|
|
993
|
+
allowBooleanAttributes: false,
|
|
994
|
+
//a tag can have attributes without any value
|
|
995
|
+
//ignoreRootElement : false,
|
|
996
|
+
parseTagValue: true,
|
|
997
|
+
parseAttributeValue: false,
|
|
998
|
+
trimValues: true,
|
|
999
|
+
//Trim string values of tag and attributes
|
|
1000
|
+
cdataPropName: false,
|
|
1001
|
+
numberParseOptions: {
|
|
1002
|
+
hex: true,
|
|
1003
|
+
leadingZeros: true,
|
|
1004
|
+
eNotation: true
|
|
1005
|
+
},
|
|
1006
|
+
tagValueProcessor: function(tagName, val) {
|
|
1007
|
+
return val;
|
|
1008
|
+
},
|
|
1009
|
+
attributeValueProcessor: function(attrName, val) {
|
|
1010
|
+
return val;
|
|
1011
|
+
},
|
|
1012
|
+
stopNodes: [],
|
|
1013
|
+
//nested tags will not be parsed even for errors
|
|
1014
|
+
alwaysCreateTextNode: false,
|
|
1015
|
+
isArray: () => false,
|
|
1016
|
+
commentPropName: false,
|
|
1017
|
+
unpairedTags: [],
|
|
1018
|
+
processEntities: true,
|
|
1019
|
+
htmlEntities: false,
|
|
1020
|
+
ignoreDeclaration: false,
|
|
1021
|
+
ignorePiTags: false,
|
|
1022
|
+
transformTagName: false,
|
|
1023
|
+
transformAttributeName: false,
|
|
1024
|
+
updateTag: function(tagName, jPath, attrs) {
|
|
1025
|
+
return tagName;
|
|
1026
|
+
}
|
|
1027
|
+
// skipEmptyListItem: false
|
|
949
1028
|
};
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
return util$2.isName(attrName);
|
|
953
|
-
}
|
|
954
|
-
function validateTagName(tagname) {
|
|
955
|
-
return util$2.isName(tagname);
|
|
956
|
-
}
|
|
957
|
-
function getLineNumberForPosition(xmlData, index) {
|
|
958
|
-
const lines = xmlData.substring(0, index).split(/\r?\n/);
|
|
959
|
-
return {
|
|
960
|
-
line: lines.length,
|
|
961
|
-
// column number is last line's length + 1, because column numbering starts at 1:
|
|
962
|
-
col: lines[lines.length - 1].length + 1
|
|
1029
|
+
const buildOptions = function(options) {
|
|
1030
|
+
return Object.assign({}, defaultOptions, options);
|
|
963
1031
|
};
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
return
|
|
967
|
-
}
|
|
968
|
-
var
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
tagValueProcessor: function(tagName, val2) {
|
|
991
|
-
return val2;
|
|
992
|
-
},
|
|
993
|
-
attributeValueProcessor: function(attrName, val2) {
|
|
994
|
-
return val2;
|
|
995
|
-
},
|
|
996
|
-
stopNodes: [],
|
|
997
|
-
//nested tags will not be parsed even for errors
|
|
998
|
-
alwaysCreateTextNode: false,
|
|
999
|
-
isArray: () => false,
|
|
1000
|
-
commentPropName: false,
|
|
1001
|
-
unpairedTags: [],
|
|
1002
|
-
processEntities: true,
|
|
1003
|
-
htmlEntities: false,
|
|
1004
|
-
ignoreDeclaration: false,
|
|
1005
|
-
ignorePiTags: false,
|
|
1006
|
-
transformTagName: false,
|
|
1007
|
-
transformAttributeName: false,
|
|
1008
|
-
updateTag: function(tagName, jPath, attrs) {
|
|
1009
|
-
return tagName;
|
|
1010
|
-
}
|
|
1011
|
-
// skipEmptyListItem: false
|
|
1012
|
-
};
|
|
1013
|
-
const buildOptions$1 = function(options) {
|
|
1014
|
-
return Object.assign({}, defaultOptions$1, options);
|
|
1015
|
-
};
|
|
1016
|
-
OptionsBuilder.buildOptions = buildOptions$1;
|
|
1017
|
-
OptionsBuilder.defaultOptions = defaultOptions$1;
|
|
1018
|
-
class XmlNode {
|
|
1019
|
-
constructor(tagname) {
|
|
1020
|
-
this.tagname = tagname;
|
|
1021
|
-
this.child = [];
|
|
1022
|
-
this[":@"] = {};
|
|
1023
|
-
}
|
|
1024
|
-
add(key, val2) {
|
|
1025
|
-
if (key === "__proto__") key = "#__proto__";
|
|
1026
|
-
this.child.push({ [key]: val2 });
|
|
1027
|
-
}
|
|
1028
|
-
addChild(node) {
|
|
1029
|
-
if (node.tagname === "__proto__") node.tagname = "#__proto__";
|
|
1030
|
-
if (node[":@"] && Object.keys(node[":@"]).length > 0) {
|
|
1031
|
-
this.child.push({ [node.tagname]: node.child, [":@"]: node[":@"] });
|
|
1032
|
-
} else {
|
|
1033
|
-
this.child.push({ [node.tagname]: node.child });
|
|
1032
|
+
OptionsBuilder.buildOptions = buildOptions;
|
|
1033
|
+
OptionsBuilder.defaultOptions = defaultOptions;
|
|
1034
|
+
return OptionsBuilder;
|
|
1035
|
+
}
|
|
1036
|
+
var xmlNode;
|
|
1037
|
+
var hasRequiredXmlNode;
|
|
1038
|
+
function requireXmlNode() {
|
|
1039
|
+
if (hasRequiredXmlNode) return xmlNode;
|
|
1040
|
+
hasRequiredXmlNode = 1;
|
|
1041
|
+
class XmlNode {
|
|
1042
|
+
constructor(tagname) {
|
|
1043
|
+
this.tagname = tagname;
|
|
1044
|
+
this.child = [];
|
|
1045
|
+
this[":@"] = {};
|
|
1046
|
+
}
|
|
1047
|
+
add(key, val) {
|
|
1048
|
+
if (key === "__proto__") key = "#__proto__";
|
|
1049
|
+
this.child.push({ [key]: val });
|
|
1050
|
+
}
|
|
1051
|
+
addChild(node) {
|
|
1052
|
+
if (node.tagname === "__proto__") node.tagname = "#__proto__";
|
|
1053
|
+
if (node[":@"] && Object.keys(node[":@"]).length > 0) {
|
|
1054
|
+
this.child.push({ [node.tagname]: node.child, [":@"]: node[":@"] });
|
|
1055
|
+
} else {
|
|
1056
|
+
this.child.push({ [node.tagname]: node.child });
|
|
1057
|
+
}
|
|
1034
1058
|
}
|
|
1035
1059
|
}
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
if (
|
|
1066
|
-
|
|
1060
|
+
xmlNode = XmlNode;
|
|
1061
|
+
return xmlNode;
|
|
1062
|
+
}
|
|
1063
|
+
var DocTypeReader;
|
|
1064
|
+
var hasRequiredDocTypeReader;
|
|
1065
|
+
function requireDocTypeReader() {
|
|
1066
|
+
if (hasRequiredDocTypeReader) return DocTypeReader;
|
|
1067
|
+
hasRequiredDocTypeReader = 1;
|
|
1068
|
+
const util2 = requireUtil();
|
|
1069
|
+
function readDocType(xmlData, i) {
|
|
1070
|
+
const entities = {};
|
|
1071
|
+
if (xmlData[i + 3] === "O" && xmlData[i + 4] === "C" && xmlData[i + 5] === "T" && xmlData[i + 6] === "Y" && xmlData[i + 7] === "P" && xmlData[i + 8] === "E") {
|
|
1072
|
+
i = i + 9;
|
|
1073
|
+
let angleBracketsCount = 1;
|
|
1074
|
+
let hasBody = false, comment = false;
|
|
1075
|
+
let exp = "";
|
|
1076
|
+
for (; i < xmlData.length; i++) {
|
|
1077
|
+
if (xmlData[i] === "<" && !comment) {
|
|
1078
|
+
if (hasBody && isEntity(xmlData, i)) {
|
|
1079
|
+
i += 7;
|
|
1080
|
+
let entityName, val;
|
|
1081
|
+
[entityName, val, i] = readEntityExp(xmlData, i + 1);
|
|
1082
|
+
if (val.indexOf("&") === -1)
|
|
1083
|
+
entities[validateEntityName(entityName)] = {
|
|
1084
|
+
regx: RegExp(`&${entityName};`, "g"),
|
|
1085
|
+
val
|
|
1086
|
+
};
|
|
1087
|
+
} else if (hasBody && isElement(xmlData, i)) i += 8;
|
|
1088
|
+
else if (hasBody && isAttlist(xmlData, i)) i += 8;
|
|
1089
|
+
else if (hasBody && isNotation(xmlData, i)) i += 9;
|
|
1090
|
+
else comment = true;
|
|
1091
|
+
angleBracketsCount++;
|
|
1092
|
+
exp = "";
|
|
1093
|
+
} else if (xmlData[i] === ">") {
|
|
1094
|
+
if (comment) {
|
|
1095
|
+
if (xmlData[i - 1] === "-" && xmlData[i - 2] === "-") {
|
|
1096
|
+
comment = false;
|
|
1097
|
+
angleBracketsCount--;
|
|
1098
|
+
}
|
|
1099
|
+
} else {
|
|
1067
1100
|
angleBracketsCount--;
|
|
1068
1101
|
}
|
|
1102
|
+
if (angleBracketsCount === 0) {
|
|
1103
|
+
break;
|
|
1104
|
+
}
|
|
1105
|
+
} else if (xmlData[i] === "[") {
|
|
1106
|
+
hasBody = true;
|
|
1069
1107
|
} else {
|
|
1070
|
-
|
|
1071
|
-
}
|
|
1072
|
-
if (angleBracketsCount === 0) {
|
|
1073
|
-
break;
|
|
1108
|
+
exp += xmlData[i];
|
|
1074
1109
|
}
|
|
1075
|
-
} else if (xmlData[i] === "[") {
|
|
1076
|
-
hasBody = true;
|
|
1077
|
-
} else {
|
|
1078
|
-
exp += xmlData[i];
|
|
1079
1110
|
}
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
throw new Error(`Unclosed DOCTYPE`);
|
|
1083
|
-
}
|
|
1084
|
-
} else {
|
|
1085
|
-
throw new Error(`Invalid Tag instead of DOCTYPE`);
|
|
1086
|
-
}
|
|
1087
|
-
return { entities, i };
|
|
1088
|
-
}
|
|
1089
|
-
function readEntityExp(xmlData, i) {
|
|
1090
|
-
let entityName2 = "";
|
|
1091
|
-
for (; i < xmlData.length && (xmlData[i] !== "'" && xmlData[i] !== '"'); i++) {
|
|
1092
|
-
entityName2 += xmlData[i];
|
|
1093
|
-
}
|
|
1094
|
-
entityName2 = entityName2.trim();
|
|
1095
|
-
if (entityName2.indexOf(" ") !== -1) throw new Error("External entites are not supported");
|
|
1096
|
-
const startChar = xmlData[i++];
|
|
1097
|
-
let val2 = "";
|
|
1098
|
-
for (; i < xmlData.length && xmlData[i] !== startChar; i++) {
|
|
1099
|
-
val2 += xmlData[i];
|
|
1100
|
-
}
|
|
1101
|
-
return [entityName2, val2, i];
|
|
1102
|
-
}
|
|
1103
|
-
function isComment(xmlData, i) {
|
|
1104
|
-
if (xmlData[i + 1] === "!" && xmlData[i + 2] === "-" && xmlData[i + 3] === "-") return true;
|
|
1105
|
-
return false;
|
|
1106
|
-
}
|
|
1107
|
-
function isEntity(xmlData, i) {
|
|
1108
|
-
if (xmlData[i + 1] === "!" && xmlData[i + 2] === "E" && xmlData[i + 3] === "N" && xmlData[i + 4] === "T" && xmlData[i + 5] === "I" && xmlData[i + 6] === "T" && xmlData[i + 7] === "Y") return true;
|
|
1109
|
-
return false;
|
|
1110
|
-
}
|
|
1111
|
-
function isElement(xmlData, i) {
|
|
1112
|
-
if (xmlData[i + 1] === "!" && xmlData[i + 2] === "E" && xmlData[i + 3] === "L" && xmlData[i + 4] === "E" && xmlData[i + 5] === "M" && xmlData[i + 6] === "E" && xmlData[i + 7] === "N" && xmlData[i + 8] === "T") return true;
|
|
1113
|
-
return false;
|
|
1114
|
-
}
|
|
1115
|
-
function isAttlist(xmlData, i) {
|
|
1116
|
-
if (xmlData[i + 1] === "!" && xmlData[i + 2] === "A" && xmlData[i + 3] === "T" && xmlData[i + 4] === "T" && xmlData[i + 5] === "L" && xmlData[i + 6] === "I" && xmlData[i + 7] === "S" && xmlData[i + 8] === "T") return true;
|
|
1117
|
-
return false;
|
|
1118
|
-
}
|
|
1119
|
-
function isNotation(xmlData, i) {
|
|
1120
|
-
if (xmlData[i + 1] === "!" && xmlData[i + 2] === "N" && xmlData[i + 3] === "O" && xmlData[i + 4] === "T" && xmlData[i + 5] === "A" && xmlData[i + 6] === "T" && xmlData[i + 7] === "I" && xmlData[i + 8] === "O" && xmlData[i + 9] === "N") return true;
|
|
1121
|
-
return false;
|
|
1122
|
-
}
|
|
1123
|
-
function validateEntityName(name) {
|
|
1124
|
-
if (util$1.isName(name))
|
|
1125
|
-
return name;
|
|
1126
|
-
else
|
|
1127
|
-
throw new Error(`Invalid entity name ${name}`);
|
|
1128
|
-
}
|
|
1129
|
-
var DocTypeReader = readDocType$1;
|
|
1130
|
-
const hexRegex = /^[-+]?0x[a-fA-F0-9]+$/;
|
|
1131
|
-
const numRegex = /^([\-\+])?(0*)(\.[0-9]+([eE]\-?[0-9]+)?|[0-9]+(\.[0-9]+([eE]\-?[0-9]+)?)?)$/;
|
|
1132
|
-
if (!Number.parseInt && window.parseInt) {
|
|
1133
|
-
Number.parseInt = window.parseInt;
|
|
1134
|
-
}
|
|
1135
|
-
if (!Number.parseFloat && window.parseFloat) {
|
|
1136
|
-
Number.parseFloat = window.parseFloat;
|
|
1137
|
-
}
|
|
1138
|
-
const consider = {
|
|
1139
|
-
hex: true,
|
|
1140
|
-
leadingZeros: true,
|
|
1141
|
-
decimalPoint: ".",
|
|
1142
|
-
eNotation: true
|
|
1143
|
-
//skipLike: /regex/
|
|
1144
|
-
};
|
|
1145
|
-
function toNumber$1(str, options = {}) {
|
|
1146
|
-
options = Object.assign({}, consider, options);
|
|
1147
|
-
if (!str || typeof str !== "string") return str;
|
|
1148
|
-
let trimmedStr = str.trim();
|
|
1149
|
-
if (options.skipLike !== void 0 && options.skipLike.test(trimmedStr)) return str;
|
|
1150
|
-
else if (options.hex && hexRegex.test(trimmedStr)) {
|
|
1151
|
-
return Number.parseInt(trimmedStr, 16);
|
|
1152
|
-
} else {
|
|
1153
|
-
const match = numRegex.exec(trimmedStr);
|
|
1154
|
-
if (match) {
|
|
1155
|
-
const sign = match[1];
|
|
1156
|
-
const leadingZeros = match[2];
|
|
1157
|
-
let numTrimmedByZeros = trimZeros(match[3]);
|
|
1158
|
-
const eNotation = match[4] || match[6];
|
|
1159
|
-
if (!options.leadingZeros && leadingZeros.length > 0 && sign && trimmedStr[2] !== ".") return str;
|
|
1160
|
-
else if (!options.leadingZeros && leadingZeros.length > 0 && !sign && trimmedStr[1] !== ".") return str;
|
|
1161
|
-
else {
|
|
1162
|
-
const num = Number(trimmedStr);
|
|
1163
|
-
const numStr = "" + num;
|
|
1164
|
-
if (numStr.search(/[eE]/) !== -1) {
|
|
1165
|
-
if (options.eNotation) return num;
|
|
1166
|
-
else return str;
|
|
1167
|
-
} else if (eNotation) {
|
|
1168
|
-
if (options.eNotation) return num;
|
|
1169
|
-
else return str;
|
|
1170
|
-
} else if (trimmedStr.indexOf(".") !== -1) {
|
|
1171
|
-
if (numStr === "0" && numTrimmedByZeros === "") return num;
|
|
1172
|
-
else if (numStr === numTrimmedByZeros) return num;
|
|
1173
|
-
else if (sign && numStr === "-" + numTrimmedByZeros) return num;
|
|
1174
|
-
else return str;
|
|
1175
|
-
}
|
|
1176
|
-
if (leadingZeros) {
|
|
1177
|
-
if (numTrimmedByZeros === numStr) return num;
|
|
1178
|
-
else if (sign + numTrimmedByZeros === numStr) return num;
|
|
1179
|
-
else return str;
|
|
1180
|
-
}
|
|
1181
|
-
if (trimmedStr === numStr) return num;
|
|
1182
|
-
else if (trimmedStr === sign + numStr) return num;
|
|
1183
|
-
return str;
|
|
1111
|
+
if (angleBracketsCount !== 0) {
|
|
1112
|
+
throw new Error(`Unclosed DOCTYPE`);
|
|
1184
1113
|
}
|
|
1185
1114
|
} else {
|
|
1186
|
-
|
|
1115
|
+
throw new Error(`Invalid Tag instead of DOCTYPE`);
|
|
1187
1116
|
}
|
|
1117
|
+
return { entities, i };
|
|
1188
1118
|
}
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1119
|
+
function readEntityExp(xmlData, i) {
|
|
1120
|
+
let entityName = "";
|
|
1121
|
+
for (; i < xmlData.length && (xmlData[i] !== "'" && xmlData[i] !== '"'); i++) {
|
|
1122
|
+
entityName += xmlData[i];
|
|
1123
|
+
}
|
|
1124
|
+
entityName = entityName.trim();
|
|
1125
|
+
if (entityName.indexOf(" ") !== -1) throw new Error("External entites are not supported");
|
|
1126
|
+
const startChar = xmlData[i++];
|
|
1127
|
+
let val = "";
|
|
1128
|
+
for (; i < xmlData.length && xmlData[i] !== startChar; i++) {
|
|
1129
|
+
val += xmlData[i];
|
|
1130
|
+
}
|
|
1131
|
+
return [entityName, val, i];
|
|
1197
1132
|
}
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
function getIgnoreAttributesFn$2(ignoreAttributes2) {
|
|
1202
|
-
if (typeof ignoreAttributes2 === "function") {
|
|
1203
|
-
return ignoreAttributes2;
|
|
1204
|
-
}
|
|
1205
|
-
if (Array.isArray(ignoreAttributes2)) {
|
|
1206
|
-
return (attrName) => {
|
|
1207
|
-
for (const pattern of ignoreAttributes2) {
|
|
1208
|
-
if (typeof pattern === "string" && attrName === pattern) {
|
|
1209
|
-
return true;
|
|
1210
|
-
}
|
|
1211
|
-
if (pattern instanceof RegExp && pattern.test(attrName)) {
|
|
1212
|
-
return true;
|
|
1213
|
-
}
|
|
1214
|
-
}
|
|
1215
|
-
};
|
|
1133
|
+
function isEntity(xmlData, i) {
|
|
1134
|
+
if (xmlData[i + 1] === "!" && xmlData[i + 2] === "E" && xmlData[i + 3] === "N" && xmlData[i + 4] === "T" && xmlData[i + 5] === "I" && xmlData[i + 6] === "T" && xmlData[i + 7] === "Y") return true;
|
|
1135
|
+
return false;
|
|
1216
1136
|
}
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
const util = util$3;
|
|
1221
|
-
const xmlNode = xmlNode$1;
|
|
1222
|
-
const readDocType = DocTypeReader;
|
|
1223
|
-
const toNumber = strnum;
|
|
1224
|
-
const getIgnoreAttributesFn$1 = ignoreAttributes;
|
|
1225
|
-
let OrderedObjParser$1 = class OrderedObjParser {
|
|
1226
|
-
constructor(options) {
|
|
1227
|
-
this.options = options;
|
|
1228
|
-
this.currentNode = null;
|
|
1229
|
-
this.tagsNodeStack = [];
|
|
1230
|
-
this.docTypeEntities = {};
|
|
1231
|
-
this.lastEntities = {
|
|
1232
|
-
"apos": { regex: /&(apos|#39|#x27);/g, val: "'" },
|
|
1233
|
-
"gt": { regex: /&(gt|#62|#x3E);/g, val: ">" },
|
|
1234
|
-
"lt": { regex: /&(lt|#60|#x3C);/g, val: "<" },
|
|
1235
|
-
"quot": { regex: /&(quot|#34|#x22);/g, val: '"' }
|
|
1236
|
-
};
|
|
1237
|
-
this.ampEntity = { regex: /&(amp|#38|#x26);/g, val: "&" };
|
|
1238
|
-
this.htmlEntities = {
|
|
1239
|
-
"space": { regex: /&(nbsp|#160);/g, val: " " },
|
|
1240
|
-
// "lt" : { regex: /&(lt|#60);/g, val: "<" },
|
|
1241
|
-
// "gt" : { regex: /&(gt|#62);/g, val: ">" },
|
|
1242
|
-
// "amp" : { regex: /&(amp|#38);/g, val: "&" },
|
|
1243
|
-
// "quot" : { regex: /&(quot|#34);/g, val: "\"" },
|
|
1244
|
-
// "apos" : { regex: /&(apos|#39);/g, val: "'" },
|
|
1245
|
-
"cent": { regex: /&(cent|#162);/g, val: "¢" },
|
|
1246
|
-
"pound": { regex: /&(pound|#163);/g, val: "£" },
|
|
1247
|
-
"yen": { regex: /&(yen|#165);/g, val: "¥" },
|
|
1248
|
-
"euro": { regex: /&(euro|#8364);/g, val: "€" },
|
|
1249
|
-
"copyright": { regex: /&(copy|#169);/g, val: "©" },
|
|
1250
|
-
"reg": { regex: /&(reg|#174);/g, val: "®" },
|
|
1251
|
-
"inr": { regex: /&(inr|#8377);/g, val: "₹" },
|
|
1252
|
-
"num_dec": { regex: /&#([0-9]{1,7});/g, val: (_, str) => String.fromCharCode(Number.parseInt(str, 10)) },
|
|
1253
|
-
"num_hex": { regex: /&#x([0-9a-fA-F]{1,6});/g, val: (_, str) => String.fromCharCode(Number.parseInt(str, 16)) }
|
|
1254
|
-
};
|
|
1255
|
-
this.addExternalEntities = addExternalEntities;
|
|
1256
|
-
this.parseXml = parseXml;
|
|
1257
|
-
this.parseTextData = parseTextData;
|
|
1258
|
-
this.resolveNameSpace = resolveNameSpace;
|
|
1259
|
-
this.buildAttributesMap = buildAttributesMap;
|
|
1260
|
-
this.isItStopNode = isItStopNode;
|
|
1261
|
-
this.replaceEntitiesValue = replaceEntitiesValue$1;
|
|
1262
|
-
this.readStopNodeData = readStopNodeData;
|
|
1263
|
-
this.saveTextToParentTag = saveTextToParentTag;
|
|
1264
|
-
this.addChild = addChild;
|
|
1265
|
-
this.ignoreAttributesFn = getIgnoreAttributesFn$1(this.options.ignoreAttributes);
|
|
1137
|
+
function isElement(xmlData, i) {
|
|
1138
|
+
if (xmlData[i + 1] === "!" && xmlData[i + 2] === "E" && xmlData[i + 3] === "L" && xmlData[i + 4] === "E" && xmlData[i + 5] === "M" && xmlData[i + 6] === "E" && xmlData[i + 7] === "N" && xmlData[i + 8] === "T") return true;
|
|
1139
|
+
return false;
|
|
1266
1140
|
}
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
for (let i = 0; i < entKeys.length; i++) {
|
|
1271
|
-
const ent = entKeys[i];
|
|
1272
|
-
this.lastEntities[ent] = {
|
|
1273
|
-
regex: new RegExp("&" + ent + ";", "g"),
|
|
1274
|
-
val: externalEntities[ent]
|
|
1275
|
-
};
|
|
1141
|
+
function isAttlist(xmlData, i) {
|
|
1142
|
+
if (xmlData[i + 1] === "!" && xmlData[i + 2] === "A" && xmlData[i + 3] === "T" && xmlData[i + 4] === "T" && xmlData[i + 5] === "L" && xmlData[i + 6] === "I" && xmlData[i + 7] === "S" && xmlData[i + 8] === "T") return true;
|
|
1143
|
+
return false;
|
|
1276
1144
|
}
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1145
|
+
function isNotation(xmlData, i) {
|
|
1146
|
+
if (xmlData[i + 1] === "!" && xmlData[i + 2] === "N" && xmlData[i + 3] === "O" && xmlData[i + 4] === "T" && xmlData[i + 5] === "A" && xmlData[i + 6] === "T" && xmlData[i + 7] === "I" && xmlData[i + 8] === "O" && xmlData[i + 9] === "N") return true;
|
|
1147
|
+
return false;
|
|
1148
|
+
}
|
|
1149
|
+
function validateEntityName(name) {
|
|
1150
|
+
if (util2.isName(name))
|
|
1151
|
+
return name;
|
|
1152
|
+
else
|
|
1153
|
+
throw new Error(`Invalid entity name ${name}`);
|
|
1154
|
+
}
|
|
1155
|
+
DocTypeReader = readDocType;
|
|
1156
|
+
return DocTypeReader;
|
|
1157
|
+
}
|
|
1158
|
+
var strnum;
|
|
1159
|
+
var hasRequiredStrnum;
|
|
1160
|
+
function requireStrnum() {
|
|
1161
|
+
if (hasRequiredStrnum) return strnum;
|
|
1162
|
+
hasRequiredStrnum = 1;
|
|
1163
|
+
const hexRegex = /^[-+]?0x[a-fA-F0-9]+$/;
|
|
1164
|
+
const numRegex = /^([\-\+])?(0*)(\.[0-9]+([eE]\-?[0-9]+)?|[0-9]+(\.[0-9]+([eE]\-?[0-9]+)?)?)$/;
|
|
1165
|
+
if (!Number.parseInt && window.parseInt) {
|
|
1166
|
+
Number.parseInt = window.parseInt;
|
|
1167
|
+
}
|
|
1168
|
+
if (!Number.parseFloat && window.parseFloat) {
|
|
1169
|
+
Number.parseFloat = window.parseFloat;
|
|
1170
|
+
}
|
|
1171
|
+
const consider = {
|
|
1172
|
+
hex: true,
|
|
1173
|
+
leadingZeros: true,
|
|
1174
|
+
decimalPoint: ".",
|
|
1175
|
+
eNotation: true
|
|
1176
|
+
//skipLike: /regex/
|
|
1177
|
+
};
|
|
1178
|
+
function toNumber(str, options = {}) {
|
|
1179
|
+
options = Object.assign({}, consider, options);
|
|
1180
|
+
if (!str || typeof str !== "string") return str;
|
|
1181
|
+
let trimmedStr = str.trim();
|
|
1182
|
+
if (options.skipLike !== void 0 && options.skipLike.test(trimmedStr)) return str;
|
|
1183
|
+
else if (options.hex && hexRegex.test(trimmedStr)) {
|
|
1184
|
+
return Number.parseInt(trimmedStr, 16);
|
|
1185
|
+
} else {
|
|
1186
|
+
const match = numRegex.exec(trimmedStr);
|
|
1187
|
+
if (match) {
|
|
1188
|
+
const sign = match[1];
|
|
1189
|
+
const leadingZeros = match[2];
|
|
1190
|
+
let numTrimmedByZeros = trimZeros(match[3]);
|
|
1191
|
+
const eNotation = match[4] || match[6];
|
|
1192
|
+
if (!options.leadingZeros && leadingZeros.length > 0 && sign && trimmedStr[2] !== ".") return str;
|
|
1193
|
+
else if (!options.leadingZeros && leadingZeros.length > 0 && !sign && trimmedStr[1] !== ".") return str;
|
|
1194
|
+
else {
|
|
1195
|
+
const num = Number(trimmedStr);
|
|
1196
|
+
const numStr = "" + num;
|
|
1197
|
+
if (numStr.search(/[eE]/) !== -1) {
|
|
1198
|
+
if (options.eNotation) return num;
|
|
1199
|
+
else return str;
|
|
1200
|
+
} else if (eNotation) {
|
|
1201
|
+
if (options.eNotation) return num;
|
|
1202
|
+
else return str;
|
|
1203
|
+
} else if (trimmedStr.indexOf(".") !== -1) {
|
|
1204
|
+
if (numStr === "0" && numTrimmedByZeros === "") return num;
|
|
1205
|
+
else if (numStr === numTrimmedByZeros) return num;
|
|
1206
|
+
else if (sign && numStr === "-" + numTrimmedByZeros) return num;
|
|
1207
|
+
else return str;
|
|
1208
|
+
}
|
|
1209
|
+
if (leadingZeros) {
|
|
1210
|
+
if (numTrimmedByZeros === numStr) return num;
|
|
1211
|
+
else if (sign + numTrimmedByZeros === numStr) return num;
|
|
1212
|
+
else return str;
|
|
1213
|
+
}
|
|
1214
|
+
if (trimmedStr === numStr) return num;
|
|
1215
|
+
else if (trimmedStr === sign + numStr) return num;
|
|
1216
|
+
return str;
|
|
1298
1217
|
}
|
|
1218
|
+
} else {
|
|
1219
|
+
return str;
|
|
1299
1220
|
}
|
|
1300
1221
|
}
|
|
1301
1222
|
}
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
return
|
|
1223
|
+
function trimZeros(numStr) {
|
|
1224
|
+
if (numStr && numStr.indexOf(".") !== -1) {
|
|
1225
|
+
numStr = numStr.replace(/0+$/, "");
|
|
1226
|
+
if (numStr === ".") numStr = "0";
|
|
1227
|
+
else if (numStr[0] === ".") numStr = "0" + numStr;
|
|
1228
|
+
else if (numStr[numStr.length - 1] === ".") numStr = numStr.substr(0, numStr.length - 1);
|
|
1229
|
+
return numStr;
|
|
1230
|
+
}
|
|
1231
|
+
return numStr;
|
|
1232
|
+
}
|
|
1233
|
+
strnum = toNumber;
|
|
1234
|
+
return strnum;
|
|
1235
|
+
}
|
|
1236
|
+
var ignoreAttributes;
|
|
1237
|
+
var hasRequiredIgnoreAttributes;
|
|
1238
|
+
function requireIgnoreAttributes() {
|
|
1239
|
+
if (hasRequiredIgnoreAttributes) return ignoreAttributes;
|
|
1240
|
+
hasRequiredIgnoreAttributes = 1;
|
|
1241
|
+
function getIgnoreAttributesFn(ignoreAttributes2) {
|
|
1242
|
+
if (typeof ignoreAttributes2 === "function") {
|
|
1243
|
+
return ignoreAttributes2;
|
|
1244
|
+
}
|
|
1245
|
+
if (Array.isArray(ignoreAttributes2)) {
|
|
1246
|
+
return (attrName) => {
|
|
1247
|
+
for (const pattern of ignoreAttributes2) {
|
|
1248
|
+
if (typeof pattern === "string" && attrName === pattern) {
|
|
1249
|
+
return true;
|
|
1250
|
+
}
|
|
1251
|
+
if (pattern instanceof RegExp && pattern.test(attrName)) {
|
|
1252
|
+
return true;
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
};
|
|
1309
1256
|
}
|
|
1310
|
-
|
|
1311
|
-
|
|
1257
|
+
return () => false;
|
|
1258
|
+
}
|
|
1259
|
+
ignoreAttributes = getIgnoreAttributesFn;
|
|
1260
|
+
return ignoreAttributes;
|
|
1261
|
+
}
|
|
1262
|
+
var OrderedObjParser_1;
|
|
1263
|
+
var hasRequiredOrderedObjParser;
|
|
1264
|
+
function requireOrderedObjParser() {
|
|
1265
|
+
if (hasRequiredOrderedObjParser) return OrderedObjParser_1;
|
|
1266
|
+
hasRequiredOrderedObjParser = 1;
|
|
1267
|
+
const util2 = requireUtil();
|
|
1268
|
+
const xmlNode2 = requireXmlNode();
|
|
1269
|
+
const readDocType = requireDocTypeReader();
|
|
1270
|
+
const toNumber = requireStrnum();
|
|
1271
|
+
const getIgnoreAttributesFn = requireIgnoreAttributes();
|
|
1272
|
+
class OrderedObjParser {
|
|
1273
|
+
constructor(options) {
|
|
1274
|
+
this.options = options;
|
|
1275
|
+
this.currentNode = null;
|
|
1276
|
+
this.tagsNodeStack = [];
|
|
1277
|
+
this.docTypeEntities = {};
|
|
1278
|
+
this.lastEntities = {
|
|
1279
|
+
"apos": { regex: /&(apos|#39|#x27);/g, val: "'" },
|
|
1280
|
+
"gt": { regex: /&(gt|#62|#x3E);/g, val: ">" },
|
|
1281
|
+
"lt": { regex: /&(lt|#60|#x3C);/g, val: "<" },
|
|
1282
|
+
"quot": { regex: /&(quot|#34|#x22);/g, val: '"' }
|
|
1283
|
+
};
|
|
1284
|
+
this.ampEntity = { regex: /&(amp|#38|#x26);/g, val: "&" };
|
|
1285
|
+
this.htmlEntities = {
|
|
1286
|
+
"space": { regex: /&(nbsp|#160);/g, val: " " },
|
|
1287
|
+
// "lt" : { regex: /&(lt|#60);/g, val: "<" },
|
|
1288
|
+
// "gt" : { regex: /&(gt|#62);/g, val: ">" },
|
|
1289
|
+
// "amp" : { regex: /&(amp|#38);/g, val: "&" },
|
|
1290
|
+
// "quot" : { regex: /&(quot|#34);/g, val: "\"" },
|
|
1291
|
+
// "apos" : { regex: /&(apos|#39);/g, val: "'" },
|
|
1292
|
+
"cent": { regex: /&(cent|#162);/g, val: "¢" },
|
|
1293
|
+
"pound": { regex: /&(pound|#163);/g, val: "£" },
|
|
1294
|
+
"yen": { regex: /&(yen|#165);/g, val: "¥" },
|
|
1295
|
+
"euro": { regex: /&(euro|#8364);/g, val: "€" },
|
|
1296
|
+
"copyright": { regex: /&(copy|#169);/g, val: "©" },
|
|
1297
|
+
"reg": { regex: /&(reg|#174);/g, val: "®" },
|
|
1298
|
+
"inr": { regex: /&(inr|#8377);/g, val: "₹" },
|
|
1299
|
+
"num_dec": { regex: /&#([0-9]{1,7});/g, val: (_, str) => String.fromCharCode(Number.parseInt(str, 10)) },
|
|
1300
|
+
"num_hex": { regex: /&#x([0-9a-fA-F]{1,6});/g, val: (_, str) => String.fromCharCode(Number.parseInt(str, 16)) }
|
|
1301
|
+
};
|
|
1302
|
+
this.addExternalEntities = addExternalEntities;
|
|
1303
|
+
this.parseXml = parseXml;
|
|
1304
|
+
this.parseTextData = parseTextData;
|
|
1305
|
+
this.resolveNameSpace = resolveNameSpace;
|
|
1306
|
+
this.buildAttributesMap = buildAttributesMap;
|
|
1307
|
+
this.isItStopNode = isItStopNode;
|
|
1308
|
+
this.replaceEntitiesValue = replaceEntitiesValue;
|
|
1309
|
+
this.readStopNodeData = readStopNodeData;
|
|
1310
|
+
this.saveTextToParentTag = saveTextToParentTag;
|
|
1311
|
+
this.addChild = addChild;
|
|
1312
|
+
this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes);
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
function addExternalEntities(externalEntities) {
|
|
1316
|
+
const entKeys = Object.keys(externalEntities);
|
|
1317
|
+
for (let i = 0; i < entKeys.length; i++) {
|
|
1318
|
+
const ent = entKeys[i];
|
|
1319
|
+
this.lastEntities[ent] = {
|
|
1320
|
+
regex: new RegExp("&" + ent + ";", "g"),
|
|
1321
|
+
val: externalEntities[ent]
|
|
1322
|
+
};
|
|
1312
1323
|
}
|
|
1313
1324
|
}
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
if (this.options.ignoreAttributes !== true && typeof attrStr === "string") {
|
|
1319
|
-
const matches = util.getAllMatches(attrStr, attrsRegx);
|
|
1320
|
-
const len = matches.length;
|
|
1321
|
-
const attrs = {};
|
|
1322
|
-
for (let i = 0; i < len; i++) {
|
|
1323
|
-
const attrName = this.resolveNameSpace(matches[i][1]);
|
|
1324
|
-
if (this.ignoreAttributesFn(attrName, jPath)) {
|
|
1325
|
-
continue;
|
|
1325
|
+
function parseTextData(val, tagName, jPath, dontTrim, hasAttributes, isLeafNode, escapeEntities) {
|
|
1326
|
+
if (val !== void 0) {
|
|
1327
|
+
if (this.options.trimValues && !dontTrim) {
|
|
1328
|
+
val = val.trim();
|
|
1326
1329
|
}
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
if (
|
|
1331
|
-
|
|
1332
|
-
}
|
|
1333
|
-
|
|
1334
|
-
if (
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
if (newVal === null || newVal === void 0) {
|
|
1341
|
-
attrs[aName] = oldVal;
|
|
1342
|
-
} else if (typeof newVal !== typeof oldVal || newVal !== oldVal) {
|
|
1343
|
-
attrs[aName] = newVal;
|
|
1330
|
+
if (val.length > 0) {
|
|
1331
|
+
if (!escapeEntities) val = this.replaceEntitiesValue(val);
|
|
1332
|
+
const newval = this.options.tagValueProcessor(tagName, val, jPath, hasAttributes, isLeafNode);
|
|
1333
|
+
if (newval === null || newval === void 0) {
|
|
1334
|
+
return val;
|
|
1335
|
+
} else if (typeof newval !== typeof val || newval !== val) {
|
|
1336
|
+
return newval;
|
|
1337
|
+
} else if (this.options.trimValues) {
|
|
1338
|
+
return parseValue(val, this.options.parseTagValue, this.options.numberParseOptions);
|
|
1339
|
+
} else {
|
|
1340
|
+
const trimmedVal = val.trim();
|
|
1341
|
+
if (trimmedVal === val) {
|
|
1342
|
+
return parseValue(val, this.options.parseTagValue, this.options.numberParseOptions);
|
|
1344
1343
|
} else {
|
|
1345
|
-
|
|
1346
|
-
oldVal,
|
|
1347
|
-
this.options.parseAttributeValue,
|
|
1348
|
-
this.options.numberParseOptions
|
|
1349
|
-
);
|
|
1344
|
+
return val;
|
|
1350
1345
|
}
|
|
1351
|
-
} else if (this.options.allowBooleanAttributes) {
|
|
1352
|
-
attrs[aName] = true;
|
|
1353
1346
|
}
|
|
1354
1347
|
}
|
|
1355
1348
|
}
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
const
|
|
1361
|
-
|
|
1362
|
-
|
|
1349
|
+
}
|
|
1350
|
+
function resolveNameSpace(tagname) {
|
|
1351
|
+
if (this.options.removeNSPrefix) {
|
|
1352
|
+
const tags = tagname.split(":");
|
|
1353
|
+
const prefix = tagname.charAt(0) === "/" ? "/" : "";
|
|
1354
|
+
if (tags[0] === "xmlns") {
|
|
1355
|
+
return "";
|
|
1356
|
+
}
|
|
1357
|
+
if (tags.length === 2) {
|
|
1358
|
+
tagname = prefix + tags[1];
|
|
1359
|
+
}
|
|
1363
1360
|
}
|
|
1364
|
-
return
|
|
1361
|
+
return tagname;
|
|
1365
1362
|
}
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
if (xmlData[i + 1] === "/") {
|
|
1377
|
-
const closeIndex = findClosingIndex(xmlData, ">", i, "Closing Tag is not closed.");
|
|
1378
|
-
let tagName = xmlData.substring(i + 2, closeIndex).trim();
|
|
1379
|
-
if (this.options.removeNSPrefix) {
|
|
1380
|
-
const colonIndex = tagName.indexOf(":");
|
|
1381
|
-
if (colonIndex !== -1) {
|
|
1382
|
-
tagName = tagName.substr(colonIndex + 1);
|
|
1383
|
-
}
|
|
1384
|
-
}
|
|
1385
|
-
if (this.options.transformTagName) {
|
|
1386
|
-
tagName = this.options.transformTagName(tagName);
|
|
1387
|
-
}
|
|
1388
|
-
if (currentNode) {
|
|
1389
|
-
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
1390
|
-
}
|
|
1391
|
-
const lastTagName = jPath.substring(jPath.lastIndexOf(".") + 1);
|
|
1392
|
-
if (tagName && this.options.unpairedTags.indexOf(tagName) !== -1) {
|
|
1393
|
-
throw new Error(`Unpaired tag can not be used as closing tag: </${tagName}>`);
|
|
1394
|
-
}
|
|
1395
|
-
let propIndex = 0;
|
|
1396
|
-
if (lastTagName && this.options.unpairedTags.indexOf(lastTagName) !== -1) {
|
|
1397
|
-
propIndex = jPath.lastIndexOf(".", jPath.lastIndexOf(".") - 1);
|
|
1398
|
-
this.tagsNodeStack.pop();
|
|
1399
|
-
} else {
|
|
1400
|
-
propIndex = jPath.lastIndexOf(".");
|
|
1363
|
+
const attrsRegx = new RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`, "gm");
|
|
1364
|
+
function buildAttributesMap(attrStr, jPath, tagName) {
|
|
1365
|
+
if (this.options.ignoreAttributes !== true && typeof attrStr === "string") {
|
|
1366
|
+
const matches = util2.getAllMatches(attrStr, attrsRegx);
|
|
1367
|
+
const len = matches.length;
|
|
1368
|
+
const attrs = {};
|
|
1369
|
+
for (let i = 0; i < len; i++) {
|
|
1370
|
+
const attrName = this.resolveNameSpace(matches[i][1]);
|
|
1371
|
+
if (this.ignoreAttributesFn(attrName, jPath)) {
|
|
1372
|
+
continue;
|
|
1401
1373
|
}
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1374
|
+
let oldVal = matches[i][4];
|
|
1375
|
+
let aName = this.options.attributeNamePrefix + attrName;
|
|
1376
|
+
if (attrName.length) {
|
|
1377
|
+
if (this.options.transformAttributeName) {
|
|
1378
|
+
aName = this.options.transformAttributeName(aName);
|
|
1379
|
+
}
|
|
1380
|
+
if (aName === "__proto__") aName = "#__proto__";
|
|
1381
|
+
if (oldVal !== void 0) {
|
|
1382
|
+
if (this.options.trimValues) {
|
|
1383
|
+
oldVal = oldVal.trim();
|
|
1384
|
+
}
|
|
1385
|
+
oldVal = this.replaceEntitiesValue(oldVal);
|
|
1386
|
+
const newVal = this.options.attributeValueProcessor(attrName, oldVal, jPath);
|
|
1387
|
+
if (newVal === null || newVal === void 0) {
|
|
1388
|
+
attrs[aName] = oldVal;
|
|
1389
|
+
} else if (typeof newVal !== typeof oldVal || newVal !== oldVal) {
|
|
1390
|
+
attrs[aName] = newVal;
|
|
1391
|
+
} else {
|
|
1392
|
+
attrs[aName] = parseValue(
|
|
1393
|
+
oldVal,
|
|
1394
|
+
this.options.parseAttributeValue,
|
|
1395
|
+
this.options.numberParseOptions
|
|
1396
|
+
);
|
|
1397
|
+
}
|
|
1398
|
+
} else if (this.options.allowBooleanAttributes) {
|
|
1399
|
+
attrs[aName] = true;
|
|
1416
1400
|
}
|
|
1417
|
-
this.addChild(currentNode, childNode, jPath);
|
|
1418
|
-
}
|
|
1419
|
-
i = tagData.closeIndex + 1;
|
|
1420
|
-
} else if (xmlData.substr(i + 1, 3) === "!--") {
|
|
1421
|
-
const endIndex = findClosingIndex(xmlData, "-->", i + 4, "Comment is not closed.");
|
|
1422
|
-
if (this.options.commentPropName) {
|
|
1423
|
-
const comment = xmlData.substring(i + 4, endIndex - 2);
|
|
1424
|
-
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
1425
|
-
currentNode.add(this.options.commentPropName, [{ [this.options.textNodeName]: comment }]);
|
|
1426
1401
|
}
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
textData = this.saveTextToParentTag(textData, currentNode, jPath, false);
|
|
1402
|
+
}
|
|
1403
|
+
if (!Object.keys(attrs).length) {
|
|
1404
|
+
return;
|
|
1405
|
+
}
|
|
1406
|
+
if (this.options.attributesGroupName) {
|
|
1407
|
+
const attrCollection = {};
|
|
1408
|
+
attrCollection[this.options.attributesGroupName] = attrs;
|
|
1409
|
+
return attrCollection;
|
|
1410
|
+
}
|
|
1411
|
+
return attrs;
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
const parseXml = function(xmlData) {
|
|
1415
|
+
xmlData = xmlData.replace(/\r\n?/g, "\n");
|
|
1416
|
+
const xmlObj = new xmlNode2("!xml");
|
|
1417
|
+
let currentNode = xmlObj;
|
|
1418
|
+
let textData = "";
|
|
1419
|
+
let jPath = "";
|
|
1420
|
+
for (let i = 0; i < xmlData.length; i++) {
|
|
1421
|
+
const ch = xmlData[i];
|
|
1422
|
+
if (ch === "<") {
|
|
1423
|
+
if (xmlData[i + 1] === "/") {
|
|
1424
|
+
const closeIndex = findClosingIndex(xmlData, ">", i, "Closing Tag is not closed.");
|
|
1425
|
+
let tagName = xmlData.substring(i + 2, closeIndex).trim();
|
|
1426
|
+
if (this.options.removeNSPrefix) {
|
|
1427
|
+
const colonIndex = tagName.indexOf(":");
|
|
1428
|
+
if (colonIndex !== -1) {
|
|
1429
|
+
tagName = tagName.substr(colonIndex + 1);
|
|
1430
|
+
}
|
|
1457
1431
|
}
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1432
|
+
if (this.options.transformTagName) {
|
|
1433
|
+
tagName = this.options.transformTagName(tagName);
|
|
1434
|
+
}
|
|
1435
|
+
if (currentNode) {
|
|
1436
|
+
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
1437
|
+
}
|
|
1438
|
+
const lastTagName = jPath.substring(jPath.lastIndexOf(".") + 1);
|
|
1439
|
+
if (tagName && this.options.unpairedTags.indexOf(tagName) !== -1) {
|
|
1440
|
+
throw new Error(`Unpaired tag can not be used as closing tag: </${tagName}>`);
|
|
1441
|
+
}
|
|
1442
|
+
let propIndex = 0;
|
|
1443
|
+
if (lastTagName && this.options.unpairedTags.indexOf(lastTagName) !== -1) {
|
|
1444
|
+
propIndex = jPath.lastIndexOf(".", jPath.lastIndexOf(".") - 1);
|
|
1445
|
+
this.tagsNodeStack.pop();
|
|
1446
|
+
} else {
|
|
1447
|
+
propIndex = jPath.lastIndexOf(".");
|
|
1448
|
+
}
|
|
1449
|
+
jPath = jPath.substring(0, propIndex);
|
|
1461
1450
|
currentNode = this.tagsNodeStack.pop();
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
if (
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
} else {
|
|
1475
|
-
tagExp = tagExp.substr(0, tagExp.length - 1);
|
|
1451
|
+
textData = "";
|
|
1452
|
+
i = closeIndex;
|
|
1453
|
+
} else if (xmlData[i + 1] === "?") {
|
|
1454
|
+
let tagData = readTagExp(xmlData, i, false, "?>");
|
|
1455
|
+
if (!tagData) throw new Error("Pi Tag is not closed.");
|
|
1456
|
+
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
1457
|
+
if (this.options.ignoreDeclaration && tagData.tagName === "?xml" || this.options.ignorePiTags) ;
|
|
1458
|
+
else {
|
|
1459
|
+
const childNode = new xmlNode2(tagData.tagName);
|
|
1460
|
+
childNode.add(this.options.textNodeName, "");
|
|
1461
|
+
if (tagData.tagName !== tagData.tagExp && tagData.attrExpPresent) {
|
|
1462
|
+
childNode[":@"] = this.buildAttributesMap(tagData.tagExp, jPath, tagData.tagName);
|
|
1476
1463
|
}
|
|
1477
|
-
|
|
1478
|
-
} else if (this.options.unpairedTags.indexOf(tagName) !== -1) {
|
|
1479
|
-
i = result.closeIndex;
|
|
1480
|
-
} else {
|
|
1481
|
-
const result2 = this.readStopNodeData(xmlData, rawTagName, closeIndex + 1);
|
|
1482
|
-
if (!result2) throw new Error(`Unexpected end of ${rawTagName}`);
|
|
1483
|
-
i = result2.i;
|
|
1484
|
-
tagContent = result2.tagContent;
|
|
1464
|
+
this.addChild(currentNode, childNode, jPath);
|
|
1485
1465
|
}
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1466
|
+
i = tagData.closeIndex + 1;
|
|
1467
|
+
} else if (xmlData.substr(i + 1, 3) === "!--") {
|
|
1468
|
+
const endIndex = findClosingIndex(xmlData, "-->", i + 4, "Comment is not closed.");
|
|
1469
|
+
if (this.options.commentPropName) {
|
|
1470
|
+
const comment = xmlData.substring(i + 4, endIndex - 2);
|
|
1471
|
+
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
1472
|
+
currentNode.add(this.options.commentPropName, [{ [this.options.textNodeName]: comment }]);
|
|
1489
1473
|
}
|
|
1490
|
-
|
|
1491
|
-
|
|
1474
|
+
i = endIndex;
|
|
1475
|
+
} else if (xmlData.substr(i + 1, 2) === "!D") {
|
|
1476
|
+
const result = readDocType(xmlData, i);
|
|
1477
|
+
this.docTypeEntities = result.entities;
|
|
1478
|
+
i = result.i;
|
|
1479
|
+
} else if (xmlData.substr(i + 1, 2) === "![") {
|
|
1480
|
+
const closeIndex = findClosingIndex(xmlData, "]]>", i, "CDATA is not closed.") - 2;
|
|
1481
|
+
const tagExp = xmlData.substring(i + 9, closeIndex);
|
|
1482
|
+
textData = this.saveTextToParentTag(textData, currentNode, jPath);
|
|
1483
|
+
let val = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true, true);
|
|
1484
|
+
if (val == void 0) val = "";
|
|
1485
|
+
if (this.options.cdataPropName) {
|
|
1486
|
+
currentNode.add(this.options.cdataPropName, [{ [this.options.textNodeName]: tagExp }]);
|
|
1487
|
+
} else {
|
|
1488
|
+
currentNode.add(this.options.textNodeName, val);
|
|
1492
1489
|
}
|
|
1493
|
-
|
|
1494
|
-
childNode.add(this.options.textNodeName, tagContent);
|
|
1495
|
-
this.addChild(currentNode, childNode, jPath);
|
|
1490
|
+
i = closeIndex + 2;
|
|
1496
1491
|
} else {
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1492
|
+
let result = readTagExp(xmlData, i, this.options.removeNSPrefix);
|
|
1493
|
+
let tagName = result.tagName;
|
|
1494
|
+
const rawTagName = result.rawTagName;
|
|
1495
|
+
let tagExp = result.tagExp;
|
|
1496
|
+
let attrExpPresent = result.attrExpPresent;
|
|
1497
|
+
let closeIndex = result.closeIndex;
|
|
1498
|
+
if (this.options.transformTagName) {
|
|
1499
|
+
tagName = this.options.transformTagName(tagName);
|
|
1500
|
+
}
|
|
1501
|
+
if (currentNode && textData) {
|
|
1502
|
+
if (currentNode.tagname !== "!xml") {
|
|
1503
|
+
textData = this.saveTextToParentTag(textData, currentNode, jPath, false);
|
|
1504
1504
|
}
|
|
1505
|
-
|
|
1506
|
-
|
|
1505
|
+
}
|
|
1506
|
+
const lastTag = currentNode;
|
|
1507
|
+
if (lastTag && this.options.unpairedTags.indexOf(lastTag.tagname) !== -1) {
|
|
1508
|
+
currentNode = this.tagsNodeStack.pop();
|
|
1509
|
+
jPath = jPath.substring(0, jPath.lastIndexOf("."));
|
|
1510
|
+
}
|
|
1511
|
+
if (tagName !== xmlObj.tagname) {
|
|
1512
|
+
jPath += jPath ? "." + tagName : tagName;
|
|
1513
|
+
}
|
|
1514
|
+
if (this.isItStopNode(this.options.stopNodes, jPath, tagName)) {
|
|
1515
|
+
let tagContent = "";
|
|
1516
|
+
if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) {
|
|
1517
|
+
if (tagName[tagName.length - 1] === "/") {
|
|
1518
|
+
tagName = tagName.substr(0, tagName.length - 1);
|
|
1519
|
+
jPath = jPath.substr(0, jPath.length - 1);
|
|
1520
|
+
tagExp = tagName;
|
|
1521
|
+
} else {
|
|
1522
|
+
tagExp = tagExp.substr(0, tagExp.length - 1);
|
|
1523
|
+
}
|
|
1524
|
+
i = result.closeIndex;
|
|
1525
|
+
} else if (this.options.unpairedTags.indexOf(tagName) !== -1) {
|
|
1526
|
+
i = result.closeIndex;
|
|
1527
|
+
} else {
|
|
1528
|
+
const result2 = this.readStopNodeData(xmlData, rawTagName, closeIndex + 1);
|
|
1529
|
+
if (!result2) throw new Error(`Unexpected end of ${rawTagName}`);
|
|
1530
|
+
i = result2.i;
|
|
1531
|
+
tagContent = result2.tagContent;
|
|
1507
1532
|
}
|
|
1508
|
-
const childNode = new
|
|
1533
|
+
const childNode = new xmlNode2(tagName);
|
|
1509
1534
|
if (tagName !== tagExp && attrExpPresent) {
|
|
1510
1535
|
childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
|
|
1511
1536
|
}
|
|
1512
|
-
|
|
1537
|
+
if (tagContent) {
|
|
1538
|
+
tagContent = this.parseTextData(tagContent, tagName, jPath, true, attrExpPresent, true, true);
|
|
1539
|
+
}
|
|
1513
1540
|
jPath = jPath.substr(0, jPath.lastIndexOf("."));
|
|
1541
|
+
childNode.add(this.options.textNodeName, tagContent);
|
|
1542
|
+
this.addChild(currentNode, childNode, jPath);
|
|
1514
1543
|
} else {
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1544
|
+
if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) {
|
|
1545
|
+
if (tagName[tagName.length - 1] === "/") {
|
|
1546
|
+
tagName = tagName.substr(0, tagName.length - 1);
|
|
1547
|
+
jPath = jPath.substr(0, jPath.length - 1);
|
|
1548
|
+
tagExp = tagName;
|
|
1549
|
+
} else {
|
|
1550
|
+
tagExp = tagExp.substr(0, tagExp.length - 1);
|
|
1551
|
+
}
|
|
1552
|
+
if (this.options.transformTagName) {
|
|
1553
|
+
tagName = this.options.transformTagName(tagName);
|
|
1554
|
+
}
|
|
1555
|
+
const childNode = new xmlNode2(tagName);
|
|
1556
|
+
if (tagName !== tagExp && attrExpPresent) {
|
|
1557
|
+
childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
|
|
1558
|
+
}
|
|
1559
|
+
this.addChild(currentNode, childNode, jPath);
|
|
1560
|
+
jPath = jPath.substr(0, jPath.lastIndexOf("."));
|
|
1561
|
+
} else {
|
|
1562
|
+
const childNode = new xmlNode2(tagName);
|
|
1563
|
+
this.tagsNodeStack.push(currentNode);
|
|
1564
|
+
if (tagName !== tagExp && attrExpPresent) {
|
|
1565
|
+
childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
|
|
1566
|
+
}
|
|
1567
|
+
this.addChild(currentNode, childNode, jPath);
|
|
1568
|
+
currentNode = childNode;
|
|
1519
1569
|
}
|
|
1520
|
-
|
|
1521
|
-
|
|
1570
|
+
textData = "";
|
|
1571
|
+
i = closeIndex;
|
|
1522
1572
|
}
|
|
1523
|
-
textData = "";
|
|
1524
|
-
i = closeIndex;
|
|
1525
1573
|
}
|
|
1574
|
+
} else {
|
|
1575
|
+
textData += xmlData[i];
|
|
1526
1576
|
}
|
|
1577
|
+
}
|
|
1578
|
+
return xmlObj.child;
|
|
1579
|
+
};
|
|
1580
|
+
function addChild(currentNode, childNode, jPath) {
|
|
1581
|
+
const result = this.options.updateTag(childNode.tagname, jPath, childNode[":@"]);
|
|
1582
|
+
if (result === false) ;
|
|
1583
|
+
else if (typeof result === "string") {
|
|
1584
|
+
childNode.tagname = result;
|
|
1585
|
+
currentNode.addChild(childNode);
|
|
1527
1586
|
} else {
|
|
1528
|
-
|
|
1587
|
+
currentNode.addChild(childNode);
|
|
1529
1588
|
}
|
|
1530
1589
|
}
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
currentNode.addChild(childNode);
|
|
1541
|
-
}
|
|
1542
|
-
}
|
|
1543
|
-
const replaceEntitiesValue$1 = function(val2) {
|
|
1544
|
-
if (this.options.processEntities) {
|
|
1545
|
-
for (let entityName2 in this.docTypeEntities) {
|
|
1546
|
-
const entity = this.docTypeEntities[entityName2];
|
|
1547
|
-
val2 = val2.replace(entity.regx, entity.val);
|
|
1548
|
-
}
|
|
1549
|
-
for (let entityName2 in this.lastEntities) {
|
|
1550
|
-
const entity = this.lastEntities[entityName2];
|
|
1551
|
-
val2 = val2.replace(entity.regex, entity.val);
|
|
1552
|
-
}
|
|
1553
|
-
if (this.options.htmlEntities) {
|
|
1554
|
-
for (let entityName2 in this.htmlEntities) {
|
|
1555
|
-
const entity = this.htmlEntities[entityName2];
|
|
1556
|
-
val2 = val2.replace(entity.regex, entity.val);
|
|
1590
|
+
const replaceEntitiesValue = function(val) {
|
|
1591
|
+
if (this.options.processEntities) {
|
|
1592
|
+
for (let entityName in this.docTypeEntities) {
|
|
1593
|
+
const entity = this.docTypeEntities[entityName];
|
|
1594
|
+
val = val.replace(entity.regx, entity.val);
|
|
1595
|
+
}
|
|
1596
|
+
for (let entityName in this.lastEntities) {
|
|
1597
|
+
const entity = this.lastEntities[entityName];
|
|
1598
|
+
val = val.replace(entity.regex, entity.val);
|
|
1557
1599
|
}
|
|
1600
|
+
if (this.options.htmlEntities) {
|
|
1601
|
+
for (let entityName in this.htmlEntities) {
|
|
1602
|
+
const entity = this.htmlEntities[entityName];
|
|
1603
|
+
val = val.replace(entity.regex, entity.val);
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
val = val.replace(this.ampEntity.regex, this.ampEntity.val);
|
|
1558
1607
|
}
|
|
1559
|
-
|
|
1560
|
-
}
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
textData
|
|
1608
|
+
return val;
|
|
1609
|
+
};
|
|
1610
|
+
function saveTextToParentTag(textData, currentNode, jPath, isLeafNode) {
|
|
1611
|
+
if (textData) {
|
|
1612
|
+
if (isLeafNode === void 0) isLeafNode = Object.keys(currentNode.child).length === 0;
|
|
1613
|
+
textData = this.parseTextData(
|
|
1614
|
+
textData,
|
|
1615
|
+
currentNode.tagname,
|
|
1616
|
+
jPath,
|
|
1617
|
+
false,
|
|
1618
|
+
currentNode[":@"] ? Object.keys(currentNode[":@"]).length !== 0 : false,
|
|
1619
|
+
isLeafNode
|
|
1620
|
+
);
|
|
1621
|
+
if (textData !== void 0 && textData !== "")
|
|
1622
|
+
currentNode.add(this.options.textNodeName, textData);
|
|
1623
|
+
textData = "";
|
|
1624
|
+
}
|
|
1625
|
+
return textData;
|
|
1577
1626
|
}
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1627
|
+
function isItStopNode(stopNodes, jPath, currentTagName) {
|
|
1628
|
+
const allNodesExp = "*." + currentTagName;
|
|
1629
|
+
for (const stopNodePath in stopNodes) {
|
|
1630
|
+
const stopNodeExp = stopNodes[stopNodePath];
|
|
1631
|
+
if (allNodesExp === stopNodeExp || jPath === stopNodeExp) return true;
|
|
1632
|
+
}
|
|
1633
|
+
return false;
|
|
1585
1634
|
}
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1635
|
+
function tagExpWithClosingIndex(xmlData, i, closingChar = ">") {
|
|
1636
|
+
let attrBoundary;
|
|
1637
|
+
let tagExp = "";
|
|
1638
|
+
for (let index = i; index < xmlData.length; index++) {
|
|
1639
|
+
let ch = xmlData[index];
|
|
1640
|
+
if (attrBoundary) {
|
|
1641
|
+
if (ch === attrBoundary) attrBoundary = "";
|
|
1642
|
+
} else if (ch === '"' || ch === "'") {
|
|
1643
|
+
attrBoundary = ch;
|
|
1644
|
+
} else if (ch === closingChar[0]) {
|
|
1645
|
+
if (closingChar[1]) {
|
|
1646
|
+
if (xmlData[index + 1] === closingChar[1]) {
|
|
1647
|
+
return {
|
|
1648
|
+
data: tagExp,
|
|
1649
|
+
index
|
|
1650
|
+
};
|
|
1651
|
+
}
|
|
1652
|
+
} else {
|
|
1600
1653
|
return {
|
|
1601
1654
|
data: tagExp,
|
|
1602
1655
|
index
|
|
1603
1656
|
};
|
|
1604
1657
|
}
|
|
1605
|
-
} else {
|
|
1606
|
-
|
|
1607
|
-
data: tagExp,
|
|
1608
|
-
index
|
|
1609
|
-
};
|
|
1658
|
+
} else if (ch === " ") {
|
|
1659
|
+
ch = " ";
|
|
1610
1660
|
}
|
|
1611
|
-
|
|
1612
|
-
ch = " ";
|
|
1661
|
+
tagExp += ch;
|
|
1613
1662
|
}
|
|
1614
|
-
tagExp += ch;
|
|
1615
1663
|
}
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1664
|
+
function findClosingIndex(xmlData, str, i, errMsg) {
|
|
1665
|
+
const closingIndex = xmlData.indexOf(str, i);
|
|
1666
|
+
if (closingIndex === -1) {
|
|
1667
|
+
throw new Error(errMsg);
|
|
1668
|
+
} else {
|
|
1669
|
+
return closingIndex + str.length - 1;
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
function readTagExp(xmlData, i, removeNSPrefix, closingChar = ">") {
|
|
1673
|
+
const result = tagExpWithClosingIndex(xmlData, i + 1, closingChar);
|
|
1674
|
+
if (!result) return;
|
|
1675
|
+
let tagExp = result.data;
|
|
1676
|
+
const closeIndex = result.index;
|
|
1677
|
+
const separatorIndex = tagExp.search(/\s/);
|
|
1678
|
+
let tagName = tagExp;
|
|
1679
|
+
let attrExpPresent = true;
|
|
1680
|
+
if (separatorIndex !== -1) {
|
|
1681
|
+
tagName = tagExp.substring(0, separatorIndex);
|
|
1682
|
+
tagExp = tagExp.substring(separatorIndex + 1).trimStart();
|
|
1683
|
+
}
|
|
1684
|
+
const rawTagName = tagName;
|
|
1685
|
+
if (removeNSPrefix) {
|
|
1686
|
+
const colonIndex = tagName.indexOf(":");
|
|
1687
|
+
if (colonIndex !== -1) {
|
|
1688
|
+
tagName = tagName.substr(colonIndex + 1);
|
|
1689
|
+
attrExpPresent = tagName !== result.data.substr(colonIndex + 1);
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
return {
|
|
1693
|
+
tagName,
|
|
1694
|
+
tagExp,
|
|
1695
|
+
closeIndex,
|
|
1696
|
+
attrExpPresent,
|
|
1697
|
+
rawTagName
|
|
1698
|
+
};
|
|
1623
1699
|
}
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
if (colonIndex !== -1) {
|
|
1641
|
-
tagName = tagName.substr(colonIndex + 1);
|
|
1642
|
-
attrExpPresent = tagName !== result.data.substr(colonIndex + 1);
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
return {
|
|
1646
|
-
tagName,
|
|
1647
|
-
tagExp,
|
|
1648
|
-
closeIndex,
|
|
1649
|
-
attrExpPresent,
|
|
1650
|
-
rawTagName
|
|
1651
|
-
};
|
|
1652
|
-
}
|
|
1653
|
-
function readStopNodeData(xmlData, tagName, i) {
|
|
1654
|
-
const startIndex = i;
|
|
1655
|
-
let openTagCount = 1;
|
|
1656
|
-
for (; i < xmlData.length; i++) {
|
|
1657
|
-
if (xmlData[i] === "<") {
|
|
1658
|
-
if (xmlData[i + 1] === "/") {
|
|
1659
|
-
const closeIndex = findClosingIndex(xmlData, ">", i, `${tagName} is not closed`);
|
|
1660
|
-
let closeTagName = xmlData.substring(i + 2, closeIndex).trim();
|
|
1661
|
-
if (closeTagName === tagName) {
|
|
1662
|
-
openTagCount--;
|
|
1663
|
-
if (openTagCount === 0) {
|
|
1664
|
-
return {
|
|
1665
|
-
tagContent: xmlData.substring(startIndex, i),
|
|
1666
|
-
i: closeIndex
|
|
1667
|
-
};
|
|
1700
|
+
function readStopNodeData(xmlData, tagName, i) {
|
|
1701
|
+
const startIndex = i;
|
|
1702
|
+
let openTagCount = 1;
|
|
1703
|
+
for (; i < xmlData.length; i++) {
|
|
1704
|
+
if (xmlData[i] === "<") {
|
|
1705
|
+
if (xmlData[i + 1] === "/") {
|
|
1706
|
+
const closeIndex = findClosingIndex(xmlData, ">", i, `${tagName} is not closed`);
|
|
1707
|
+
let closeTagName = xmlData.substring(i + 2, closeIndex).trim();
|
|
1708
|
+
if (closeTagName === tagName) {
|
|
1709
|
+
openTagCount--;
|
|
1710
|
+
if (openTagCount === 0) {
|
|
1711
|
+
return {
|
|
1712
|
+
tagContent: xmlData.substring(startIndex, i),
|
|
1713
|
+
i: closeIndex
|
|
1714
|
+
};
|
|
1715
|
+
}
|
|
1668
1716
|
}
|
|
1669
|
-
|
|
1670
|
-
i
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
i
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
i
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1717
|
+
i = closeIndex;
|
|
1718
|
+
} else if (xmlData[i + 1] === "?") {
|
|
1719
|
+
const closeIndex = findClosingIndex(xmlData, "?>", i + 1, "StopNode is not closed.");
|
|
1720
|
+
i = closeIndex;
|
|
1721
|
+
} else if (xmlData.substr(i + 1, 3) === "!--") {
|
|
1722
|
+
const closeIndex = findClosingIndex(xmlData, "-->", i + 3, "StopNode is not closed.");
|
|
1723
|
+
i = closeIndex;
|
|
1724
|
+
} else if (xmlData.substr(i + 1, 2) === "![") {
|
|
1725
|
+
const closeIndex = findClosingIndex(xmlData, "]]>", i, "StopNode is not closed.") - 2;
|
|
1726
|
+
i = closeIndex;
|
|
1727
|
+
} else {
|
|
1728
|
+
const tagData = readTagExp(xmlData, i, ">");
|
|
1729
|
+
if (tagData) {
|
|
1730
|
+
const openTagName = tagData && tagData.tagName;
|
|
1731
|
+
if (openTagName === tagName && tagData.tagExp[tagData.tagExp.length - 1] !== "/") {
|
|
1732
|
+
openTagCount++;
|
|
1733
|
+
}
|
|
1734
|
+
i = tagData.closeIndex;
|
|
1686
1735
|
}
|
|
1687
|
-
i = tagData.closeIndex;
|
|
1688
1736
|
}
|
|
1689
1737
|
}
|
|
1690
1738
|
}
|
|
1691
1739
|
}
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
else return toNumber(val2, options);
|
|
1699
|
-
} else {
|
|
1700
|
-
if (util.isExist(val2)) {
|
|
1701
|
-
return val2;
|
|
1740
|
+
function parseValue(val, shouldParse, options) {
|
|
1741
|
+
if (shouldParse && typeof val === "string") {
|
|
1742
|
+
const newval = val.trim();
|
|
1743
|
+
if (newval === "true") return true;
|
|
1744
|
+
else if (newval === "false") return false;
|
|
1745
|
+
else return toNumber(val, options);
|
|
1702
1746
|
} else {
|
|
1703
|
-
|
|
1747
|
+
if (util2.isExist(val)) {
|
|
1748
|
+
return val;
|
|
1749
|
+
} else {
|
|
1750
|
+
return "";
|
|
1751
|
+
}
|
|
1704
1752
|
}
|
|
1705
1753
|
}
|
|
1754
|
+
OrderedObjParser_1 = OrderedObjParser;
|
|
1755
|
+
return OrderedObjParser_1;
|
|
1706
1756
|
}
|
|
1707
|
-
var OrderedObjParser_1 = OrderedObjParser$1;
|
|
1708
1757
|
var node2json = {};
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
else
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1758
|
+
var hasRequiredNode2json;
|
|
1759
|
+
function requireNode2json() {
|
|
1760
|
+
if (hasRequiredNode2json) return node2json;
|
|
1761
|
+
hasRequiredNode2json = 1;
|
|
1762
|
+
function prettify(node, options) {
|
|
1763
|
+
return compress(node, options);
|
|
1764
|
+
}
|
|
1765
|
+
function compress(arr, options, jPath) {
|
|
1766
|
+
let text;
|
|
1767
|
+
const compressedObj = {};
|
|
1768
|
+
for (let i = 0; i < arr.length; i++) {
|
|
1769
|
+
const tagObj = arr[i];
|
|
1770
|
+
const property = propName(tagObj);
|
|
1771
|
+
let newJpath = "";
|
|
1772
|
+
if (jPath === void 0) newJpath = property;
|
|
1773
|
+
else newJpath = jPath + "." + property;
|
|
1774
|
+
if (property === options.textNodeName) {
|
|
1775
|
+
if (text === void 0) text = tagObj[property];
|
|
1776
|
+
else text += "" + tagObj[property];
|
|
1777
|
+
} else if (property === void 0) {
|
|
1778
|
+
continue;
|
|
1779
|
+
} else if (tagObj[property]) {
|
|
1780
|
+
let val = compress(tagObj[property], options, newJpath);
|
|
1781
|
+
const isLeaf = isLeafTag(val, options);
|
|
1782
|
+
if (tagObj[":@"]) {
|
|
1783
|
+
assignAttributes(val, tagObj[":@"], newJpath, options);
|
|
1784
|
+
} else if (Object.keys(val).length === 1 && val[options.textNodeName] !== void 0 && !options.alwaysCreateTextNode) {
|
|
1785
|
+
val = val[options.textNodeName];
|
|
1786
|
+
} else if (Object.keys(val).length === 0) {
|
|
1787
|
+
if (options.alwaysCreateTextNode) val[options.textNodeName] = "";
|
|
1788
|
+
else val = "";
|
|
1740
1789
|
}
|
|
1741
|
-
compressedObj[property].
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1790
|
+
if (compressedObj[property] !== void 0 && compressedObj.hasOwnProperty(property)) {
|
|
1791
|
+
if (!Array.isArray(compressedObj[property])) {
|
|
1792
|
+
compressedObj[property] = [compressedObj[property]];
|
|
1793
|
+
}
|
|
1794
|
+
compressedObj[property].push(val);
|
|
1745
1795
|
} else {
|
|
1746
|
-
|
|
1796
|
+
if (options.isArray(property, newJpath, isLeaf)) {
|
|
1797
|
+
compressedObj[property] = [val];
|
|
1798
|
+
} else {
|
|
1799
|
+
compressedObj[property] = val;
|
|
1800
|
+
}
|
|
1747
1801
|
}
|
|
1748
1802
|
}
|
|
1749
1803
|
}
|
|
1804
|
+
if (typeof text === "string") {
|
|
1805
|
+
if (text.length > 0) compressedObj[options.textNodeName] = text;
|
|
1806
|
+
} else if (text !== void 0) compressedObj[options.textNodeName] = text;
|
|
1807
|
+
return compressedObj;
|
|
1750
1808
|
}
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
function propName$1(obj) {
|
|
1757
|
-
const keys = Object.keys(obj);
|
|
1758
|
-
for (let i = 0; i < keys.length; i++) {
|
|
1759
|
-
const key = keys[i];
|
|
1760
|
-
if (key !== ":@") return key;
|
|
1761
|
-
}
|
|
1762
|
-
}
|
|
1763
|
-
function assignAttributes(obj, attrMap, jpath, options) {
|
|
1764
|
-
if (attrMap) {
|
|
1765
|
-
const keys = Object.keys(attrMap);
|
|
1766
|
-
const len = keys.length;
|
|
1767
|
-
for (let i = 0; i < len; i++) {
|
|
1768
|
-
const atrrName = keys[i];
|
|
1769
|
-
if (options.isArray(atrrName, jpath + "." + atrrName, true, true)) {
|
|
1770
|
-
obj[atrrName] = [attrMap[atrrName]];
|
|
1771
|
-
} else {
|
|
1772
|
-
obj[atrrName] = attrMap[atrrName];
|
|
1773
|
-
}
|
|
1809
|
+
function propName(obj) {
|
|
1810
|
+
const keys = Object.keys(obj);
|
|
1811
|
+
for (let i = 0; i < keys.length; i++) {
|
|
1812
|
+
const key = keys[i];
|
|
1813
|
+
if (key !== ":@") return key;
|
|
1774
1814
|
}
|
|
1775
1815
|
}
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
}
|
|
1788
|
-
node2json.prettify = prettify$1;
|
|
1789
|
-
const { buildOptions } = OptionsBuilder;
|
|
1790
|
-
const OrderedObjParser2 = OrderedObjParser_1;
|
|
1791
|
-
const { prettify } = node2json;
|
|
1792
|
-
const validator$1 = validator$2;
|
|
1793
|
-
let XMLParser$1 = class XMLParser {
|
|
1794
|
-
constructor(options) {
|
|
1795
|
-
this.externalEntities = {};
|
|
1796
|
-
this.options = buildOptions(options);
|
|
1797
|
-
}
|
|
1798
|
-
/**
|
|
1799
|
-
* Parse XML dats to JS object
|
|
1800
|
-
* @param {string|Buffer} xmlData
|
|
1801
|
-
* @param {boolean|Object} validationOption
|
|
1802
|
-
*/
|
|
1803
|
-
parse(xmlData, validationOption) {
|
|
1804
|
-
if (typeof xmlData === "string") ;
|
|
1805
|
-
else if (xmlData.toString) {
|
|
1806
|
-
xmlData = xmlData.toString();
|
|
1807
|
-
} else {
|
|
1808
|
-
throw new Error("XML data is accepted in String or Bytes[] form.");
|
|
1809
|
-
}
|
|
1810
|
-
if (validationOption) {
|
|
1811
|
-
if (validationOption === true) validationOption = {};
|
|
1812
|
-
const result = validator$1.validate(xmlData, validationOption);
|
|
1813
|
-
if (result !== true) {
|
|
1814
|
-
throw Error(`${result.err.msg}:${result.err.line}:${result.err.col}`);
|
|
1816
|
+
function assignAttributes(obj, attrMap, jpath, options) {
|
|
1817
|
+
if (attrMap) {
|
|
1818
|
+
const keys = Object.keys(attrMap);
|
|
1819
|
+
const len = keys.length;
|
|
1820
|
+
for (let i = 0; i < len; i++) {
|
|
1821
|
+
const atrrName = keys[i];
|
|
1822
|
+
if (options.isArray(atrrName, jpath + "." + atrrName, true, true)) {
|
|
1823
|
+
obj[atrrName] = [attrMap[atrrName]];
|
|
1824
|
+
} else {
|
|
1825
|
+
obj[atrrName] = attrMap[atrrName];
|
|
1826
|
+
}
|
|
1815
1827
|
}
|
|
1816
1828
|
}
|
|
1817
|
-
const orderedObjParser = new OrderedObjParser2(this.options);
|
|
1818
|
-
orderedObjParser.addExternalEntities(this.externalEntities);
|
|
1819
|
-
const orderedResult = orderedObjParser.parseXml(xmlData);
|
|
1820
|
-
if (this.options.preserveOrder || orderedResult === void 0) return orderedResult;
|
|
1821
|
-
else return prettify(orderedResult, this.options);
|
|
1822
1829
|
}
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
if (
|
|
1830
|
-
|
|
1831
|
-
} else if (key.indexOf("&") !== -1 || key.indexOf(";") !== -1) {
|
|
1832
|
-
throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '
'");
|
|
1833
|
-
} else if (value === "&") {
|
|
1834
|
-
throw new Error("An entity with value '&' is not permitted");
|
|
1835
|
-
} else {
|
|
1836
|
-
this.externalEntities[key] = value;
|
|
1830
|
+
function isLeafTag(obj, options) {
|
|
1831
|
+
const { textNodeName } = options;
|
|
1832
|
+
const propCount = Object.keys(obj).length;
|
|
1833
|
+
if (propCount === 0) {
|
|
1834
|
+
return true;
|
|
1835
|
+
}
|
|
1836
|
+
if (propCount === 1 && (obj[textNodeName] || typeof obj[textNodeName] === "boolean" || obj[textNodeName] === 0)) {
|
|
1837
|
+
return true;
|
|
1837
1838
|
}
|
|
1839
|
+
return false;
|
|
1838
1840
|
}
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
if (isPreviousElementTag) {
|
|
1866
|
-
xmlStr += indentation;
|
|
1867
|
-
}
|
|
1868
|
-
xmlStr += tagText;
|
|
1869
|
-
isPreviousElementTag = false;
|
|
1870
|
-
continue;
|
|
1871
|
-
} else if (tagName === options.cdataPropName) {
|
|
1872
|
-
if (isPreviousElementTag) {
|
|
1873
|
-
xmlStr += indentation;
|
|
1874
|
-
}
|
|
1875
|
-
xmlStr += `<![CDATA[${tagObj[tagName][0][options.textNodeName]}]]>`;
|
|
1876
|
-
isPreviousElementTag = false;
|
|
1877
|
-
continue;
|
|
1878
|
-
} else if (tagName === options.commentPropName) {
|
|
1879
|
-
xmlStr += indentation + `<!--${tagObj[tagName][0][options.textNodeName]}-->`;
|
|
1880
|
-
isPreviousElementTag = true;
|
|
1881
|
-
continue;
|
|
1882
|
-
} else if (tagName[0] === "?") {
|
|
1883
|
-
const attStr2 = attr_to_str(tagObj[":@"], options);
|
|
1884
|
-
const tempInd = tagName === "?xml" ? "" : indentation;
|
|
1885
|
-
let piTextNodeName = tagObj[tagName][0][options.textNodeName];
|
|
1886
|
-
piTextNodeName = piTextNodeName.length !== 0 ? " " + piTextNodeName : "";
|
|
1887
|
-
xmlStr += tempInd + `<${tagName}${piTextNodeName}${attStr2}?>`;
|
|
1888
|
-
isPreviousElementTag = true;
|
|
1889
|
-
continue;
|
|
1890
|
-
}
|
|
1891
|
-
let newIdentation = indentation;
|
|
1892
|
-
if (newIdentation !== "") {
|
|
1893
|
-
newIdentation += options.indentBy;
|
|
1894
|
-
}
|
|
1895
|
-
const attStr = attr_to_str(tagObj[":@"], options);
|
|
1896
|
-
const tagStart = indentation + `<${tagName}${attStr}`;
|
|
1897
|
-
const tagValue = arrToStr(tagObj[tagName], options, newJPath, newIdentation);
|
|
1898
|
-
if (options.unpairedTags.indexOf(tagName) !== -1) {
|
|
1899
|
-
if (options.suppressUnpairedNode) xmlStr += tagStart + ">";
|
|
1900
|
-
else xmlStr += tagStart + "/>";
|
|
1901
|
-
} else if ((!tagValue || tagValue.length === 0) && options.suppressEmptyNode) {
|
|
1902
|
-
xmlStr += tagStart + "/>";
|
|
1903
|
-
} else if (tagValue && tagValue.endsWith(">")) {
|
|
1904
|
-
xmlStr += tagStart + `>${tagValue}${indentation}</${tagName}>`;
|
|
1905
|
-
} else {
|
|
1906
|
-
xmlStr += tagStart + ">";
|
|
1907
|
-
if (tagValue && indentation !== "" && (tagValue.includes("/>") || tagValue.includes("</"))) {
|
|
1908
|
-
xmlStr += indentation + options.indentBy + tagValue + indentation;
|
|
1841
|
+
node2json.prettify = prettify;
|
|
1842
|
+
return node2json;
|
|
1843
|
+
}
|
|
1844
|
+
var XMLParser_1;
|
|
1845
|
+
var hasRequiredXMLParser;
|
|
1846
|
+
function requireXMLParser() {
|
|
1847
|
+
if (hasRequiredXMLParser) return XMLParser_1;
|
|
1848
|
+
hasRequiredXMLParser = 1;
|
|
1849
|
+
const { buildOptions } = requireOptionsBuilder();
|
|
1850
|
+
const OrderedObjParser = requireOrderedObjParser();
|
|
1851
|
+
const { prettify } = requireNode2json();
|
|
1852
|
+
const validator2 = requireValidator();
|
|
1853
|
+
class XMLParser {
|
|
1854
|
+
constructor(options) {
|
|
1855
|
+
this.externalEntities = {};
|
|
1856
|
+
this.options = buildOptions(options);
|
|
1857
|
+
}
|
|
1858
|
+
/**
|
|
1859
|
+
* Parse XML dats to JS object
|
|
1860
|
+
* @param {string|Buffer} xmlData
|
|
1861
|
+
* @param {boolean|Object} validationOption
|
|
1862
|
+
*/
|
|
1863
|
+
parse(xmlData, validationOption) {
|
|
1864
|
+
if (typeof xmlData === "string") ;
|
|
1865
|
+
else if (xmlData.toString) {
|
|
1866
|
+
xmlData = xmlData.toString();
|
|
1909
1867
|
} else {
|
|
1910
|
-
|
|
1868
|
+
throw new Error("XML data is accepted in String or Bytes[] form.");
|
|
1869
|
+
}
|
|
1870
|
+
if (validationOption) {
|
|
1871
|
+
if (validationOption === true) validationOption = {};
|
|
1872
|
+
const result = validator2.validate(xmlData, validationOption);
|
|
1873
|
+
if (result !== true) {
|
|
1874
|
+
throw Error(`${result.err.msg}:${result.err.line}:${result.err.col}`);
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
const orderedObjParser = new OrderedObjParser(this.options);
|
|
1878
|
+
orderedObjParser.addExternalEntities(this.externalEntities);
|
|
1879
|
+
const orderedResult = orderedObjParser.parseXml(xmlData);
|
|
1880
|
+
if (this.options.preserveOrder || orderedResult === void 0) return orderedResult;
|
|
1881
|
+
else return prettify(orderedResult, this.options);
|
|
1882
|
+
}
|
|
1883
|
+
/**
|
|
1884
|
+
* Add Entity which is not by default supported by this library
|
|
1885
|
+
* @param {string} key
|
|
1886
|
+
* @param {string} value
|
|
1887
|
+
*/
|
|
1888
|
+
addEntity(key, value) {
|
|
1889
|
+
if (value.indexOf("&") !== -1) {
|
|
1890
|
+
throw new Error("Entity value can't have '&'");
|
|
1891
|
+
} else if (key.indexOf("&") !== -1 || key.indexOf(";") !== -1) {
|
|
1892
|
+
throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '
'");
|
|
1893
|
+
} else if (value === "&") {
|
|
1894
|
+
throw new Error("An entity with value '&' is not permitted");
|
|
1895
|
+
} else {
|
|
1896
|
+
this.externalEntities[key] = value;
|
|
1911
1897
|
}
|
|
1912
|
-
xmlStr += `</${tagName}>`;
|
|
1913
1898
|
}
|
|
1914
|
-
isPreviousElementTag = true;
|
|
1915
|
-
}
|
|
1916
|
-
return xmlStr;
|
|
1917
|
-
}
|
|
1918
|
-
function propName(obj) {
|
|
1919
|
-
const keys = Object.keys(obj);
|
|
1920
|
-
for (let i = 0; i < keys.length; i++) {
|
|
1921
|
-
const key = keys[i];
|
|
1922
|
-
if (!obj.hasOwnProperty(key)) continue;
|
|
1923
|
-
if (key !== ":@") return key;
|
|
1924
1899
|
}
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1900
|
+
XMLParser_1 = XMLParser;
|
|
1901
|
+
return XMLParser_1;
|
|
1902
|
+
}
|
|
1903
|
+
var orderedJs2Xml;
|
|
1904
|
+
var hasRequiredOrderedJs2Xml;
|
|
1905
|
+
function requireOrderedJs2Xml() {
|
|
1906
|
+
if (hasRequiredOrderedJs2Xml) return orderedJs2Xml;
|
|
1907
|
+
hasRequiredOrderedJs2Xml = 1;
|
|
1908
|
+
const EOL = "\n";
|
|
1909
|
+
function toXml(jArray, options) {
|
|
1910
|
+
let indentation = "";
|
|
1911
|
+
if (options.format && options.indentBy.length > 0) {
|
|
1912
|
+
indentation = EOL;
|
|
1913
|
+
}
|
|
1914
|
+
return arrToStr(jArray, options, "", indentation);
|
|
1915
|
+
}
|
|
1916
|
+
function arrToStr(arr, options, jPath, indentation) {
|
|
1917
|
+
let xmlStr = "";
|
|
1918
|
+
let isPreviousElementTag = false;
|
|
1919
|
+
for (let i = 0; i < arr.length; i++) {
|
|
1920
|
+
const tagObj = arr[i];
|
|
1921
|
+
const tagName = propName(tagObj);
|
|
1922
|
+
if (tagName === void 0) continue;
|
|
1923
|
+
let newJPath = "";
|
|
1924
|
+
if (jPath.length === 0) newJPath = tagName;
|
|
1925
|
+
else newJPath = `${jPath}.${tagName}`;
|
|
1926
|
+
if (tagName === options.textNodeName) {
|
|
1927
|
+
let tagText = tagObj[tagName];
|
|
1928
|
+
if (!isStopNode(newJPath, options)) {
|
|
1929
|
+
tagText = options.tagValueProcessor(tagName, tagText);
|
|
1930
|
+
tagText = replaceEntitiesValue(tagText, options);
|
|
1931
|
+
}
|
|
1932
|
+
if (isPreviousElementTag) {
|
|
1933
|
+
xmlStr += indentation;
|
|
1934
|
+
}
|
|
1935
|
+
xmlStr += tagText;
|
|
1936
|
+
isPreviousElementTag = false;
|
|
1937
|
+
continue;
|
|
1938
|
+
} else if (tagName === options.cdataPropName) {
|
|
1939
|
+
if (isPreviousElementTag) {
|
|
1940
|
+
xmlStr += indentation;
|
|
1941
|
+
}
|
|
1942
|
+
xmlStr += `<![CDATA[${tagObj[tagName][0][options.textNodeName]}]]>`;
|
|
1943
|
+
isPreviousElementTag = false;
|
|
1944
|
+
continue;
|
|
1945
|
+
} else if (tagName === options.commentPropName) {
|
|
1946
|
+
xmlStr += indentation + `<!--${tagObj[tagName][0][options.textNodeName]}-->`;
|
|
1947
|
+
isPreviousElementTag = true;
|
|
1948
|
+
continue;
|
|
1949
|
+
} else if (tagName[0] === "?") {
|
|
1950
|
+
const attStr2 = attr_to_str(tagObj[":@"], options);
|
|
1951
|
+
const tempInd = tagName === "?xml" ? "" : indentation;
|
|
1952
|
+
let piTextNodeName = tagObj[tagName][0][options.textNodeName];
|
|
1953
|
+
piTextNodeName = piTextNodeName.length !== 0 ? " " + piTextNodeName : "";
|
|
1954
|
+
xmlStr += tempInd + `<${tagName}${piTextNodeName}${attStr2}?>`;
|
|
1955
|
+
isPreviousElementTag = true;
|
|
1956
|
+
continue;
|
|
1957
|
+
}
|
|
1958
|
+
let newIdentation = indentation;
|
|
1959
|
+
if (newIdentation !== "") {
|
|
1960
|
+
newIdentation += options.indentBy;
|
|
1961
|
+
}
|
|
1962
|
+
const attStr = attr_to_str(tagObj[":@"], options);
|
|
1963
|
+
const tagStart = indentation + `<${tagName}${attStr}`;
|
|
1964
|
+
const tagValue = arrToStr(tagObj[tagName], options, newJPath, newIdentation);
|
|
1965
|
+
if (options.unpairedTags.indexOf(tagName) !== -1) {
|
|
1966
|
+
if (options.suppressUnpairedNode) xmlStr += tagStart + ">";
|
|
1967
|
+
else xmlStr += tagStart + "/>";
|
|
1968
|
+
} else if ((!tagValue || tagValue.length === 0) && options.suppressEmptyNode) {
|
|
1969
|
+
xmlStr += tagStart + "/>";
|
|
1970
|
+
} else if (tagValue && tagValue.endsWith(">")) {
|
|
1971
|
+
xmlStr += tagStart + `>${tagValue}${indentation}</${tagName}>`;
|
|
1935
1972
|
} else {
|
|
1936
|
-
|
|
1973
|
+
xmlStr += tagStart + ">";
|
|
1974
|
+
if (tagValue && indentation !== "" && (tagValue.includes("/>") || tagValue.includes("</"))) {
|
|
1975
|
+
xmlStr += indentation + options.indentBy + tagValue + indentation;
|
|
1976
|
+
} else {
|
|
1977
|
+
xmlStr += tagValue;
|
|
1978
|
+
}
|
|
1979
|
+
xmlStr += `</${tagName}>`;
|
|
1937
1980
|
}
|
|
1981
|
+
isPreviousElementTag = true;
|
|
1938
1982
|
}
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1983
|
+
return xmlStr;
|
|
1984
|
+
}
|
|
1985
|
+
function propName(obj) {
|
|
1986
|
+
const keys = Object.keys(obj);
|
|
1987
|
+
for (let i = 0; i < keys.length; i++) {
|
|
1988
|
+
const key = keys[i];
|
|
1989
|
+
if (!obj.hasOwnProperty(key)) continue;
|
|
1990
|
+
if (key !== ":@") return key;
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
function attr_to_str(attrMap, options) {
|
|
1994
|
+
let attrStr = "";
|
|
1995
|
+
if (attrMap && !options.ignoreAttributes) {
|
|
1996
|
+
for (let attr in attrMap) {
|
|
1997
|
+
if (!attrMap.hasOwnProperty(attr)) continue;
|
|
1998
|
+
let attrVal = options.attributeValueProcessor(attr, attrMap[attr]);
|
|
1999
|
+
attrVal = replaceEntitiesValue(attrVal, options);
|
|
2000
|
+
if (attrVal === true && options.suppressBooleanAttributes) {
|
|
2001
|
+
attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}`;
|
|
2002
|
+
} else {
|
|
2003
|
+
attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}="${attrVal}"`;
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
1955
2006
|
}
|
|
2007
|
+
return attrStr;
|
|
1956
2008
|
}
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
attributesGroupName: false,
|
|
1965
|
-
textNodeName: "#text",
|
|
1966
|
-
ignoreAttributes: true,
|
|
1967
|
-
cdataPropName: false,
|
|
1968
|
-
format: false,
|
|
1969
|
-
indentBy: " ",
|
|
1970
|
-
suppressEmptyNode: false,
|
|
1971
|
-
suppressUnpairedNode: true,
|
|
1972
|
-
suppressBooleanAttributes: true,
|
|
1973
|
-
tagValueProcessor: function(key, a) {
|
|
1974
|
-
return a;
|
|
1975
|
-
},
|
|
1976
|
-
attributeValueProcessor: function(attrName, a) {
|
|
1977
|
-
return a;
|
|
1978
|
-
},
|
|
1979
|
-
preserveOrder: false,
|
|
1980
|
-
commentPropName: false,
|
|
1981
|
-
unpairedTags: [],
|
|
1982
|
-
entities: [
|
|
1983
|
-
{ regex: new RegExp("&", "g"), val: "&" },
|
|
1984
|
-
//it must be on top
|
|
1985
|
-
{ regex: new RegExp(">", "g"), val: ">" },
|
|
1986
|
-
{ regex: new RegExp("<", "g"), val: "<" },
|
|
1987
|
-
{ regex: new RegExp("'", "g"), val: "'" },
|
|
1988
|
-
{ regex: new RegExp('"', "g"), val: """ }
|
|
1989
|
-
],
|
|
1990
|
-
processEntities: true,
|
|
1991
|
-
stopNodes: [],
|
|
1992
|
-
// transformTagName: false,
|
|
1993
|
-
// transformAttributeName: false,
|
|
1994
|
-
oneListGroup: false
|
|
1995
|
-
};
|
|
1996
|
-
function Builder(options) {
|
|
1997
|
-
this.options = Object.assign({}, defaultOptions, options);
|
|
1998
|
-
if (this.options.ignoreAttributes === true || this.options.attributesGroupName) {
|
|
1999
|
-
this.isAttribute = function() {
|
|
2000
|
-
return false;
|
|
2001
|
-
};
|
|
2002
|
-
} else {
|
|
2003
|
-
this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes);
|
|
2004
|
-
this.attrPrefixLen = this.options.attributeNamePrefix.length;
|
|
2005
|
-
this.isAttribute = isAttribute;
|
|
2006
|
-
}
|
|
2007
|
-
this.processTextOrObjNode = processTextOrObjNode;
|
|
2008
|
-
if (this.options.format) {
|
|
2009
|
-
this.indentate = indentate;
|
|
2010
|
-
this.tagEndChar = ">\n";
|
|
2011
|
-
this.newLine = "\n";
|
|
2012
|
-
} else {
|
|
2013
|
-
this.indentate = function() {
|
|
2014
|
-
return "";
|
|
2015
|
-
};
|
|
2016
|
-
this.tagEndChar = ">";
|
|
2017
|
-
this.newLine = "";
|
|
2009
|
+
function isStopNode(jPath, options) {
|
|
2010
|
+
jPath = jPath.substr(0, jPath.length - options.textNodeName.length - 1);
|
|
2011
|
+
let tagName = jPath.substr(jPath.lastIndexOf(".") + 1);
|
|
2012
|
+
for (let index in options.stopNodes) {
|
|
2013
|
+
if (options.stopNodes[index] === jPath || options.stopNodes[index] === "*." + tagName) return true;
|
|
2014
|
+
}
|
|
2015
|
+
return false;
|
|
2018
2016
|
}
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2017
|
+
function replaceEntitiesValue(textValue, options) {
|
|
2018
|
+
if (textValue && textValue.length > 0 && options.processEntities) {
|
|
2019
|
+
for (let i = 0; i < options.entities.length; i++) {
|
|
2020
|
+
const entity = options.entities[i];
|
|
2021
|
+
textValue = textValue.replace(entity.regex, entity.val);
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
return textValue;
|
|
2025
|
+
}
|
|
2026
|
+
orderedJs2Xml = toXml;
|
|
2027
|
+
return orderedJs2Xml;
|
|
2028
|
+
}
|
|
2029
|
+
var json2xml;
|
|
2030
|
+
var hasRequiredJson2xml;
|
|
2031
|
+
function requireJson2xml() {
|
|
2032
|
+
if (hasRequiredJson2xml) return json2xml;
|
|
2033
|
+
hasRequiredJson2xml = 1;
|
|
2034
|
+
const buildFromOrderedJs = requireOrderedJs2Xml();
|
|
2035
|
+
const getIgnoreAttributesFn = requireIgnoreAttributes();
|
|
2036
|
+
const defaultOptions = {
|
|
2037
|
+
attributeNamePrefix: "@_",
|
|
2038
|
+
attributesGroupName: false,
|
|
2039
|
+
textNodeName: "#text",
|
|
2040
|
+
ignoreAttributes: true,
|
|
2041
|
+
cdataPropName: false,
|
|
2042
|
+
format: false,
|
|
2043
|
+
indentBy: " ",
|
|
2044
|
+
suppressEmptyNode: false,
|
|
2045
|
+
suppressUnpairedNode: true,
|
|
2046
|
+
suppressBooleanAttributes: true,
|
|
2047
|
+
tagValueProcessor: function(key, a) {
|
|
2048
|
+
return a;
|
|
2049
|
+
},
|
|
2050
|
+
attributeValueProcessor: function(attrName, a) {
|
|
2051
|
+
return a;
|
|
2052
|
+
},
|
|
2053
|
+
preserveOrder: false,
|
|
2054
|
+
commentPropName: false,
|
|
2055
|
+
unpairedTags: [],
|
|
2056
|
+
entities: [
|
|
2057
|
+
{ regex: new RegExp("&", "g"), val: "&" },
|
|
2058
|
+
//it must be on top
|
|
2059
|
+
{ regex: new RegExp(">", "g"), val: ">" },
|
|
2060
|
+
{ regex: new RegExp("<", "g"), val: "<" },
|
|
2061
|
+
{ regex: new RegExp("'", "g"), val: "'" },
|
|
2062
|
+
{ regex: new RegExp('"', "g"), val: """ }
|
|
2063
|
+
],
|
|
2064
|
+
processEntities: true,
|
|
2065
|
+
stopNodes: [],
|
|
2066
|
+
// transformTagName: false,
|
|
2067
|
+
// transformAttributeName: false,
|
|
2068
|
+
oneListGroup: false
|
|
2069
|
+
};
|
|
2070
|
+
function Builder(options) {
|
|
2071
|
+
this.options = Object.assign({}, defaultOptions, options);
|
|
2072
|
+
if (this.options.ignoreAttributes === true || this.options.attributesGroupName) {
|
|
2073
|
+
this.isAttribute = function() {
|
|
2074
|
+
return false;
|
|
2075
|
+
};
|
|
2076
|
+
} else {
|
|
2077
|
+
this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes);
|
|
2078
|
+
this.attrPrefixLen = this.options.attributeNamePrefix.length;
|
|
2079
|
+
this.isAttribute = isAttribute;
|
|
2080
|
+
}
|
|
2081
|
+
this.processTextOrObjNode = processTextOrObjNode;
|
|
2082
|
+
if (this.options.format) {
|
|
2083
|
+
this.indentate = indentate;
|
|
2084
|
+
this.tagEndChar = ">\n";
|
|
2085
|
+
this.newLine = "\n";
|
|
2086
|
+
} else {
|
|
2087
|
+
this.indentate = function() {
|
|
2088
|
+
return "";
|
|
2027
2089
|
};
|
|
2090
|
+
this.tagEndChar = ">";
|
|
2091
|
+
this.newLine = "";
|
|
2028
2092
|
}
|
|
2029
|
-
return this.j2x(jObj, 0, []).val;
|
|
2030
2093
|
}
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
let newval = this.options.tagValueProcessor(key, "" + jObj[key]);
|
|
2059
|
-
val2 += this.replaceEntitiesValue(newval);
|
|
2094
|
+
Builder.prototype.build = function(jObj) {
|
|
2095
|
+
if (this.options.preserveOrder) {
|
|
2096
|
+
return buildFromOrderedJs(jObj, this.options);
|
|
2097
|
+
} else {
|
|
2098
|
+
if (Array.isArray(jObj) && this.options.arrayNodeName && this.options.arrayNodeName.length > 1) {
|
|
2099
|
+
jObj = {
|
|
2100
|
+
[this.options.arrayNodeName]: jObj
|
|
2101
|
+
};
|
|
2102
|
+
}
|
|
2103
|
+
return this.j2x(jObj, 0, []).val;
|
|
2104
|
+
}
|
|
2105
|
+
};
|
|
2106
|
+
Builder.prototype.j2x = function(jObj, level, ajPath) {
|
|
2107
|
+
let attrStr = "";
|
|
2108
|
+
let val = "";
|
|
2109
|
+
const jPath = ajPath.join(".");
|
|
2110
|
+
for (let key in jObj) {
|
|
2111
|
+
if (!Object.prototype.hasOwnProperty.call(jObj, key)) continue;
|
|
2112
|
+
if (typeof jObj[key] === "undefined") {
|
|
2113
|
+
if (this.isAttribute(key)) {
|
|
2114
|
+
val += "";
|
|
2115
|
+
}
|
|
2116
|
+
} else if (jObj[key] === null) {
|
|
2117
|
+
if (this.isAttribute(key)) {
|
|
2118
|
+
val += "";
|
|
2119
|
+
} else if (key[0] === "?") {
|
|
2120
|
+
val += this.indentate(level) + "<" + key + "?" + this.tagEndChar;
|
|
2060
2121
|
} else {
|
|
2061
|
-
|
|
2122
|
+
val += this.indentate(level) + "<" + key + "/" + this.tagEndChar;
|
|
2062
2123
|
}
|
|
2063
|
-
}
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
else val2 += this.indentate(level) + "<" + key + "/" + this.tagEndChar;
|
|
2074
|
-
} else if (typeof item === "object") {
|
|
2075
|
-
if (this.options.oneListGroup) {
|
|
2076
|
-
const result = this.j2x(item, level + 1, ajPath.concat(key));
|
|
2077
|
-
listTagVal += result.val;
|
|
2078
|
-
if (this.options.attributesGroupName && item.hasOwnProperty(this.options.attributesGroupName)) {
|
|
2079
|
-
listTagAttr += result.attrStr;
|
|
2080
|
-
}
|
|
2124
|
+
} else if (jObj[key] instanceof Date) {
|
|
2125
|
+
val += this.buildTextValNode(jObj[key], key, "", level);
|
|
2126
|
+
} else if (typeof jObj[key] !== "object") {
|
|
2127
|
+
const attr = this.isAttribute(key);
|
|
2128
|
+
if (attr && !this.ignoreAttributesFn(attr, jPath)) {
|
|
2129
|
+
attrStr += this.buildAttrPairStr(attr, "" + jObj[key]);
|
|
2130
|
+
} else if (!attr) {
|
|
2131
|
+
if (key === this.options.textNodeName) {
|
|
2132
|
+
let newval = this.options.tagValueProcessor(key, "" + jObj[key]);
|
|
2133
|
+
val += this.replaceEntitiesValue(newval);
|
|
2081
2134
|
} else {
|
|
2082
|
-
|
|
2135
|
+
val += this.buildTextValNode(jObj[key], key, "", level);
|
|
2083
2136
|
}
|
|
2084
|
-
}
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2137
|
+
}
|
|
2138
|
+
} else if (Array.isArray(jObj[key])) {
|
|
2139
|
+
const arrLen = jObj[key].length;
|
|
2140
|
+
let listTagVal = "";
|
|
2141
|
+
let listTagAttr = "";
|
|
2142
|
+
for (let j = 0; j < arrLen; j++) {
|
|
2143
|
+
const item = jObj[key][j];
|
|
2144
|
+
if (typeof item === "undefined") ;
|
|
2145
|
+
else if (item === null) {
|
|
2146
|
+
if (key[0] === "?") val += this.indentate(level) + "<" + key + "?" + this.tagEndChar;
|
|
2147
|
+
else val += this.indentate(level) + "<" + key + "/" + this.tagEndChar;
|
|
2148
|
+
} else if (typeof item === "object") {
|
|
2149
|
+
if (this.options.oneListGroup) {
|
|
2150
|
+
const result = this.j2x(item, level + 1, ajPath.concat(key));
|
|
2151
|
+
listTagVal += result.val;
|
|
2152
|
+
if (this.options.attributesGroupName && item.hasOwnProperty(this.options.attributesGroupName)) {
|
|
2153
|
+
listTagAttr += result.attrStr;
|
|
2154
|
+
}
|
|
2155
|
+
} else {
|
|
2156
|
+
listTagVal += this.processTextOrObjNode(item, key, level, ajPath);
|
|
2157
|
+
}
|
|
2089
2158
|
} else {
|
|
2090
|
-
|
|
2159
|
+
if (this.options.oneListGroup) {
|
|
2160
|
+
let textValue = this.options.tagValueProcessor(key, item);
|
|
2161
|
+
textValue = this.replaceEntitiesValue(textValue);
|
|
2162
|
+
listTagVal += textValue;
|
|
2163
|
+
} else {
|
|
2164
|
+
listTagVal += this.buildTextValNode(item, key, "", level);
|
|
2165
|
+
}
|
|
2091
2166
|
}
|
|
2092
2167
|
}
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
listTagVal = this.buildObjectNode(listTagVal, key, listTagAttr, level);
|
|
2096
|
-
}
|
|
2097
|
-
val2 += listTagVal;
|
|
2098
|
-
} else {
|
|
2099
|
-
if (this.options.attributesGroupName && key === this.options.attributesGroupName) {
|
|
2100
|
-
const Ks = Object.keys(jObj[key]);
|
|
2101
|
-
const L = Ks.length;
|
|
2102
|
-
for (let j = 0; j < L; j++) {
|
|
2103
|
-
attrStr += this.buildAttrPairStr(Ks[j], "" + jObj[key][Ks[j]]);
|
|
2168
|
+
if (this.options.oneListGroup) {
|
|
2169
|
+
listTagVal = this.buildObjectNode(listTagVal, key, listTagAttr, level);
|
|
2104
2170
|
}
|
|
2171
|
+
val += listTagVal;
|
|
2105
2172
|
} else {
|
|
2106
|
-
|
|
2173
|
+
if (this.options.attributesGroupName && key === this.options.attributesGroupName) {
|
|
2174
|
+
const Ks = Object.keys(jObj[key]);
|
|
2175
|
+
const L = Ks.length;
|
|
2176
|
+
for (let j = 0; j < L; j++) {
|
|
2177
|
+
attrStr += this.buildAttrPairStr(Ks[j], "" + jObj[key][Ks[j]]);
|
|
2178
|
+
}
|
|
2179
|
+
} else {
|
|
2180
|
+
val += this.processTextOrObjNode(jObj[key], key, level, ajPath);
|
|
2181
|
+
}
|
|
2107
2182
|
}
|
|
2108
2183
|
}
|
|
2184
|
+
return { attrStr, val };
|
|
2185
|
+
};
|
|
2186
|
+
Builder.prototype.buildAttrPairStr = function(attrName, val) {
|
|
2187
|
+
val = this.options.attributeValueProcessor(attrName, "" + val);
|
|
2188
|
+
val = this.replaceEntitiesValue(val);
|
|
2189
|
+
if (this.options.suppressBooleanAttributes && val === "true") {
|
|
2190
|
+
return " " + attrName;
|
|
2191
|
+
} else return " " + attrName + '="' + val + '"';
|
|
2192
|
+
};
|
|
2193
|
+
function processTextOrObjNode(object, key, level, ajPath) {
|
|
2194
|
+
const result = this.j2x(object, level + 1, ajPath.concat(key));
|
|
2195
|
+
if (object[this.options.textNodeName] !== void 0 && Object.keys(object).length === 1) {
|
|
2196
|
+
return this.buildTextValNode(object[this.options.textNodeName], key, result.attrStr, level);
|
|
2197
|
+
} else {
|
|
2198
|
+
return this.buildObjectNode(result.val, key, result.attrStr, level);
|
|
2199
|
+
}
|
|
2109
2200
|
}
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
}
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
else {
|
|
2131
|
-
return this.indentate(level) + "<" + key + attrStr + this.closeTag(key) + this.tagEndChar;
|
|
2201
|
+
Builder.prototype.buildObjectNode = function(val, key, attrStr, level) {
|
|
2202
|
+
if (val === "") {
|
|
2203
|
+
if (key[0] === "?") return this.indentate(level) + "<" + key + attrStr + "?" + this.tagEndChar;
|
|
2204
|
+
else {
|
|
2205
|
+
return this.indentate(level) + "<" + key + attrStr + this.closeTag(key) + this.tagEndChar;
|
|
2206
|
+
}
|
|
2207
|
+
} else {
|
|
2208
|
+
let tagEndExp = "</" + key + this.tagEndChar;
|
|
2209
|
+
let piClosingChar = "";
|
|
2210
|
+
if (key[0] === "?") {
|
|
2211
|
+
piClosingChar = "?";
|
|
2212
|
+
tagEndExp = "";
|
|
2213
|
+
}
|
|
2214
|
+
if ((attrStr || attrStr === "") && val.indexOf("<") === -1) {
|
|
2215
|
+
return this.indentate(level) + "<" + key + attrStr + piClosingChar + ">" + val + tagEndExp;
|
|
2216
|
+
} else if (this.options.commentPropName !== false && key === this.options.commentPropName && piClosingChar.length === 0) {
|
|
2217
|
+
return this.indentate(level) + `<!--${val}-->` + this.newLine;
|
|
2218
|
+
} else {
|
|
2219
|
+
return this.indentate(level) + "<" + key + attrStr + piClosingChar + this.tagEndChar + val + this.indentate(level) + tagEndExp;
|
|
2220
|
+
}
|
|
2132
2221
|
}
|
|
2133
|
-
}
|
|
2134
|
-
|
|
2135
|
-
let
|
|
2136
|
-
if (key
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
if ((attrStr || attrStr === "") && val2.indexOf("<") === -1) {
|
|
2141
|
-
return this.indentate(level) + "<" + key + attrStr + piClosingChar + ">" + val2 + tagEndExp;
|
|
2142
|
-
} else if (this.options.commentPropName !== false && key === this.options.commentPropName && piClosingChar.length === 0) {
|
|
2143
|
-
return this.indentate(level) + `<!--${val2}-->` + this.newLine;
|
|
2222
|
+
};
|
|
2223
|
+
Builder.prototype.closeTag = function(key) {
|
|
2224
|
+
let closeTag = "";
|
|
2225
|
+
if (this.options.unpairedTags.indexOf(key) !== -1) {
|
|
2226
|
+
if (!this.options.suppressUnpairedNode) closeTag = "/";
|
|
2227
|
+
} else if (this.options.suppressEmptyNode) {
|
|
2228
|
+
closeTag = "/";
|
|
2144
2229
|
} else {
|
|
2145
|
-
|
|
2230
|
+
closeTag = `></${key}`;
|
|
2146
2231
|
}
|
|
2147
|
-
|
|
2148
|
-
};
|
|
2149
|
-
Builder.prototype.
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
if (
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
closeTag = `></${key}`;
|
|
2157
|
-
}
|
|
2158
|
-
return closeTag;
|
|
2159
|
-
};
|
|
2160
|
-
Builder.prototype.buildTextValNode = function(val2, key, attrStr, level) {
|
|
2161
|
-
if (this.options.cdataPropName !== false && key === this.options.cdataPropName) {
|
|
2162
|
-
return this.indentate(level) + `<![CDATA[${val2}]]>` + this.newLine;
|
|
2163
|
-
} else if (this.options.commentPropName !== false && key === this.options.commentPropName) {
|
|
2164
|
-
return this.indentate(level) + `<!--${val2}-->` + this.newLine;
|
|
2165
|
-
} else if (key[0] === "?") {
|
|
2166
|
-
return this.indentate(level) + "<" + key + attrStr + "?" + this.tagEndChar;
|
|
2167
|
-
} else {
|
|
2168
|
-
let textValue = this.options.tagValueProcessor(key, val2);
|
|
2169
|
-
textValue = this.replaceEntitiesValue(textValue);
|
|
2170
|
-
if (textValue === "") {
|
|
2171
|
-
return this.indentate(level) + "<" + key + attrStr + this.closeTag(key) + this.tagEndChar;
|
|
2232
|
+
return closeTag;
|
|
2233
|
+
};
|
|
2234
|
+
Builder.prototype.buildTextValNode = function(val, key, attrStr, level) {
|
|
2235
|
+
if (this.options.cdataPropName !== false && key === this.options.cdataPropName) {
|
|
2236
|
+
return this.indentate(level) + `<![CDATA[${val}]]>` + this.newLine;
|
|
2237
|
+
} else if (this.options.commentPropName !== false && key === this.options.commentPropName) {
|
|
2238
|
+
return this.indentate(level) + `<!--${val}-->` + this.newLine;
|
|
2239
|
+
} else if (key[0] === "?") {
|
|
2240
|
+
return this.indentate(level) + "<" + key + attrStr + "?" + this.tagEndChar;
|
|
2172
2241
|
} else {
|
|
2173
|
-
|
|
2242
|
+
let textValue = this.options.tagValueProcessor(key, val);
|
|
2243
|
+
textValue = this.replaceEntitiesValue(textValue);
|
|
2244
|
+
if (textValue === "") {
|
|
2245
|
+
return this.indentate(level) + "<" + key + attrStr + this.closeTag(key) + this.tagEndChar;
|
|
2246
|
+
} else {
|
|
2247
|
+
return this.indentate(level) + "<" + key + attrStr + ">" + textValue + "</" + key + this.tagEndChar;
|
|
2248
|
+
}
|
|
2174
2249
|
}
|
|
2175
|
-
}
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2250
|
+
};
|
|
2251
|
+
Builder.prototype.replaceEntitiesValue = function(textValue) {
|
|
2252
|
+
if (textValue && textValue.length > 0 && this.options.processEntities) {
|
|
2253
|
+
for (let i = 0; i < this.options.entities.length; i++) {
|
|
2254
|
+
const entity = this.options.entities[i];
|
|
2255
|
+
textValue = textValue.replace(entity.regex, entity.val);
|
|
2256
|
+
}
|
|
2182
2257
|
}
|
|
2258
|
+
return textValue;
|
|
2259
|
+
};
|
|
2260
|
+
function indentate(level) {
|
|
2261
|
+
return this.options.indentBy.repeat(level);
|
|
2183
2262
|
}
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
if (name.startsWith(this.options.attributeNamePrefix) && name !== this.options.textNodeName) {
|
|
2191
|
-
return name.substr(this.attrPrefixLen);
|
|
2192
|
-
} else {
|
|
2193
|
-
return false;
|
|
2263
|
+
function isAttribute(name) {
|
|
2264
|
+
if (name.startsWith(this.options.attributeNamePrefix) && name !== this.options.textNodeName) {
|
|
2265
|
+
return name.substr(this.attrPrefixLen);
|
|
2266
|
+
} else {
|
|
2267
|
+
return false;
|
|
2268
|
+
}
|
|
2194
2269
|
}
|
|
2270
|
+
json2xml = Builder;
|
|
2271
|
+
return json2xml;
|
|
2272
|
+
}
|
|
2273
|
+
var fxp;
|
|
2274
|
+
var hasRequiredFxp;
|
|
2275
|
+
function requireFxp() {
|
|
2276
|
+
if (hasRequiredFxp) return fxp;
|
|
2277
|
+
hasRequiredFxp = 1;
|
|
2278
|
+
const validator2 = requireValidator();
|
|
2279
|
+
const XMLParser = requireXMLParser();
|
|
2280
|
+
const XMLBuilder = requireJson2xml();
|
|
2281
|
+
fxp = {
|
|
2282
|
+
XMLParser,
|
|
2283
|
+
XMLValidator: validator2,
|
|
2284
|
+
XMLBuilder
|
|
2285
|
+
};
|
|
2286
|
+
return fxp;
|
|
2195
2287
|
}
|
|
2196
|
-
var
|
|
2197
|
-
const validator = validator$2;
|
|
2198
|
-
const XMLParser2 = XMLParser_1;
|
|
2199
|
-
const XMLBuilder = json2xml;
|
|
2200
|
-
var fxp = {
|
|
2201
|
-
XMLParser: XMLParser2,
|
|
2202
|
-
XMLValidator: validator,
|
|
2203
|
-
XMLBuilder
|
|
2204
|
-
};
|
|
2288
|
+
var fxpExports = requireFxp();
|
|
2205
2289
|
function isSvg(string) {
|
|
2206
2290
|
if (typeof string !== "string") {
|
|
2207
2291
|
throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
|
|
@@ -2210,11 +2294,11 @@ function isSvg(string) {
|
|
|
2210
2294
|
if (string.length === 0) {
|
|
2211
2295
|
return false;
|
|
2212
2296
|
}
|
|
2213
|
-
if (
|
|
2297
|
+
if (fxpExports.XMLValidator.validate(string) !== true) {
|
|
2214
2298
|
return false;
|
|
2215
2299
|
}
|
|
2216
2300
|
let jsonObject;
|
|
2217
|
-
const parser = new
|
|
2301
|
+
const parser = new fxpExports.XMLParser();
|
|
2218
2302
|
try {
|
|
2219
2303
|
jsonObject = parser.parse(string);
|
|
2220
2304
|
} catch {
|
|
@@ -2341,412 +2425,479 @@ const isValidView = function(view) {
|
|
|
2341
2425
|
}
|
|
2342
2426
|
return true;
|
|
2343
2427
|
};
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
const
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
"
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
(function(module2, exports2) {
|
|
2374
|
-
const {
|
|
2375
|
-
MAX_SAFE_COMPONENT_LENGTH: MAX_SAFE_COMPONENT_LENGTH2,
|
|
2376
|
-
MAX_SAFE_BUILD_LENGTH: MAX_SAFE_BUILD_LENGTH2,
|
|
2377
|
-
MAX_LENGTH: MAX_LENGTH2
|
|
2378
|
-
} = constants;
|
|
2379
|
-
const debug2 = debug_1;
|
|
2380
|
-
exports2 = module2.exports = {};
|
|
2381
|
-
const re2 = exports2.re = [];
|
|
2382
|
-
const safeRe = exports2.safeRe = [];
|
|
2383
|
-
const src = exports2.src = [];
|
|
2384
|
-
const t2 = exports2.t = {};
|
|
2385
|
-
let R = 0;
|
|
2386
|
-
const LETTERDASHNUMBER = "[a-zA-Z0-9-]";
|
|
2387
|
-
const safeRegexReplacements = [
|
|
2388
|
-
["\\s", 1],
|
|
2389
|
-
["\\d", MAX_LENGTH2],
|
|
2390
|
-
[LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH2]
|
|
2428
|
+
var debug_1;
|
|
2429
|
+
var hasRequiredDebug;
|
|
2430
|
+
function requireDebug() {
|
|
2431
|
+
if (hasRequiredDebug) return debug_1;
|
|
2432
|
+
hasRequiredDebug = 1;
|
|
2433
|
+
const debug = typeof process === "object" && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG) ? (...args) => console.error("SEMVER", ...args) : () => {
|
|
2434
|
+
};
|
|
2435
|
+
debug_1 = debug;
|
|
2436
|
+
return debug_1;
|
|
2437
|
+
}
|
|
2438
|
+
var constants;
|
|
2439
|
+
var hasRequiredConstants;
|
|
2440
|
+
function requireConstants() {
|
|
2441
|
+
if (hasRequiredConstants) return constants;
|
|
2442
|
+
hasRequiredConstants = 1;
|
|
2443
|
+
const SEMVER_SPEC_VERSION = "2.0.0";
|
|
2444
|
+
const MAX_LENGTH = 256;
|
|
2445
|
+
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || /* istanbul ignore next */
|
|
2446
|
+
9007199254740991;
|
|
2447
|
+
const MAX_SAFE_COMPONENT_LENGTH = 16;
|
|
2448
|
+
const MAX_SAFE_BUILD_LENGTH = MAX_LENGTH - 6;
|
|
2449
|
+
const RELEASE_TYPES = [
|
|
2450
|
+
"major",
|
|
2451
|
+
"premajor",
|
|
2452
|
+
"minor",
|
|
2453
|
+
"preminor",
|
|
2454
|
+
"patch",
|
|
2455
|
+
"prepatch",
|
|
2456
|
+
"prerelease"
|
|
2391
2457
|
];
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2458
|
+
constants = {
|
|
2459
|
+
MAX_LENGTH,
|
|
2460
|
+
MAX_SAFE_COMPONENT_LENGTH,
|
|
2461
|
+
MAX_SAFE_BUILD_LENGTH,
|
|
2462
|
+
MAX_SAFE_INTEGER,
|
|
2463
|
+
RELEASE_TYPES,
|
|
2464
|
+
SEMVER_SPEC_VERSION,
|
|
2465
|
+
FLAG_INCLUDE_PRERELEASE: 1,
|
|
2466
|
+
FLAG_LOOSE: 2
|
|
2397
2467
|
};
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2468
|
+
return constants;
|
|
2469
|
+
}
|
|
2470
|
+
var re = { exports: {} };
|
|
2471
|
+
var hasRequiredRe;
|
|
2472
|
+
function requireRe() {
|
|
2473
|
+
if (hasRequiredRe) return re.exports;
|
|
2474
|
+
hasRequiredRe = 1;
|
|
2475
|
+
(function(module2, exports2) {
|
|
2476
|
+
const {
|
|
2477
|
+
MAX_SAFE_COMPONENT_LENGTH,
|
|
2478
|
+
MAX_SAFE_BUILD_LENGTH,
|
|
2479
|
+
MAX_LENGTH
|
|
2480
|
+
} = requireConstants();
|
|
2481
|
+
const debug = requireDebug();
|
|
2482
|
+
exports2 = module2.exports = {};
|
|
2483
|
+
const re2 = exports2.re = [];
|
|
2484
|
+
const safeRe = exports2.safeRe = [];
|
|
2485
|
+
const src = exports2.src = [];
|
|
2486
|
+
const t = exports2.t = {};
|
|
2487
|
+
let R = 0;
|
|
2488
|
+
const LETTERDASHNUMBER = "[a-zA-Z0-9-]";
|
|
2489
|
+
const safeRegexReplacements = [
|
|
2490
|
+
["\\s", 1],
|
|
2491
|
+
["\\d", MAX_LENGTH],
|
|
2492
|
+
[LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH]
|
|
2493
|
+
];
|
|
2494
|
+
const makeSafeRegex = (value) => {
|
|
2495
|
+
for (const [token, max] of safeRegexReplacements) {
|
|
2496
|
+
value = value.split(`${token}*`).join(`${token}{0,${max}}`).split(`${token}+`).join(`${token}{1,${max}}`);
|
|
2497
|
+
}
|
|
2498
|
+
return value;
|
|
2499
|
+
};
|
|
2500
|
+
const createToken = (name, value, isGlobal) => {
|
|
2501
|
+
const safe = makeSafeRegex(value);
|
|
2502
|
+
const index = R++;
|
|
2503
|
+
debug(name, index, value);
|
|
2504
|
+
t[name] = index;
|
|
2505
|
+
src[index] = value;
|
|
2506
|
+
re2[index] = new RegExp(value, isGlobal ? "g" : void 0);
|
|
2507
|
+
safeRe[index] = new RegExp(safe, isGlobal ? "g" : void 0);
|
|
2508
|
+
};
|
|
2509
|
+
createToken("NUMERICIDENTIFIER", "0|[1-9]\\d*");
|
|
2510
|
+
createToken("NUMERICIDENTIFIERLOOSE", "\\d+");
|
|
2511
|
+
createToken("NONNUMERICIDENTIFIER", `\\d*[a-zA-Z-]${LETTERDASHNUMBER}*`);
|
|
2512
|
+
createToken("MAINVERSION", `(${src[t.NUMERICIDENTIFIER]})\\.(${src[t.NUMERICIDENTIFIER]})\\.(${src[t.NUMERICIDENTIFIER]})`);
|
|
2513
|
+
createToken("MAINVERSIONLOOSE", `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.(${src[t.NUMERICIDENTIFIERLOOSE]})\\.(${src[t.NUMERICIDENTIFIERLOOSE]})`);
|
|
2514
|
+
createToken("PRERELEASEIDENTIFIER", `(?:${src[t.NUMERICIDENTIFIER]}|${src[t.NONNUMERICIDENTIFIER]})`);
|
|
2515
|
+
createToken("PRERELEASEIDENTIFIERLOOSE", `(?:${src[t.NUMERICIDENTIFIERLOOSE]}|${src[t.NONNUMERICIDENTIFIER]})`);
|
|
2516
|
+
createToken("PRERELEASE", `(?:-(${src[t.PRERELEASEIDENTIFIER]}(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`);
|
|
2517
|
+
createToken("PRERELEASELOOSE", `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`);
|
|
2518
|
+
createToken("BUILDIDENTIFIER", `${LETTERDASHNUMBER}+`);
|
|
2519
|
+
createToken("BUILD", `(?:\\+(${src[t.BUILDIDENTIFIER]}(?:\\.${src[t.BUILDIDENTIFIER]})*))`);
|
|
2520
|
+
createToken("FULLPLAIN", `v?${src[t.MAINVERSION]}${src[t.PRERELEASE]}?${src[t.BUILD]}?`);
|
|
2521
|
+
createToken("FULL", `^${src[t.FULLPLAIN]}$`);
|
|
2522
|
+
createToken("LOOSEPLAIN", `[v=\\s]*${src[t.MAINVERSIONLOOSE]}${src[t.PRERELEASELOOSE]}?${src[t.BUILD]}?`);
|
|
2523
|
+
createToken("LOOSE", `^${src[t.LOOSEPLAIN]}$`);
|
|
2524
|
+
createToken("GTLT", "((?:<|>)?=?)");
|
|
2525
|
+
createToken("XRANGEIDENTIFIERLOOSE", `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);
|
|
2526
|
+
createToken("XRANGEIDENTIFIER", `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`);
|
|
2527
|
+
createToken("XRANGEPLAIN", `[v=\\s]*(${src[t.XRANGEIDENTIFIER]})(?:\\.(${src[t.XRANGEIDENTIFIER]})(?:\\.(${src[t.XRANGEIDENTIFIER]})(?:${src[t.PRERELEASE]})?${src[t.BUILD]}?)?)?`);
|
|
2528
|
+
createToken("XRANGEPLAINLOOSE", `[v=\\s]*(${src[t.XRANGEIDENTIFIERLOOSE]})(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})(?:${src[t.PRERELEASELOOSE]})?${src[t.BUILD]}?)?)?`);
|
|
2529
|
+
createToken("XRANGE", `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAIN]}$`);
|
|
2530
|
+
createToken("XRANGELOOSE", `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`);
|
|
2531
|
+
createToken("COERCEPLAIN", `${"(^|[^\\d])(\\d{1,"}${MAX_SAFE_COMPONENT_LENGTH}})(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?`);
|
|
2532
|
+
createToken("COERCE", `${src[t.COERCEPLAIN]}(?:$|[^\\d])`);
|
|
2533
|
+
createToken("COERCEFULL", src[t.COERCEPLAIN] + `(?:${src[t.PRERELEASE]})?(?:${src[t.BUILD]})?(?:$|[^\\d])`);
|
|
2534
|
+
createToken("COERCERTL", src[t.COERCE], true);
|
|
2535
|
+
createToken("COERCERTLFULL", src[t.COERCEFULL], true);
|
|
2536
|
+
createToken("LONETILDE", "(?:~>?)");
|
|
2537
|
+
createToken("TILDETRIM", `(\\s*)${src[t.LONETILDE]}\\s+`, true);
|
|
2538
|
+
exports2.tildeTrimReplace = "$1~";
|
|
2539
|
+
createToken("TILDE", `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`);
|
|
2540
|
+
createToken("TILDELOOSE", `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`);
|
|
2541
|
+
createToken("LONECARET", "(?:\\^)");
|
|
2542
|
+
createToken("CARETTRIM", `(\\s*)${src[t.LONECARET]}\\s+`, true);
|
|
2543
|
+
exports2.caretTrimReplace = "$1^";
|
|
2544
|
+
createToken("CARET", `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`);
|
|
2545
|
+
createToken("CARETLOOSE", `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`);
|
|
2546
|
+
createToken("COMPARATORLOOSE", `^${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]})$|^$`);
|
|
2547
|
+
createToken("COMPARATOR", `^${src[t.GTLT]}\\s*(${src[t.FULLPLAIN]})$|^$`);
|
|
2548
|
+
createToken("COMPARATORTRIM", `(\\s*)${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true);
|
|
2549
|
+
exports2.comparatorTrimReplace = "$1$2$3";
|
|
2550
|
+
createToken("HYPHENRANGE", `^\\s*(${src[t.XRANGEPLAIN]})\\s+-\\s+(${src[t.XRANGEPLAIN]})\\s*$`);
|
|
2551
|
+
createToken("HYPHENRANGELOOSE", `^\\s*(${src[t.XRANGEPLAINLOOSE]})\\s+-\\s+(${src[t.XRANGEPLAINLOOSE]})\\s*$`);
|
|
2552
|
+
createToken("STAR", "(<|>)?=?\\s*\\*");
|
|
2553
|
+
createToken("GTE0", "^\\s*>=\\s*0\\.0\\.0\\s*$");
|
|
2554
|
+
createToken("GTE0PRE", "^\\s*>=\\s*0\\.0\\.0-0\\s*$");
|
|
2555
|
+
})(re, re.exports);
|
|
2556
|
+
return re.exports;
|
|
2557
|
+
}
|
|
2558
|
+
var parseOptions_1;
|
|
2559
|
+
var hasRequiredParseOptions;
|
|
2560
|
+
function requireParseOptions() {
|
|
2561
|
+
if (hasRequiredParseOptions) return parseOptions_1;
|
|
2562
|
+
hasRequiredParseOptions = 1;
|
|
2563
|
+
const looseOption = Object.freeze({ loose: true });
|
|
2564
|
+
const emptyOpts = Object.freeze({});
|
|
2565
|
+
const parseOptions = (options) => {
|
|
2566
|
+
if (!options) {
|
|
2567
|
+
return emptyOpts;
|
|
2568
|
+
}
|
|
2569
|
+
if (typeof options !== "object") {
|
|
2570
|
+
return looseOption;
|
|
2571
|
+
}
|
|
2572
|
+
return options;
|
|
2406
2573
|
};
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
}
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
};
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
}
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
const debug = debug_1;
|
|
2483
|
-
const { MAX_LENGTH, MAX_SAFE_INTEGER } = constants;
|
|
2484
|
-
const { safeRe: re, t } = reExports;
|
|
2485
|
-
const parseOptions = parseOptions_1;
|
|
2486
|
-
const { compareIdentifiers } = identifiers;
|
|
2487
|
-
let SemVer$2 = class SemVer {
|
|
2488
|
-
constructor(version, options) {
|
|
2489
|
-
options = parseOptions(options);
|
|
2490
|
-
if (version instanceof SemVer) {
|
|
2491
|
-
if (version.loose === !!options.loose && version.includePrerelease === !!options.includePrerelease) {
|
|
2492
|
-
return version;
|
|
2574
|
+
parseOptions_1 = parseOptions;
|
|
2575
|
+
return parseOptions_1;
|
|
2576
|
+
}
|
|
2577
|
+
var identifiers;
|
|
2578
|
+
var hasRequiredIdentifiers;
|
|
2579
|
+
function requireIdentifiers() {
|
|
2580
|
+
if (hasRequiredIdentifiers) return identifiers;
|
|
2581
|
+
hasRequiredIdentifiers = 1;
|
|
2582
|
+
const numeric = /^[0-9]+$/;
|
|
2583
|
+
const compareIdentifiers = (a, b) => {
|
|
2584
|
+
const anum = numeric.test(a);
|
|
2585
|
+
const bnum = numeric.test(b);
|
|
2586
|
+
if (anum && bnum) {
|
|
2587
|
+
a = +a;
|
|
2588
|
+
b = +b;
|
|
2589
|
+
}
|
|
2590
|
+
return a === b ? 0 : anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : 1;
|
|
2591
|
+
};
|
|
2592
|
+
const rcompareIdentifiers = (a, b) => compareIdentifiers(b, a);
|
|
2593
|
+
identifiers = {
|
|
2594
|
+
compareIdentifiers,
|
|
2595
|
+
rcompareIdentifiers
|
|
2596
|
+
};
|
|
2597
|
+
return identifiers;
|
|
2598
|
+
}
|
|
2599
|
+
var semver;
|
|
2600
|
+
var hasRequiredSemver;
|
|
2601
|
+
function requireSemver() {
|
|
2602
|
+
if (hasRequiredSemver) return semver;
|
|
2603
|
+
hasRequiredSemver = 1;
|
|
2604
|
+
const debug = requireDebug();
|
|
2605
|
+
const { MAX_LENGTH, MAX_SAFE_INTEGER } = requireConstants();
|
|
2606
|
+
const { safeRe: re2, t } = requireRe();
|
|
2607
|
+
const parseOptions = requireParseOptions();
|
|
2608
|
+
const { compareIdentifiers } = requireIdentifiers();
|
|
2609
|
+
class SemVer {
|
|
2610
|
+
constructor(version, options) {
|
|
2611
|
+
options = parseOptions(options);
|
|
2612
|
+
if (version instanceof SemVer) {
|
|
2613
|
+
if (version.loose === !!options.loose && version.includePrerelease === !!options.includePrerelease) {
|
|
2614
|
+
return version;
|
|
2615
|
+
} else {
|
|
2616
|
+
version = version.version;
|
|
2617
|
+
}
|
|
2618
|
+
} else if (typeof version !== "string") {
|
|
2619
|
+
throw new TypeError(`Invalid version. Must be a string. Got type "${typeof version}".`);
|
|
2620
|
+
}
|
|
2621
|
+
if (version.length > MAX_LENGTH) {
|
|
2622
|
+
throw new TypeError(
|
|
2623
|
+
`version is longer than ${MAX_LENGTH} characters`
|
|
2624
|
+
);
|
|
2625
|
+
}
|
|
2626
|
+
debug("SemVer", version, options);
|
|
2627
|
+
this.options = options;
|
|
2628
|
+
this.loose = !!options.loose;
|
|
2629
|
+
this.includePrerelease = !!options.includePrerelease;
|
|
2630
|
+
const m = version.trim().match(options.loose ? re2[t.LOOSE] : re2[t.FULL]);
|
|
2631
|
+
if (!m) {
|
|
2632
|
+
throw new TypeError(`Invalid Version: ${version}`);
|
|
2633
|
+
}
|
|
2634
|
+
this.raw = version;
|
|
2635
|
+
this.major = +m[1];
|
|
2636
|
+
this.minor = +m[2];
|
|
2637
|
+
this.patch = +m[3];
|
|
2638
|
+
if (this.major > MAX_SAFE_INTEGER || this.major < 0) {
|
|
2639
|
+
throw new TypeError("Invalid major version");
|
|
2640
|
+
}
|
|
2641
|
+
if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) {
|
|
2642
|
+
throw new TypeError("Invalid minor version");
|
|
2643
|
+
}
|
|
2644
|
+
if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) {
|
|
2645
|
+
throw new TypeError("Invalid patch version");
|
|
2646
|
+
}
|
|
2647
|
+
if (!m[4]) {
|
|
2648
|
+
this.prerelease = [];
|
|
2493
2649
|
} else {
|
|
2494
|
-
|
|
2650
|
+
this.prerelease = m[4].split(".").map((id) => {
|
|
2651
|
+
if (/^[0-9]+$/.test(id)) {
|
|
2652
|
+
const num = +id;
|
|
2653
|
+
if (num >= 0 && num < MAX_SAFE_INTEGER) {
|
|
2654
|
+
return num;
|
|
2655
|
+
}
|
|
2656
|
+
}
|
|
2657
|
+
return id;
|
|
2658
|
+
});
|
|
2495
2659
|
}
|
|
2496
|
-
|
|
2497
|
-
|
|
2660
|
+
this.build = m[5] ? m[5].split(".") : [];
|
|
2661
|
+
this.format();
|
|
2498
2662
|
}
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2663
|
+
format() {
|
|
2664
|
+
this.version = `${this.major}.${this.minor}.${this.patch}`;
|
|
2665
|
+
if (this.prerelease.length) {
|
|
2666
|
+
this.version += `-${this.prerelease.join(".")}`;
|
|
2667
|
+
}
|
|
2668
|
+
return this.version;
|
|
2503
2669
|
}
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
this.loose = !!options.loose;
|
|
2507
|
-
this.includePrerelease = !!options.includePrerelease;
|
|
2508
|
-
const m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL]);
|
|
2509
|
-
if (!m) {
|
|
2510
|
-
throw new TypeError(`Invalid Version: ${version}`);
|
|
2511
|
-
}
|
|
2512
|
-
this.raw = version;
|
|
2513
|
-
this.major = +m[1];
|
|
2514
|
-
this.minor = +m[2];
|
|
2515
|
-
this.patch = +m[3];
|
|
2516
|
-
if (this.major > MAX_SAFE_INTEGER || this.major < 0) {
|
|
2517
|
-
throw new TypeError("Invalid major version");
|
|
2518
|
-
}
|
|
2519
|
-
if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) {
|
|
2520
|
-
throw new TypeError("Invalid minor version");
|
|
2521
|
-
}
|
|
2522
|
-
if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) {
|
|
2523
|
-
throw new TypeError("Invalid patch version");
|
|
2524
|
-
}
|
|
2525
|
-
if (!m[4]) {
|
|
2526
|
-
this.prerelease = [];
|
|
2527
|
-
} else {
|
|
2528
|
-
this.prerelease = m[4].split(".").map((id) => {
|
|
2529
|
-
if (/^[0-9]+$/.test(id)) {
|
|
2530
|
-
const num = +id;
|
|
2531
|
-
if (num >= 0 && num < MAX_SAFE_INTEGER) {
|
|
2532
|
-
return num;
|
|
2533
|
-
}
|
|
2534
|
-
}
|
|
2535
|
-
return id;
|
|
2536
|
-
});
|
|
2670
|
+
toString() {
|
|
2671
|
+
return this.version;
|
|
2537
2672
|
}
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
}
|
|
2548
|
-
toString() {
|
|
2549
|
-
return this.version;
|
|
2550
|
-
}
|
|
2551
|
-
compare(other) {
|
|
2552
|
-
debug("SemVer.compare", this.version, this.options, other);
|
|
2553
|
-
if (!(other instanceof SemVer)) {
|
|
2554
|
-
if (typeof other === "string" && other === this.version) {
|
|
2673
|
+
compare(other) {
|
|
2674
|
+
debug("SemVer.compare", this.version, this.options, other);
|
|
2675
|
+
if (!(other instanceof SemVer)) {
|
|
2676
|
+
if (typeof other === "string" && other === this.version) {
|
|
2677
|
+
return 0;
|
|
2678
|
+
}
|
|
2679
|
+
other = new SemVer(other, this.options);
|
|
2680
|
+
}
|
|
2681
|
+
if (other.version === this.version) {
|
|
2555
2682
|
return 0;
|
|
2556
2683
|
}
|
|
2557
|
-
|
|
2684
|
+
return this.compareMain(other) || this.comparePre(other);
|
|
2558
2685
|
}
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
compareMain(other) {
|
|
2565
|
-
if (!(other instanceof SemVer)) {
|
|
2566
|
-
other = new SemVer(other, this.options);
|
|
2567
|
-
}
|
|
2568
|
-
return compareIdentifiers(this.major, other.major) || compareIdentifiers(this.minor, other.minor) || compareIdentifiers(this.patch, other.patch);
|
|
2569
|
-
}
|
|
2570
|
-
comparePre(other) {
|
|
2571
|
-
if (!(other instanceof SemVer)) {
|
|
2572
|
-
other = new SemVer(other, this.options);
|
|
2686
|
+
compareMain(other) {
|
|
2687
|
+
if (!(other instanceof SemVer)) {
|
|
2688
|
+
other = new SemVer(other, this.options);
|
|
2689
|
+
}
|
|
2690
|
+
return compareIdentifiers(this.major, other.major) || compareIdentifiers(this.minor, other.minor) || compareIdentifiers(this.patch, other.patch);
|
|
2573
2691
|
}
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
return 0;
|
|
2580
|
-
}
|
|
2581
|
-
let i = 0;
|
|
2582
|
-
do {
|
|
2583
|
-
const a = this.prerelease[i];
|
|
2584
|
-
const b = other.prerelease[i];
|
|
2585
|
-
debug("prerelease compare", i, a, b);
|
|
2586
|
-
if (a === void 0 && b === void 0) {
|
|
2587
|
-
return 0;
|
|
2588
|
-
} else if (b === void 0) {
|
|
2589
|
-
return 1;
|
|
2590
|
-
} else if (a === void 0) {
|
|
2692
|
+
comparePre(other) {
|
|
2693
|
+
if (!(other instanceof SemVer)) {
|
|
2694
|
+
other = new SemVer(other, this.options);
|
|
2695
|
+
}
|
|
2696
|
+
if (this.prerelease.length && !other.prerelease.length) {
|
|
2591
2697
|
return -1;
|
|
2592
|
-
} else if (
|
|
2593
|
-
|
|
2594
|
-
} else {
|
|
2595
|
-
return
|
|
2698
|
+
} else if (!this.prerelease.length && other.prerelease.length) {
|
|
2699
|
+
return 1;
|
|
2700
|
+
} else if (!this.prerelease.length && !other.prerelease.length) {
|
|
2701
|
+
return 0;
|
|
2596
2702
|
}
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2703
|
+
let i = 0;
|
|
2704
|
+
do {
|
|
2705
|
+
const a = this.prerelease[i];
|
|
2706
|
+
const b = other.prerelease[i];
|
|
2707
|
+
debug("prerelease compare", i, a, b);
|
|
2708
|
+
if (a === void 0 && b === void 0) {
|
|
2709
|
+
return 0;
|
|
2710
|
+
} else if (b === void 0) {
|
|
2711
|
+
return 1;
|
|
2712
|
+
} else if (a === void 0) {
|
|
2713
|
+
return -1;
|
|
2714
|
+
} else if (a === b) {
|
|
2715
|
+
continue;
|
|
2716
|
+
} else {
|
|
2717
|
+
return compareIdentifiers(a, b);
|
|
2718
|
+
}
|
|
2719
|
+
} while (++i);
|
|
2602
2720
|
}
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
// down to pre-release. premajor and prepatch work the same way.
|
|
2623
|
-
inc(release, identifier, identifierBase) {
|
|
2624
|
-
switch (release) {
|
|
2625
|
-
case "premajor":
|
|
2626
|
-
this.prerelease.length = 0;
|
|
2627
|
-
this.patch = 0;
|
|
2628
|
-
this.minor = 0;
|
|
2629
|
-
this.major++;
|
|
2630
|
-
this.inc("pre", identifier, identifierBase);
|
|
2631
|
-
break;
|
|
2632
|
-
case "preminor":
|
|
2633
|
-
this.prerelease.length = 0;
|
|
2634
|
-
this.patch = 0;
|
|
2635
|
-
this.minor++;
|
|
2636
|
-
this.inc("pre", identifier, identifierBase);
|
|
2637
|
-
break;
|
|
2638
|
-
case "prepatch":
|
|
2639
|
-
this.prerelease.length = 0;
|
|
2640
|
-
this.inc("patch", identifier, identifierBase);
|
|
2641
|
-
this.inc("pre", identifier, identifierBase);
|
|
2642
|
-
break;
|
|
2643
|
-
case "prerelease":
|
|
2644
|
-
if (this.prerelease.length === 0) {
|
|
2645
|
-
this.inc("patch", identifier, identifierBase);
|
|
2721
|
+
compareBuild(other) {
|
|
2722
|
+
if (!(other instanceof SemVer)) {
|
|
2723
|
+
other = new SemVer(other, this.options);
|
|
2724
|
+
}
|
|
2725
|
+
let i = 0;
|
|
2726
|
+
do {
|
|
2727
|
+
const a = this.build[i];
|
|
2728
|
+
const b = other.build[i];
|
|
2729
|
+
debug("build compare", i, a, b);
|
|
2730
|
+
if (a === void 0 && b === void 0) {
|
|
2731
|
+
return 0;
|
|
2732
|
+
} else if (b === void 0) {
|
|
2733
|
+
return 1;
|
|
2734
|
+
} else if (a === void 0) {
|
|
2735
|
+
return -1;
|
|
2736
|
+
} else if (a === b) {
|
|
2737
|
+
continue;
|
|
2738
|
+
} else {
|
|
2739
|
+
return compareIdentifiers(a, b);
|
|
2646
2740
|
}
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2741
|
+
} while (++i);
|
|
2742
|
+
}
|
|
2743
|
+
// preminor will bump the version up to the next minor release, and immediately
|
|
2744
|
+
// down to pre-release. premajor and prepatch work the same way.
|
|
2745
|
+
inc(release, identifier, identifierBase) {
|
|
2746
|
+
switch (release) {
|
|
2747
|
+
case "premajor":
|
|
2748
|
+
this.prerelease.length = 0;
|
|
2749
|
+
this.patch = 0;
|
|
2750
|
+
this.minor = 0;
|
|
2651
2751
|
this.major++;
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
case "minor":
|
|
2658
|
-
if (this.patch !== 0 || this.prerelease.length === 0) {
|
|
2752
|
+
this.inc("pre", identifier, identifierBase);
|
|
2753
|
+
break;
|
|
2754
|
+
case "preminor":
|
|
2755
|
+
this.prerelease.length = 0;
|
|
2756
|
+
this.patch = 0;
|
|
2659
2757
|
this.minor++;
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
if (!identifier && identifierBase === false) {
|
|
2673
|
-
throw new Error("invalid increment argument: identifier is empty");
|
|
2674
|
-
}
|
|
2675
|
-
if (this.prerelease.length === 0) {
|
|
2676
|
-
this.prerelease = [base];
|
|
2677
|
-
} else {
|
|
2678
|
-
let i = this.prerelease.length;
|
|
2679
|
-
while (--i >= 0) {
|
|
2680
|
-
if (typeof this.prerelease[i] === "number") {
|
|
2681
|
-
this.prerelease[i]++;
|
|
2682
|
-
i = -2;
|
|
2683
|
-
}
|
|
2758
|
+
this.inc("pre", identifier, identifierBase);
|
|
2759
|
+
break;
|
|
2760
|
+
case "prepatch":
|
|
2761
|
+
this.prerelease.length = 0;
|
|
2762
|
+
this.inc("patch", identifier, identifierBase);
|
|
2763
|
+
this.inc("pre", identifier, identifierBase);
|
|
2764
|
+
break;
|
|
2765
|
+
// If the input is a non-prerelease version, this acts the same as
|
|
2766
|
+
// prepatch.
|
|
2767
|
+
case "prerelease":
|
|
2768
|
+
if (this.prerelease.length === 0) {
|
|
2769
|
+
this.inc("patch", identifier, identifierBase);
|
|
2684
2770
|
}
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
this.
|
|
2771
|
+
this.inc("pre", identifier, identifierBase);
|
|
2772
|
+
break;
|
|
2773
|
+
case "major":
|
|
2774
|
+
if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) {
|
|
2775
|
+
this.major++;
|
|
2690
2776
|
}
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2777
|
+
this.minor = 0;
|
|
2778
|
+
this.patch = 0;
|
|
2779
|
+
this.prerelease = [];
|
|
2780
|
+
break;
|
|
2781
|
+
case "minor":
|
|
2782
|
+
if (this.patch !== 0 || this.prerelease.length === 0) {
|
|
2783
|
+
this.minor++;
|
|
2696
2784
|
}
|
|
2697
|
-
|
|
2698
|
-
|
|
2785
|
+
this.patch = 0;
|
|
2786
|
+
this.prerelease = [];
|
|
2787
|
+
break;
|
|
2788
|
+
case "patch":
|
|
2789
|
+
if (this.prerelease.length === 0) {
|
|
2790
|
+
this.patch++;
|
|
2791
|
+
}
|
|
2792
|
+
this.prerelease = [];
|
|
2793
|
+
break;
|
|
2794
|
+
// This probably shouldn't be used publicly.
|
|
2795
|
+
// 1.0.0 'pre' would become 1.0.0-0 which is the wrong direction.
|
|
2796
|
+
case "pre": {
|
|
2797
|
+
const base = Number(identifierBase) ? 1 : 0;
|
|
2798
|
+
if (!identifier && identifierBase === false) {
|
|
2799
|
+
throw new Error("invalid increment argument: identifier is empty");
|
|
2800
|
+
}
|
|
2801
|
+
if (this.prerelease.length === 0) {
|
|
2802
|
+
this.prerelease = [base];
|
|
2803
|
+
} else {
|
|
2804
|
+
let i = this.prerelease.length;
|
|
2805
|
+
while (--i >= 0) {
|
|
2806
|
+
if (typeof this.prerelease[i] === "number") {
|
|
2807
|
+
this.prerelease[i]++;
|
|
2808
|
+
i = -2;
|
|
2809
|
+
}
|
|
2810
|
+
}
|
|
2811
|
+
if (i === -1) {
|
|
2812
|
+
if (identifier === this.prerelease.join(".") && identifierBase === false) {
|
|
2813
|
+
throw new Error("invalid increment argument: identifier already exists");
|
|
2814
|
+
}
|
|
2815
|
+
this.prerelease.push(base);
|
|
2816
|
+
}
|
|
2817
|
+
}
|
|
2818
|
+
if (identifier) {
|
|
2819
|
+
let prerelease = [identifier, base];
|
|
2820
|
+
if (identifierBase === false) {
|
|
2821
|
+
prerelease = [identifier];
|
|
2822
|
+
}
|
|
2823
|
+
if (compareIdentifiers(this.prerelease[0], identifier) === 0) {
|
|
2824
|
+
if (isNaN(this.prerelease[1])) {
|
|
2825
|
+
this.prerelease = prerelease;
|
|
2826
|
+
}
|
|
2827
|
+
} else {
|
|
2699
2828
|
this.prerelease = prerelease;
|
|
2700
2829
|
}
|
|
2701
|
-
} else {
|
|
2702
|
-
this.prerelease = prerelease;
|
|
2703
2830
|
}
|
|
2831
|
+
break;
|
|
2704
2832
|
}
|
|
2705
|
-
|
|
2833
|
+
default:
|
|
2834
|
+
throw new Error(`invalid increment argument: ${release}`);
|
|
2706
2835
|
}
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
this.raw += `+${this.build.join(".")}`;
|
|
2836
|
+
this.raw = this.format();
|
|
2837
|
+
if (this.build.length) {
|
|
2838
|
+
this.raw += `+${this.build.join(".")}`;
|
|
2839
|
+
}
|
|
2840
|
+
return this;
|
|
2713
2841
|
}
|
|
2714
|
-
return this;
|
|
2715
|
-
}
|
|
2716
|
-
};
|
|
2717
|
-
var semver = SemVer$2;
|
|
2718
|
-
const SemVer$1 = semver;
|
|
2719
|
-
const parse$1 = (version, options, throwErrors = false) => {
|
|
2720
|
-
if (version instanceof SemVer$1) {
|
|
2721
|
-
return version;
|
|
2722
2842
|
}
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2843
|
+
semver = SemVer;
|
|
2844
|
+
return semver;
|
|
2845
|
+
}
|
|
2846
|
+
var parse_1;
|
|
2847
|
+
var hasRequiredParse;
|
|
2848
|
+
function requireParse() {
|
|
2849
|
+
if (hasRequiredParse) return parse_1;
|
|
2850
|
+
hasRequiredParse = 1;
|
|
2851
|
+
const SemVer = requireSemver();
|
|
2852
|
+
const parse = (version, options, throwErrors = false) => {
|
|
2853
|
+
if (version instanceof SemVer) {
|
|
2854
|
+
return version;
|
|
2728
2855
|
}
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
}
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
};
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
var
|
|
2743
|
-
|
|
2856
|
+
try {
|
|
2857
|
+
return new SemVer(version, options);
|
|
2858
|
+
} catch (er) {
|
|
2859
|
+
if (!throwErrors) {
|
|
2860
|
+
return null;
|
|
2861
|
+
}
|
|
2862
|
+
throw er;
|
|
2863
|
+
}
|
|
2864
|
+
};
|
|
2865
|
+
parse_1 = parse;
|
|
2866
|
+
return parse_1;
|
|
2867
|
+
}
|
|
2868
|
+
var valid_1;
|
|
2869
|
+
var hasRequiredValid;
|
|
2870
|
+
function requireValid() {
|
|
2871
|
+
if (hasRequiredValid) return valid_1;
|
|
2872
|
+
hasRequiredValid = 1;
|
|
2873
|
+
const parse = requireParse();
|
|
2874
|
+
const valid2 = (version, options) => {
|
|
2875
|
+
const v = parse(version, options);
|
|
2876
|
+
return v ? v.version : null;
|
|
2877
|
+
};
|
|
2878
|
+
valid_1 = valid2;
|
|
2879
|
+
return valid_1;
|
|
2880
|
+
}
|
|
2881
|
+
var validExports = requireValid();
|
|
2882
|
+
const valid = /* @__PURE__ */ getDefaultExportFromCjs(validExports);
|
|
2883
|
+
var major_1;
|
|
2884
|
+
var hasRequiredMajor;
|
|
2885
|
+
function requireMajor() {
|
|
2886
|
+
if (hasRequiredMajor) return major_1;
|
|
2887
|
+
hasRequiredMajor = 1;
|
|
2888
|
+
const SemVer = requireSemver();
|
|
2889
|
+
const major2 = (a, loose) => new SemVer(a, loose).major;
|
|
2890
|
+
major_1 = major2;
|
|
2891
|
+
return major_1;
|
|
2892
|
+
}
|
|
2893
|
+
var majorExports = requireMajor();
|
|
2894
|
+
const major = /* @__PURE__ */ getDefaultExportFromCjs(majorExports);
|
|
2744
2895
|
class ProxyBus {
|
|
2745
2896
|
bus;
|
|
2746
2897
|
constructor(bus2) {
|
|
2747
|
-
if (typeof bus2.getVersion !== "function" || !valid
|
|
2898
|
+
if (typeof bus2.getVersion !== "function" || !valid(bus2.getVersion())) {
|
|
2748
2899
|
console.warn("Proxying an event bus with an unknown or invalid version");
|
|
2749
|
-
} else if (major
|
|
2900
|
+
} else if (major(bus2.getVersion()) !== major(this.getVersion())) {
|
|
2750
2901
|
console.warn(
|
|
2751
2902
|
"Proxying an event bus of version " + bus2.getVersion() + " with " + this.getVersion()
|
|
2752
2903
|
);
|