hot-updater
Version:
React Native OTA solution for self-hosted
1,310 lines (1,298 loc) • 508 kB
JavaScript
const require_picocolors$1 = require('./picocolors-nLcU57DT.cjs');
const node_fs = require_picocolors$1.__toESM(require("node:fs"));
const fs = require_picocolors$1.__toESM(require("fs"));
const __clack_prompts = require_picocolors$1.__toESM(require("@clack/prompts"));
const __hot_updater_plugin_core = require_picocolors$1.__toESM(require("@hot-updater/plugin-core"));
const path = require_picocolors$1.__toESM(require("path"));
const __expo_fingerprint = require_picocolors$1.__toESM(require("@expo/fingerprint"));
//#region ../../node_modules/.pnpm/fast-xml-parser@5.2.3/node_modules/fast-xml-parser/src/util.js
const nameStartChar$1 = ":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";
const nameChar$1 = nameStartChar$1 + "\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
const nameRegexp = "[" + nameStartChar$1 + "][" + nameChar$1 + "]*";
const regexName = new RegExp("^" + nameRegexp + "$");
function getAllMatches(string$1, regex) {
const matches = [];
let match = regex.exec(string$1);
while (match) {
const allmatches = [];
allmatches.startIndex = regex.lastIndex - match[0].length;
const len$1 = match.length;
for (let index = 0; index < len$1; index++) allmatches.push(match[index]);
matches.push(allmatches);
match = regex.exec(string$1);
}
return matches;
}
const isName = function(string$1) {
const match = regexName.exec(string$1);
return !(match === null || typeof match === "undefined");
};
function isExist(v) {
return typeof v !== "undefined";
}
//#endregion
//#region ../../node_modules/.pnpm/fast-xml-parser@5.2.3/node_modules/fast-xml-parser/src/validator.js
const defaultOptions$2 = {
allowBooleanAttributes: false,
unpairedTags: []
};
function validate(xmlData, options) {
options = Object.assign({}, defaultOptions$2, options);
const tags = [];
let tagFound = false;
let reachedRoot = false;
if (xmlData[0] === "") xmlData = xmlData.substr(1);
for (let i$1 = 0; i$1 < xmlData.length; i$1++) if (xmlData[i$1] === "<" && xmlData[i$1 + 1] === "?") {
i$1 += 2;
i$1 = readPI(xmlData, i$1);
if (i$1.err) return i$1;
} else if (xmlData[i$1] === "<") {
let tagStartPos = i$1;
i$1++;
if (xmlData[i$1] === "!") {
i$1 = readCommentAndCDATA(xmlData, i$1);
continue;
} else {
let closingTag = false;
if (xmlData[i$1] === "/") {
closingTag = true;
i$1++;
}
let tagName = "";
for (; i$1 < xmlData.length && xmlData[i$1] !== ">" && xmlData[i$1] !== " " && xmlData[i$1] !== " " && xmlData[i$1] !== "\n" && xmlData[i$1] !== "\r"; i$1++) tagName += xmlData[i$1];
tagName = tagName.trim();
if (tagName[tagName.length - 1] === "/") {
tagName = tagName.substring(0, tagName.length - 1);
i$1--;
}
if (!validateTagName(tagName)) {
let msg;
if (tagName.trim().length === 0) msg = "Invalid space after '<'.";
else msg = "Tag '" + tagName + "' is an invalid name.";
return getErrorObject("InvalidTag", msg, getLineNumberForPosition(xmlData, i$1));
}
const result = readAttributeStr(xmlData, i$1);
if (result === false) return getErrorObject("InvalidAttr", "Attributes for '" + tagName + "' have open quote.", getLineNumberForPosition(xmlData, i$1));
let attrStr = result.value;
i$1 = result.index;
if (attrStr[attrStr.length - 1] === "/") {
const attrStrStart = i$1 - attrStr.length;
attrStr = attrStr.substring(0, attrStr.length - 1);
const isValid = validateAttributeString(attrStr, options);
if (isValid === true) tagFound = true;
else return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, attrStrStart + isValid.err.line));
} else if (closingTag) if (!result.tagClosed) return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' doesn't have proper closing.", getLineNumberForPosition(xmlData, i$1));
else if (attrStr.trim().length > 0) return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' can't have attributes or invalid starting.", getLineNumberForPosition(xmlData, tagStartPos));
else if (tags.length === 0) return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' has not been opened.", getLineNumberForPosition(xmlData, tagStartPos));
else {
const otg = tags.pop();
if (tagName !== otg.tagName) {
let openPos = getLineNumberForPosition(xmlData, otg.tagStartPos);
return getErrorObject("InvalidTag", "Expected closing tag '" + otg.tagName + "' (opened in line " + openPos.line + ", col " + openPos.col + ") instead of closing tag '" + tagName + "'.", getLineNumberForPosition(xmlData, tagStartPos));
}
if (tags.length == 0) reachedRoot = true;
}
else {
const isValid = validateAttributeString(attrStr, options);
if (isValid !== true) return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, i$1 - attrStr.length + isValid.err.line));
if (reachedRoot === true) return getErrorObject("InvalidXml", "Multiple possible root nodes found.", getLineNumberForPosition(xmlData, i$1));
else if (options.unpairedTags.indexOf(tagName) !== -1) {} else tags.push({
tagName,
tagStartPos
});
tagFound = true;
}
for (i$1++; i$1 < xmlData.length; i$1++) if (xmlData[i$1] === "<") if (xmlData[i$1 + 1] === "!") {
i$1++;
i$1 = readCommentAndCDATA(xmlData, i$1);
continue;
} else if (xmlData[i$1 + 1] === "?") {
i$1 = readPI(xmlData, ++i$1);
if (i$1.err) return i$1;
} else break;
else if (xmlData[i$1] === "&") {
const afterAmp = validateAmpersand(xmlData, i$1);
if (afterAmp == -1) return getErrorObject("InvalidChar", "char '&' is not expected.", getLineNumberForPosition(xmlData, i$1));
i$1 = afterAmp;
} else if (reachedRoot === true && !isWhiteSpace(xmlData[i$1])) return getErrorObject("InvalidXml", "Extra text at the end", getLineNumberForPosition(xmlData, i$1));
if (xmlData[i$1] === "<") i$1--;
}
} else {
if (isWhiteSpace(xmlData[i$1])) continue;
return getErrorObject("InvalidChar", "char '" + xmlData[i$1] + "' is not expected.", getLineNumberForPosition(xmlData, i$1));
}
if (!tagFound) return getErrorObject("InvalidXml", "Start tag expected.", 1);
else if (tags.length == 1) return getErrorObject("InvalidTag", "Unclosed tag '" + tags[0].tagName + "'.", getLineNumberForPosition(xmlData, tags[0].tagStartPos));
else if (tags.length > 0) return getErrorObject("InvalidXml", "Invalid '" + JSON.stringify(tags.map((t) => t.tagName), null, 4).replace(/\r?\n/g, "") + "' found.", {
line: 1,
col: 1
});
return true;
}
function isWhiteSpace(char) {
return char === " " || char === " " || char === "\n" || char === "\r";
}
/**
* Read Processing insstructions and skip
* @param {*} xmlData
* @param {*} i
*/
function readPI(xmlData, i$1) {
const start = i$1;
for (; i$1 < xmlData.length; i$1++) if (xmlData[i$1] == "?" || xmlData[i$1] == " ") {
const tagname = xmlData.substr(start, i$1 - start);
if (i$1 > 5 && tagname === "xml") return getErrorObject("InvalidXml", "XML declaration allowed only at the start of the document.", getLineNumberForPosition(xmlData, i$1));
else if (xmlData[i$1] == "?" && xmlData[i$1 + 1] == ">") {
i$1++;
break;
} else continue;
}
return i$1;
}
function readCommentAndCDATA(xmlData, i$1) {
if (xmlData.length > i$1 + 5 && xmlData[i$1 + 1] === "-" && xmlData[i$1 + 2] === "-") {
for (i$1 += 3; i$1 < xmlData.length; i$1++) if (xmlData[i$1] === "-" && xmlData[i$1 + 1] === "-" && xmlData[i$1 + 2] === ">") {
i$1 += 2;
break;
}
} else if (xmlData.length > i$1 + 8 && xmlData[i$1 + 1] === "D" && xmlData[i$1 + 2] === "O" && xmlData[i$1 + 3] === "C" && xmlData[i$1 + 4] === "T" && xmlData[i$1 + 5] === "Y" && xmlData[i$1 + 6] === "P" && xmlData[i$1 + 7] === "E") {
let angleBracketsCount = 1;
for (i$1 += 8; i$1 < xmlData.length; i$1++) if (xmlData[i$1] === "<") angleBracketsCount++;
else if (xmlData[i$1] === ">") {
angleBracketsCount--;
if (angleBracketsCount === 0) break;
}
} else if (xmlData.length > i$1 + 9 && xmlData[i$1 + 1] === "[" && xmlData[i$1 + 2] === "C" && xmlData[i$1 + 3] === "D" && xmlData[i$1 + 4] === "A" && xmlData[i$1 + 5] === "T" && xmlData[i$1 + 6] === "A" && xmlData[i$1 + 7] === "[") {
for (i$1 += 8; i$1 < xmlData.length; i$1++) if (xmlData[i$1] === "]" && xmlData[i$1 + 1] === "]" && xmlData[i$1 + 2] === ">") {
i$1 += 2;
break;
}
}
return i$1;
}
const doubleQuote = "\"";
const singleQuote = "'";
/**
* Keep reading xmlData until '<' is found outside the attribute value.
* @param {string} xmlData
* @param {number} i
*/
function readAttributeStr(xmlData, i$1) {
let attrStr = "";
let startChar = "";
let tagClosed = false;
for (; i$1 < xmlData.length; i$1++) {
if (xmlData[i$1] === doubleQuote || xmlData[i$1] === singleQuote) if (startChar === "") startChar = xmlData[i$1];
else if (startChar !== xmlData[i$1]) {} else startChar = "";
else if (xmlData[i$1] === ">") {
if (startChar === "") {
tagClosed = true;
break;
}
}
attrStr += xmlData[i$1];
}
if (startChar !== "") return false;
return {
value: attrStr,
index: i$1,
tagClosed
};
}
/**
* Select all the attributes whether valid or invalid.
*/
const validAttrStrRegxp = new RegExp("(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['\"])(([\\s\\S])*?)\\5)?", "g");
function validateAttributeString(attrStr, options) {
const matches = getAllMatches(attrStr, validAttrStrRegxp);
const attrNames = {};
for (let i$1 = 0; i$1 < matches.length; i$1++) {
if (matches[i$1][1].length === 0) return getErrorObject("InvalidAttr", "Attribute '" + matches[i$1][2] + "' has no space in starting.", getPositionFromMatch(matches[i$1]));
else if (matches[i$1][3] !== void 0 && matches[i$1][4] === void 0) return getErrorObject("InvalidAttr", "Attribute '" + matches[i$1][2] + "' is without value.", getPositionFromMatch(matches[i$1]));
else if (matches[i$1][3] === void 0 && !options.allowBooleanAttributes) return getErrorObject("InvalidAttr", "boolean attribute '" + matches[i$1][2] + "' is not allowed.", getPositionFromMatch(matches[i$1]));
const attrName = matches[i$1][2];
if (!validateAttrName(attrName)) return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is an invalid name.", getPositionFromMatch(matches[i$1]));
if (!attrNames.hasOwnProperty(attrName)) attrNames[attrName] = 1;
else return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is repeated.", getPositionFromMatch(matches[i$1]));
}
return true;
}
function validateNumberAmpersand(xmlData, i$1) {
let re = /\d/;
if (xmlData[i$1] === "x") {
i$1++;
re = /[\da-fA-F]/;
}
for (; i$1 < xmlData.length; i$1++) {
if (xmlData[i$1] === ";") return i$1;
if (!xmlData[i$1].match(re)) break;
}
return -1;
}
function validateAmpersand(xmlData, i$1) {
i$1++;
if (xmlData[i$1] === ";") return -1;
if (xmlData[i$1] === "#") {
i$1++;
return validateNumberAmpersand(xmlData, i$1);
}
let count = 0;
for (; i$1 < xmlData.length; i$1++, count++) {
if (xmlData[i$1].match(/\w/) && count < 20) continue;
if (xmlData[i$1] === ";") break;
return -1;
}
return i$1;
}
function getErrorObject(code$1, message, lineNumber) {
return { err: {
code: code$1,
msg: message,
line: lineNumber.line || lineNumber,
col: lineNumber.col
} };
}
function validateAttrName(attrName) {
return isName(attrName);
}
function validateTagName(tagname) {
return isName(tagname);
}
function getLineNumberForPosition(xmlData, index) {
const lines = xmlData.substring(0, index).split(/\r?\n/);
return {
line: lines.length,
col: lines[lines.length - 1].length + 1
};
}
function getPositionFromMatch(match) {
return match.startIndex + match[1].length;
}
//#endregion
//#region ../../node_modules/.pnpm/fast-xml-parser@5.2.3/node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js
const defaultOptions$1 = {
preserveOrder: false,
attributeNamePrefix: "@_",
attributesGroupName: false,
textNodeName: "#text",
ignoreAttributes: true,
removeNSPrefix: false,
allowBooleanAttributes: false,
parseTagValue: true,
parseAttributeValue: false,
trimValues: true,
cdataPropName: false,
numberParseOptions: {
hex: true,
leadingZeros: true,
eNotation: true
},
tagValueProcessor: function(tagName, val) {
return val;
},
attributeValueProcessor: function(attrName, val) {
return val;
},
stopNodes: [],
alwaysCreateTextNode: false,
isArray: () => false,
commentPropName: false,
unpairedTags: [],
processEntities: true,
htmlEntities: false,
ignoreDeclaration: false,
ignorePiTags: false,
transformTagName: false,
transformAttributeName: false,
updateTag: function(tagName, jPath, attrs) {
return tagName;
},
captureMetaData: false
};
const buildOptions = function(options) {
return Object.assign({}, defaultOptions$1, options);
};
//#endregion
//#region ../../node_modules/.pnpm/fast-xml-parser@5.2.3/node_modules/fast-xml-parser/src/xmlparser/xmlNode.js
let METADATA_SYMBOL$1;
if (typeof Symbol !== "function") METADATA_SYMBOL$1 = "@@xmlMetadata";
else METADATA_SYMBOL$1 = Symbol("XML Node Metadata");
var XmlNode = class {
constructor(tagname) {
this.tagname = tagname;
this.child = [];
this[":@"] = {};
}
add(key, val) {
if (key === "__proto__") key = "#__proto__";
this.child.push({ [key]: val });
}
addChild(node, startIndex) {
if (node.tagname === "__proto__") node.tagname = "#__proto__";
if (node[":@"] && Object.keys(node[":@"]).length > 0) this.child.push({
[node.tagname]: node.child,
[":@"]: node[":@"]
});
else this.child.push({ [node.tagname]: node.child });
if (startIndex !== void 0) this.child[this.child.length - 1][METADATA_SYMBOL$1] = { startIndex };
}
/** symbol used for metadata */
static getMetaDataSymbol() {
return METADATA_SYMBOL$1;
}
};
//#endregion
//#region ../../node_modules/.pnpm/fast-xml-parser@5.2.3/node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js
function readDocType(xmlData, i$1) {
const entities$1 = {};
if (xmlData[i$1 + 3] === "O" && xmlData[i$1 + 4] === "C" && xmlData[i$1 + 5] === "T" && xmlData[i$1 + 6] === "Y" && xmlData[i$1 + 7] === "P" && xmlData[i$1 + 8] === "E") {
i$1 = i$1 + 9;
let angleBracketsCount = 1;
let hasBody = false, comment = false;
let exp = "";
for (; i$1 < xmlData.length; i$1++) if (xmlData[i$1] === "<" && !comment) {
if (hasBody && hasSeq(xmlData, "!ENTITY", i$1)) {
i$1 += 7;
let entityName, val;
[entityName, val, i$1] = readEntityExp(xmlData, i$1 + 1);
if (val.indexOf("&") === -1) entities$1[entityName] = {
regx: RegExp(`&${entityName};`, "g"),
val
};
} else if (hasBody && hasSeq(xmlData, "!ELEMENT", i$1)) {
i$1 += 8;
const { index } = readElementExp(xmlData, i$1 + 1);
i$1 = index;
} else if (hasBody && hasSeq(xmlData, "!ATTLIST", i$1)) i$1 += 8;
else if (hasBody && hasSeq(xmlData, "!NOTATION", i$1)) {
i$1 += 9;
const { index } = readNotationExp(xmlData, i$1 + 1);
i$1 = index;
} else if (hasSeq(xmlData, "!--", i$1)) comment = true;
else throw new Error("Invalid DOCTYPE");
angleBracketsCount++;
exp = "";
} else if (xmlData[i$1] === ">") {
if (comment) {
if (xmlData[i$1 - 1] === "-" && xmlData[i$1 - 2] === "-") {
comment = false;
angleBracketsCount--;
}
} else angleBracketsCount--;
if (angleBracketsCount === 0) break;
} else if (xmlData[i$1] === "[") hasBody = true;
else exp += xmlData[i$1];
if (angleBracketsCount !== 0) throw new Error(`Unclosed DOCTYPE`);
} else throw new Error(`Invalid Tag instead of DOCTYPE`);
return {
entities: entities$1,
i: i$1
};
}
const skipWhitespace = (data, index) => {
while (index < data.length && /\s/.test(data[index])) index++;
return index;
};
function readEntityExp(xmlData, i$1) {
i$1 = skipWhitespace(xmlData, i$1);
let entityName = "";
while (i$1 < xmlData.length && !/\s/.test(xmlData[i$1]) && xmlData[i$1] !== "\"" && xmlData[i$1] !== "'") {
entityName += xmlData[i$1];
i$1++;
}
validateEntityName(entityName);
i$1 = skipWhitespace(xmlData, i$1);
if (xmlData.substring(i$1, i$1 + 6).toUpperCase() === "SYSTEM") throw new Error("External entities are not supported");
else if (xmlData[i$1] === "%") throw new Error("Parameter entities are not supported");
let entityValue = "";
[i$1, entityValue] = readIdentifierVal(xmlData, i$1, "entity");
i$1--;
return [
entityName,
entityValue,
i$1
];
}
function readNotationExp(xmlData, i$1) {
i$1 = skipWhitespace(xmlData, i$1);
let notationName = "";
while (i$1 < xmlData.length && !/\s/.test(xmlData[i$1])) {
notationName += xmlData[i$1];
i$1++;
}
validateEntityName(notationName);
i$1 = skipWhitespace(xmlData, i$1);
const identifierType = xmlData.substring(i$1, i$1 + 6).toUpperCase();
if (identifierType !== "SYSTEM" && identifierType !== "PUBLIC") throw new Error(`Expected SYSTEM or PUBLIC, found "${identifierType}"`);
i$1 += identifierType.length;
i$1 = skipWhitespace(xmlData, i$1);
let publicIdentifier = null;
let systemIdentifier = null;
if (identifierType === "PUBLIC") {
[i$1, publicIdentifier] = readIdentifierVal(xmlData, i$1, "publicIdentifier");
i$1 = skipWhitespace(xmlData, i$1);
if (xmlData[i$1] === "\"" || xmlData[i$1] === "'") [i$1, systemIdentifier] = readIdentifierVal(xmlData, i$1, "systemIdentifier");
} else if (identifierType === "SYSTEM") {
[i$1, systemIdentifier] = readIdentifierVal(xmlData, i$1, "systemIdentifier");
if (!systemIdentifier) throw new Error("Missing mandatory system identifier for SYSTEM notation");
}
return {
notationName,
publicIdentifier,
systemIdentifier,
index: --i$1
};
}
function readIdentifierVal(xmlData, i$1, type$1) {
let identifierVal = "";
const startChar = xmlData[i$1];
if (startChar !== "\"" && startChar !== "'") throw new Error(`Expected quoted string, found "${startChar}"`);
i$1++;
while (i$1 < xmlData.length && xmlData[i$1] !== startChar) {
identifierVal += xmlData[i$1];
i$1++;
}
if (xmlData[i$1] !== startChar) throw new Error(`Unterminated ${type$1} value`);
i$1++;
return [i$1, identifierVal];
}
function readElementExp(xmlData, i$1) {
i$1 = skipWhitespace(xmlData, i$1);
let elementName = "";
while (i$1 < xmlData.length && !/\s/.test(xmlData[i$1])) {
elementName += xmlData[i$1];
i$1++;
}
if (!validateEntityName(elementName)) throw new Error(`Invalid element name: "${elementName}"`);
i$1 = skipWhitespace(xmlData, i$1);
let contentModel = "";
if (xmlData[i$1] === "E" && hasSeq(xmlData, "MPTY", i$1)) i$1 += 6;
else if (xmlData[i$1] === "A" && hasSeq(xmlData, "NY", i$1)) i$1 += 4;
else if (xmlData[i$1] === "(") {
i$1++;
while (i$1 < xmlData.length && xmlData[i$1] !== ")") {
contentModel += xmlData[i$1];
i$1++;
}
if (xmlData[i$1] !== ")") throw new Error("Unterminated content model");
} else throw new Error(`Invalid Element Expression, found "${xmlData[i$1]}"`);
return {
elementName,
contentModel: contentModel.trim(),
index: i$1
};
}
function hasSeq(data, seq, i$1) {
for (let j = 0; j < seq.length; j++) if (seq[j] !== data[i$1 + j + 1]) return false;
return true;
}
function validateEntityName(name) {
if (isName(name)) return name;
else throw new Error(`Invalid entity name ${name}`);
}
//#endregion
//#region ../../node_modules/.pnpm/strnum@2.1.1/node_modules/strnum/strnum.js
const hexRegex = /^[-+]?0x[a-fA-F0-9]+$/;
const numRegex = /^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/;
const consider = {
hex: true,
leadingZeros: true,
decimalPoint: ".",
eNotation: true
};
function toNumber(str, options = {}) {
options = Object.assign({}, consider, options);
if (!str || typeof str !== "string") return str;
let trimmedStr = str.trim();
if (options.skipLike !== void 0 && options.skipLike.test(trimmedStr)) return str;
else if (str === "0") return 0;
else if (options.hex && hexRegex.test(trimmedStr)) return parse_int(trimmedStr, 16);
else if (trimmedStr.search(/.+[eE].+/) !== -1) return resolveEnotation(str, trimmedStr, options);
else {
const match = numRegex.exec(trimmedStr);
if (match) {
const sign = match[1] || "";
const leadingZeros = match[2];
let numTrimmedByZeros = trimZeros(match[3]);
const decimalAdjacentToLeadingZeros = sign ? str[leadingZeros.length + 1] === "." : str[leadingZeros.length] === ".";
if (!options.leadingZeros && (leadingZeros.length > 1 || leadingZeros.length === 1 && !decimalAdjacentToLeadingZeros)) return str;
else {
const num = Number(trimmedStr);
const parsedStr = String(num);
if (num === 0) return num;
if (parsedStr.search(/[eE]/) !== -1) if (options.eNotation) return num;
else return str;
else if (trimmedStr.indexOf(".") !== -1) if (parsedStr === "0") return num;
else if (parsedStr === numTrimmedByZeros) return num;
else if (parsedStr === `${sign}${numTrimmedByZeros}`) return num;
else return str;
let n = leadingZeros ? numTrimmedByZeros : trimmedStr;
if (leadingZeros) return n === parsedStr || sign + n === parsedStr ? num : str;
else return n === parsedStr || n === sign + parsedStr ? num : str;
}
} else return str;
}
}
const eNotationRegx = /^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;
function resolveEnotation(str, trimmedStr, options) {
if (!options.eNotation) return str;
const notation = trimmedStr.match(eNotationRegx);
if (notation) {
let sign = notation[1] || "";
const eChar = notation[3].indexOf("e") === -1 ? "E" : "e";
const leadingZeros = notation[2];
const eAdjacentToLeadingZeros = sign ? str[leadingZeros.length + 1] === eChar : str[leadingZeros.length] === eChar;
if (leadingZeros.length > 1 && eAdjacentToLeadingZeros) return str;
else if (leadingZeros.length === 1 && (notation[3].startsWith(`.${eChar}`) || notation[3][0] === eChar)) return Number(trimmedStr);
else if (options.leadingZeros && !eAdjacentToLeadingZeros) {
trimmedStr = (notation[1] || "") + notation[3];
return Number(trimmedStr);
} else return str;
} else return str;
}
/**
*
* @param {string} numStr without leading zeros
* @returns
*/
function trimZeros(numStr) {
if (numStr && numStr.indexOf(".") !== -1) {
numStr = numStr.replace(/0+$/, "");
if (numStr === ".") numStr = "0";
else if (numStr[0] === ".") numStr = "0" + numStr;
else if (numStr[numStr.length - 1] === ".") numStr = numStr.substring(0, numStr.length - 1);
return numStr;
}
return numStr;
}
function parse_int(numStr, base) {
if (parseInt) return parseInt(numStr, base);
else if (Number.parseInt) return Number.parseInt(numStr, base);
else if (window && window.parseInt) return window.parseInt(numStr, base);
else throw new Error("parseInt, Number.parseInt, window.parseInt are not supported");
}
//#endregion
//#region ../../node_modules/.pnpm/fast-xml-parser@5.2.3/node_modules/fast-xml-parser/src/ignoreAttributes.js
function getIgnoreAttributesFn(ignoreAttributes) {
if (typeof ignoreAttributes === "function") return ignoreAttributes;
if (Array.isArray(ignoreAttributes)) return (attrName) => {
for (const pattern$1 of ignoreAttributes) {
if (typeof pattern$1 === "string" && attrName === pattern$1) return true;
if (pattern$1 instanceof RegExp && pattern$1.test(attrName)) return true;
}
};
return () => false;
}
//#endregion
//#region ../../node_modules/.pnpm/fast-xml-parser@5.2.3/node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js
var OrderedObjParser = class {
constructor(options) {
this.options = options;
this.currentNode = null;
this.tagsNodeStack = [];
this.docTypeEntities = {};
this.lastEntities = {
"apos": {
regex: /&(apos|#39|#x27);/g,
val: "'"
},
"gt": {
regex: /&(gt|#62|#x3E);/g,
val: ">"
},
"lt": {
regex: /&(lt|#60|#x3C);/g,
val: "<"
},
"quot": {
regex: /&(quot|#34|#x22);/g,
val: "\""
}
};
this.ampEntity = {
regex: /&(amp|#38|#x26);/g,
val: "&"
};
this.htmlEntities = {
"space": {
regex: /&(nbsp|#160);/g,
val: " "
},
"cent": {
regex: /&(cent|#162);/g,
val: "¢"
},
"pound": {
regex: /&(pound|#163);/g,
val: "£"
},
"yen": {
regex: /&(yen|#165);/g,
val: "¥"
},
"euro": {
regex: /&(euro|#8364);/g,
val: "€"
},
"copyright": {
regex: /&(copy|#169);/g,
val: "©"
},
"reg": {
regex: /&(reg|#174);/g,
val: "®"
},
"inr": {
regex: /&(inr|#8377);/g,
val: "₹"
},
"num_dec": {
regex: /&#([0-9]{1,7});/g,
val: (_, str) => String.fromCodePoint(Number.parseInt(str, 10))
},
"num_hex": {
regex: /&#x([0-9a-fA-F]{1,6});/g,
val: (_, str) => String.fromCodePoint(Number.parseInt(str, 16))
}
};
this.addExternalEntities = addExternalEntities;
this.parseXml = parseXml;
this.parseTextData = parseTextData;
this.resolveNameSpace = resolveNameSpace;
this.buildAttributesMap = buildAttributesMap;
this.isItStopNode = isItStopNode;
this.replaceEntitiesValue = replaceEntitiesValue$1;
this.readStopNodeData = readStopNodeData;
this.saveTextToParentTag = saveTextToParentTag;
this.addChild = addChild;
this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes);
}
};
function addExternalEntities(externalEntities) {
const entKeys = Object.keys(externalEntities);
for (let i$1 = 0; i$1 < entKeys.length; i$1++) {
const ent = entKeys[i$1];
this.lastEntities[ent] = {
regex: new RegExp("&" + ent + ";", "g"),
val: externalEntities[ent]
};
}
}
/**
* @param {string} val
* @param {string} tagName
* @param {string} jPath
* @param {boolean} dontTrim
* @param {boolean} hasAttributes
* @param {boolean} isLeafNode
* @param {boolean} escapeEntities
*/
function parseTextData(val, tagName, jPath, dontTrim, hasAttributes, isLeafNode, escapeEntities) {
if (val !== void 0) {
if (this.options.trimValues && !dontTrim) val = val.trim();
if (val.length > 0) {
if (!escapeEntities) val = this.replaceEntitiesValue(val);
const newval = this.options.tagValueProcessor(tagName, val, jPath, hasAttributes, isLeafNode);
if (newval === null || newval === void 0) return val;
else if (typeof newval !== typeof val || newval !== val) return newval;
else if (this.options.trimValues) return parseValue(val, this.options.parseTagValue, this.options.numberParseOptions);
else {
const trimmedVal = val.trim();
if (trimmedVal === val) return parseValue(val, this.options.parseTagValue, this.options.numberParseOptions);
else return val;
}
}
}
}
function resolveNameSpace(tagname) {
if (this.options.removeNSPrefix) {
const tags = tagname.split(":");
const prefix = tagname.charAt(0) === "/" ? "/" : "";
if (tags[0] === "xmlns") return "";
if (tags.length === 2) tagname = prefix + tags[1];
}
return tagname;
}
const attrsRegx = new RegExp("([^\\s=]+)\\s*(=\\s*(['\"])([\\s\\S]*?)\\3)?", "gm");
function buildAttributesMap(attrStr, jPath, tagName) {
if (this.options.ignoreAttributes !== true && typeof attrStr === "string") {
const matches = getAllMatches(attrStr, attrsRegx);
const len$1 = matches.length;
const attrs = {};
for (let i$1 = 0; i$1 < len$1; i$1++) {
const attrName = this.resolveNameSpace(matches[i$1][1]);
if (this.ignoreAttributesFn(attrName, jPath)) continue;
let oldVal = matches[i$1][4];
let aName = this.options.attributeNamePrefix + attrName;
if (attrName.length) {
if (this.options.transformAttributeName) aName = this.options.transformAttributeName(aName);
if (aName === "__proto__") aName = "#__proto__";
if (oldVal !== void 0) {
if (this.options.trimValues) oldVal = oldVal.trim();
oldVal = this.replaceEntitiesValue(oldVal);
const newVal = this.options.attributeValueProcessor(attrName, oldVal, jPath);
if (newVal === null || newVal === void 0) attrs[aName] = oldVal;
else if (typeof newVal !== typeof oldVal || newVal !== oldVal) attrs[aName] = newVal;
else attrs[aName] = parseValue(oldVal, this.options.parseAttributeValue, this.options.numberParseOptions);
} else if (this.options.allowBooleanAttributes) attrs[aName] = true;
}
}
if (!Object.keys(attrs).length) return;
if (this.options.attributesGroupName) {
const attrCollection = {};
attrCollection[this.options.attributesGroupName] = attrs;
return attrCollection;
}
return attrs;
}
}
const parseXml = function(xmlData) {
xmlData = xmlData.replace(/\r\n?/g, "\n");
const xmlObj = new XmlNode("!xml");
let currentNode = xmlObj;
let textData = "";
let jPath = "";
for (let i$1 = 0; i$1 < xmlData.length; i$1++) {
const ch = xmlData[i$1];
if (ch === "<") if (xmlData[i$1 + 1] === "/") {
const closeIndex = findClosingIndex(xmlData, ">", i$1, "Closing Tag is not closed.");
let tagName = xmlData.substring(i$1 + 2, closeIndex).trim();
if (this.options.removeNSPrefix) {
const colonIndex = tagName.indexOf(":");
if (colonIndex !== -1) tagName = tagName.substr(colonIndex + 1);
}
if (this.options.transformTagName) tagName = this.options.transformTagName(tagName);
if (currentNode) textData = this.saveTextToParentTag(textData, currentNode, jPath);
const lastTagName = jPath.substring(jPath.lastIndexOf(".") + 1);
if (tagName && this.options.unpairedTags.indexOf(tagName) !== -1) throw new Error(`Unpaired tag can not be used as closing tag: </${tagName}>`);
let propIndex = 0;
if (lastTagName && this.options.unpairedTags.indexOf(lastTagName) !== -1) {
propIndex = jPath.lastIndexOf(".", jPath.lastIndexOf(".") - 1);
this.tagsNodeStack.pop();
} else propIndex = jPath.lastIndexOf(".");
jPath = jPath.substring(0, propIndex);
currentNode = this.tagsNodeStack.pop();
textData = "";
i$1 = closeIndex;
} else if (xmlData[i$1 + 1] === "?") {
let tagData = readTagExp(xmlData, i$1, false, "?>");
if (!tagData) throw new Error("Pi Tag is not closed.");
textData = this.saveTextToParentTag(textData, currentNode, jPath);
if (this.options.ignoreDeclaration && tagData.tagName === "?xml" || this.options.ignorePiTags) {} else {
const childNode = new XmlNode(tagData.tagName);
childNode.add(this.options.textNodeName, "");
if (tagData.tagName !== tagData.tagExp && tagData.attrExpPresent) childNode[":@"] = this.buildAttributesMap(tagData.tagExp, jPath, tagData.tagName);
this.addChild(currentNode, childNode, jPath, i$1);
}
i$1 = tagData.closeIndex + 1;
} else if (xmlData.substr(i$1 + 1, 3) === "!--") {
const endIndex = findClosingIndex(xmlData, "-->", i$1 + 4, "Comment is not closed.");
if (this.options.commentPropName) {
const comment = xmlData.substring(i$1 + 4, endIndex - 2);
textData = this.saveTextToParentTag(textData, currentNode, jPath);
currentNode.add(this.options.commentPropName, [{ [this.options.textNodeName]: comment }]);
}
i$1 = endIndex;
} else if (xmlData.substr(i$1 + 1, 2) === "!D") {
const result = readDocType(xmlData, i$1);
this.docTypeEntities = result.entities;
i$1 = result.i;
} else if (xmlData.substr(i$1 + 1, 2) === "![") {
const closeIndex = findClosingIndex(xmlData, "]]>", i$1, "CDATA is not closed.") - 2;
const tagExp = xmlData.substring(i$1 + 9, closeIndex);
textData = this.saveTextToParentTag(textData, currentNode, jPath);
let val = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true, true);
if (val == void 0) val = "";
if (this.options.cdataPropName) currentNode.add(this.options.cdataPropName, [{ [this.options.textNodeName]: tagExp }]);
else currentNode.add(this.options.textNodeName, val);
i$1 = closeIndex + 2;
} else {
let result = readTagExp(xmlData, i$1, this.options.removeNSPrefix);
let tagName = result.tagName;
const rawTagName = result.rawTagName;
let tagExp = result.tagExp;
let attrExpPresent = result.attrExpPresent;
let closeIndex = result.closeIndex;
if (this.options.transformTagName) tagName = this.options.transformTagName(tagName);
if (currentNode && textData) {
if (currentNode.tagname !== "!xml") textData = this.saveTextToParentTag(textData, currentNode, jPath, false);
}
const lastTag = currentNode;
if (lastTag && this.options.unpairedTags.indexOf(lastTag.tagname) !== -1) {
currentNode = this.tagsNodeStack.pop();
jPath = jPath.substring(0, jPath.lastIndexOf("."));
}
if (tagName !== xmlObj.tagname) jPath += jPath ? "." + tagName : tagName;
const startIndex = i$1;
if (this.isItStopNode(this.options.stopNodes, jPath, tagName)) {
let tagContent = "";
if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) {
if (tagName[tagName.length - 1] === "/") {
tagName = tagName.substr(0, tagName.length - 1);
jPath = jPath.substr(0, jPath.length - 1);
tagExp = tagName;
} else tagExp = tagExp.substr(0, tagExp.length - 1);
i$1 = result.closeIndex;
} else if (this.options.unpairedTags.indexOf(tagName) !== -1) i$1 = result.closeIndex;
else {
const result$1 = this.readStopNodeData(xmlData, rawTagName, closeIndex + 1);
if (!result$1) throw new Error(`Unexpected end of ${rawTagName}`);
i$1 = result$1.i;
tagContent = result$1.tagContent;
}
const childNode = new XmlNode(tagName);
if (tagName !== tagExp && attrExpPresent) childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
if (tagContent) tagContent = this.parseTextData(tagContent, tagName, jPath, true, attrExpPresent, true, true);
jPath = jPath.substr(0, jPath.lastIndexOf("."));
childNode.add(this.options.textNodeName, tagContent);
this.addChild(currentNode, childNode, jPath, startIndex);
} else {
if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) {
if (tagName[tagName.length - 1] === "/") {
tagName = tagName.substr(0, tagName.length - 1);
jPath = jPath.substr(0, jPath.length - 1);
tagExp = tagName;
} else tagExp = tagExp.substr(0, tagExp.length - 1);
if (this.options.transformTagName) tagName = this.options.transformTagName(tagName);
const childNode = new XmlNode(tagName);
if (tagName !== tagExp && attrExpPresent) childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
this.addChild(currentNode, childNode, jPath, startIndex);
jPath = jPath.substr(0, jPath.lastIndexOf("."));
} else {
const childNode = new XmlNode(tagName);
this.tagsNodeStack.push(currentNode);
if (tagName !== tagExp && attrExpPresent) childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
this.addChild(currentNode, childNode, jPath, startIndex);
currentNode = childNode;
}
textData = "";
i$1 = closeIndex;
}
}
else textData += xmlData[i$1];
}
return xmlObj.child;
};
function addChild(currentNode, childNode, jPath, startIndex) {
if (!this.options.captureMetaData) startIndex = void 0;
const result = this.options.updateTag(childNode.tagname, jPath, childNode[":@"]);
if (result === false) {} else if (typeof result === "string") {
childNode.tagname = result;
currentNode.addChild(childNode, startIndex);
} else currentNode.addChild(childNode, startIndex);
}
const replaceEntitiesValue$1 = function(val) {
if (this.options.processEntities) {
for (let entityName in this.docTypeEntities) {
const entity = this.docTypeEntities[entityName];
val = val.replace(entity.regx, entity.val);
}
for (let entityName in this.lastEntities) {
const entity = this.lastEntities[entityName];
val = val.replace(entity.regex, entity.val);
}
if (this.options.htmlEntities) for (let entityName in this.htmlEntities) {
const entity = this.htmlEntities[entityName];
val = val.replace(entity.regex, entity.val);
}
val = val.replace(this.ampEntity.regex, this.ampEntity.val);
}
return val;
};
function saveTextToParentTag(textData, currentNode, jPath, isLeafNode) {
if (textData) {
if (isLeafNode === void 0) isLeafNode = currentNode.child.length === 0;
textData = this.parseTextData(textData, currentNode.tagname, jPath, false, currentNode[":@"] ? Object.keys(currentNode[":@"]).length !== 0 : false, isLeafNode);
if (textData !== void 0 && textData !== "") currentNode.add(this.options.textNodeName, textData);
textData = "";
}
return textData;
}
/**
*
* @param {string[]} stopNodes
* @param {string} jPath
* @param {string} currentTagName
*/
function isItStopNode(stopNodes, jPath, currentTagName) {
const allNodesExp = "*." + currentTagName;
for (const stopNodePath in stopNodes) {
const stopNodeExp = stopNodes[stopNodePath];
if (allNodesExp === stopNodeExp || jPath === stopNodeExp) return true;
}
return false;
}
/**
* Returns the tag Expression and where it is ending handling single-double quotes situation
* @param {string} xmlData
* @param {number} i starting index
* @returns
*/
function tagExpWithClosingIndex(xmlData, i$1, closingChar = ">") {
let attrBoundary;
let tagExp = "";
for (let index = i$1; index < xmlData.length; index++) {
let ch = xmlData[index];
if (attrBoundary) {
if (ch === attrBoundary) attrBoundary = "";
} else if (ch === "\"" || ch === "'") attrBoundary = ch;
else if (ch === closingChar[0]) if (closingChar[1]) {
if (xmlData[index + 1] === closingChar[1]) return {
data: tagExp,
index
};
} else return {
data: tagExp,
index
};
else if (ch === " ") ch = " ";
tagExp += ch;
}
}
function findClosingIndex(xmlData, str, i$1, errMsg) {
const closingIndex = xmlData.indexOf(str, i$1);
if (closingIndex === -1) throw new Error(errMsg);
else return closingIndex + str.length - 1;
}
function readTagExp(xmlData, i$1, removeNSPrefix, closingChar = ">") {
const result = tagExpWithClosingIndex(xmlData, i$1 + 1, closingChar);
if (!result) return;
let tagExp = result.data;
const closeIndex = result.index;
const separatorIndex = tagExp.search(/\s/);
let tagName = tagExp;
let attrExpPresent = true;
if (separatorIndex !== -1) {
tagName = tagExp.substring(0, separatorIndex);
tagExp = tagExp.substring(separatorIndex + 1).trimStart();
}
const rawTagName = tagName;
if (removeNSPrefix) {
const colonIndex = tagName.indexOf(":");
if (colonIndex !== -1) {
tagName = tagName.substr(colonIndex + 1);
attrExpPresent = tagName !== result.data.substr(colonIndex + 1);
}
}
return {
tagName,
tagExp,
closeIndex,
attrExpPresent,
rawTagName
};
}
/**
* find paired tag for a stop node
* @param {string} xmlData
* @param {string} tagName
* @param {number} i
*/
function readStopNodeData(xmlData, tagName, i$1) {
const startIndex = i$1;
let openTagCount = 1;
for (; i$1 < xmlData.length; i$1++) if (xmlData[i$1] === "<") if (xmlData[i$1 + 1] === "/") {
const closeIndex = findClosingIndex(xmlData, ">", i$1, `${tagName} is not closed`);
let closeTagName = xmlData.substring(i$1 + 2, closeIndex).trim();
if (closeTagName === tagName) {
openTagCount--;
if (openTagCount === 0) return {
tagContent: xmlData.substring(startIndex, i$1),
i: closeIndex
};
}
i$1 = closeIndex;
} else if (xmlData[i$1 + 1] === "?") {
const closeIndex = findClosingIndex(xmlData, "?>", i$1 + 1, "StopNode is not closed.");
i$1 = closeIndex;
} else if (xmlData.substr(i$1 + 1, 3) === "!--") {
const closeIndex = findClosingIndex(xmlData, "-->", i$1 + 3, "StopNode is not closed.");
i$1 = closeIndex;
} else if (xmlData.substr(i$1 + 1, 2) === "![") {
const closeIndex = findClosingIndex(xmlData, "]]>", i$1, "StopNode is not closed.") - 2;
i$1 = closeIndex;
} else {
const tagData = readTagExp(xmlData, i$1, ">");
if (tagData) {
const openTagName = tagData && tagData.tagName;
if (openTagName === tagName && tagData.tagExp[tagData.tagExp.length - 1] !== "/") openTagCount++;
i$1 = tagData.closeIndex;
}
}
}
function parseValue(val, shouldParse, options) {
if (shouldParse && typeof val === "string") {
const newval = val.trim();
if (newval === "true") return true;
else if (newval === "false") return false;
else return toNumber(val, options);
} else if (isExist(val)) return val;
else return "";
}
//#endregion
//#region ../../node_modules/.pnpm/fast-xml-parser@5.2.3/node_modules/fast-xml-parser/src/xmlparser/node2json.js
const METADATA_SYMBOL = XmlNode.getMetaDataSymbol();
/**
*
* @param {array} node
* @param {any} options
* @returns
*/
function prettify(node, options) {
return compress(node, options);
}
/**
*
* @param {array} arr
* @param {object} options
* @param {string} jPath
* @returns object
*/
function compress(arr, options, jPath) {
let text;
const compressedObj = {};
for (let i$1 = 0; i$1 < arr.length; i$1++) {
const tagObj = arr[i$1];
const property = propName$1(tagObj);
let newJpath = "";
if (jPath === void 0) newJpath = property;
else newJpath = jPath + "." + property;
if (property === options.textNodeName) if (text === void 0) text = tagObj[property];
else text += "" + tagObj[property];
else if (property === void 0) continue;
else if (tagObj[property]) {
let val = compress(tagObj[property], options, newJpath);
const isLeaf = isLeafTag(val, options);
if (tagObj[METADATA_SYMBOL] !== void 0) val[METADATA_SYMBOL] = tagObj[METADATA_SYMBOL];
if (tagObj[":@"]) assignAttributes(val, tagObj[":@"], newJpath, options);
else if (Object.keys(val).length === 1 && val[options.textNodeName] !== void 0 && !options.alwaysCreateTextNode) val = val[options.textNodeName];
else if (Object.keys(val).length === 0) if (options.alwaysCreateTextNode) val[options.textNodeName] = "";
else val = "";
if (compressedObj[property] !== void 0 && compressedObj.hasOwnProperty(property)) {
if (!Array.isArray(compressedObj[property])) compressedObj[property] = [compressedObj[property]];
compressedObj[property].push(val);
} else if (options.isArray(property, newJpath, isLeaf)) compressedObj[property] = [val];
else compressedObj[property] = val;
}
}
if (typeof text === "string") {
if (text.length > 0) compressedObj[options.textNodeName] = text;
} else if (text !== void 0) compressedObj[options.textNodeName] = text;
return compressedObj;
}
function propName$1(obj) {
const keys = Object.keys(obj);
for (let i$1 = 0; i$1 < keys.length; i$1++) {
const key = keys[i$1];
if (key !== ":@") return key;
}
}
function assignAttributes(obj, attrMap, jpath, options) {
if (attrMap) {
const keys = Object.keys(attrMap);
const len$1 = keys.length;
for (let i$1 = 0; i$1 < len$1; i$1++) {
const atrrName = keys[i$1];
if (options.isArray(atrrName, jpath + "." + atrrName, true, true)) obj[atrrName] = [attrMap[atrrName]];
else obj[atrrName] = attrMap[atrrName];
}
}
}
function isLeafTag(obj, options) {
const { textNodeName } = options;
const propCount = Object.keys(obj).length;
if (propCount === 0) return true;
if (propCount === 1 && (obj[textNodeName] || typeof obj[textNodeName] === "boolean" || obj[textNodeName] === 0)) return true;
return false;
}
//#endregion
//#region ../../node_modules/.pnpm/fast-xml-parser@5.2.3/node_modules/fast-xml-parser/src/xmlparser/XMLParser.js
var XMLParser = class {
constructor(options) {
this.externalEntities = {};
this.options = buildOptions(options);
}
/**
* Parse XML dats to JS object
* @param {string|Buffer} xmlData
* @param {boolean|Object} validationOption
*/
parse(xmlData, validationOption) {
if (typeof xmlData === "string") {} else if (xmlData.toString) xmlData = xmlData.toString();
else throw new Error("XML data is accepted in String or Bytes[] form.");
if (validationOption) {
if (validationOption === true) validationOption = {};
const result = validate(xmlData, validationOption);
if (result !== true) throw Error(`${result.err.msg}:${result.err.line}:${result.err.col}`);
}
const orderedObjParser = new OrderedObjParser(this.options);
orderedObjParser.addExternalEntities(this.externalEntities);
const orderedResult = orderedObjParser.parseXml(xmlData);
if (this.options.preserveOrder || orderedResult === void 0) return orderedResult;
else return prettify(orderedResult, this.options);
}
/**
* Add Entity which is not by default supported by this library
* @param {string} key
* @param {string} value
*/
addEntity(key, value) {
if (value.indexOf("&") !== -1) throw new Error("Entity value can't have '&'");
else if (key.indexOf("&") !== -1 || key.indexOf(";") !== -1) throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '
'");
else if (value === "&") throw new Error("An entity with value '&' is not permitted");
else this.externalEntities[key] = value;
}
/**
* Returns a Symbol that can be used to access the metadata
* property on a node.
*
* If Symbol is not available in the environment, an ordinary property is used
* and the name of the property is here returned.
*
* The XMLMetaData property is only present when `captureMetaData`
* is true in the options.
*/
static getMetaDataSymbol() {
return XmlNode.getMetaDataSymbol();
}
};
//#endregion
//#region ../../node_modules/.pnpm/fast-xml-parser@5.2.3/node_modules/fast-xml-parser/src/xmlbuilder/orderedJs2Xml.js
const EOL = "\n";
/**
*
* @param {array} jArray
* @param {any} options
* @returns
*/
function toXml(jArray, options) {
let indentation = "";
if (options.format && options.indentBy.length > 0) indentation = EOL;
return arrToStr(jArray, options, "", indentation);
}
function arrToStr(arr, options, jPath, indentation) {
let xmlStr = "";
let isPreviousElementTag = false;
for (let i$1 = 0; i$1 < arr.length; i$1++) {
const tagObj = arr[i$1];
const tagName = propName(tagObj);
if (tagName === void 0) continue;
let newJPath = "";
if (jPath.length === 0) newJPath = tagName;
else newJPath = `${jPath}.${tagName}`;
if (tagName === options.textNodeName) {
let tagText = tagObj[tagName];
if (!isStopNode(newJPath, options)) {
tagText = options.tagValueProcessor(tagName, tagText);
tagText = replaceEntitiesValue(tagText, options);
}
if (isPreviousElementTag) xmlStr += indentation;
xmlStr += tagText;
isPreviousElementTag = false;
continue;
} else if (tagName === options.cdataPropName) {
if (isPreviousElementTag) xmlStr += indentation;
xmlStr += `<![CDATA[${tagObj[tagName][0][options.textNodeName]}]]>`;
isPreviousElementTag = false;
continue;
} else if (tagName === options.commentPropName) {
xmlStr += indentation + `<!--${tagObj[tagName][0][options.textNodeName]}-->`;
isPreviousElementTag = true;
continue;
} else if (tagName[0] === "?") {
const attStr$1 = attr_to_str(tagObj[":@"], options);
const tempInd = tagName === "?xml" ? "" : indentation;
let piTextNodeName = tagObj[tagName][0][options.textNodeName];
piTextNodeName = piTextNodeName.length !== 0 ? " " + piTextNodeName : "";
xmlStr += tempInd + `<${tagName}${piTextNodeName}${attStr$1}?>`;
isPreviousElementTag = true;
continue;
}
let newIdentation = indentation;
if (newIdentation !== "") newIdentation += options.indentBy;
const attStr = attr_to_str(tagObj[":@"], options);
const tagStart = indentation + `<${tagName}${attStr}`;
const tagValue = arrToStr(tagObj[tagName], options, newJPath, newIdentation);
if (options.unpairedTags.indexOf(tagName) !== -1) if (options.suppressUnpairedNode) xmlStr += tagStart + ">";
else xmlStr += tagStart + "/>";
else if ((!tagValue || tagValue.length === 0) && options.suppressEmptyNode) xmlStr += tagStart + "/>";
else if (tagValue && tagValue.endsWith(">")) xmlStr += tagStart + `>${tagValue}${indentation}</${tagName}>`;
else {
xmlStr += tagStart + ">";
if (tagValue && indentation !== "" && (tagValue.includes("/>") || tagValue.includes("</"))) xmlStr += indentation + options.indentBy + tagValue + indentation;
else xmlStr += tagValue;
xmlStr += `</${tagName}>`;
}
isPreviousElementTag = true;
}
return xmlStr;
}
function propName(obj) {
const keys = Object.keys(obj);
for (let i$1 = 0; i$1 < keys.length; i$1++) {
const key = keys[i$1];
if (!obj.hasOwnProperty(key)) continue;
if (key !== ":@") return key;
}
}
function attr_to_str(attrMap, options) {
let attrStr = "";
if (attrMap && !options.ignoreAttributes) for (let attr in attrMap) {
if (!attrMap.hasOwnProperty(attr)) continue;
let attrVal = options.attributeValueProcessor(attr, attrMap[attr]);
attrVal = replaceEntitiesValue(attrVal, options);
if (attrVal === true && options.suppressBooleanAttributes) attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}`;
else attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}="${attrVal}"`;
}
return attrStr;
}
function isStopNode(jPath, options) {
jPath = jPath.substr(0, jPath.length - options.textNodeName.length - 1);
let tagName = jPath.substr(jPath.lastIndexOf(".") + 1);
for (let index in options.stopNodes) if (options.stopNodes[index] === jPath || options.stopNodes[index] === "*." + tagName) return true;
return false;
}
function replaceEntitiesValue(textValue, options) {
if (textValue && textValue.length > 0 && options.processEntities) for (let i$1 = 0; i$1 < options.entities.length; i$1++) {
const entity = options.entities[i$1];
textValue = textValue.replace(entity.regex, entity.val);
}
return textValue;
}
//#endregion
//#region ../../node_modules/.pnpm/fast-xml-parser@5.2.3/node_modules/fast-xml-parser/src/xmlbuilder/json2xml.js
const defaultOptions = {
attributeNamePrefix: "@_",
attributesGroupName: false,
textNodeName: "#text",
ignoreAttributes: true,
cdataPropName: false,
format: false,
indentBy: " ",
suppressEmptyNode: false,
suppressUnpairedNode: true,
suppressBooleanAttributes: true,
tagValueProcessor: function(key, a) {
return a;
},
attributeValueProcessor: function(attrName, a) {
return a;
},
preserveOrder: false,
commentPropName: false,
unpairedTags: [],
entities: [
{
regex: new RegExp("&", "g"),
val: "&"
},
{
regex: new RegExp(">", "g"),
val: ">"
},
{
regex: new RegExp("<", "g"),
val: "<"
},
{
r