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