初始化环境文件
This commit is contained in:
88
node_modules/@aws-sdk/xml-builder/dist-es/XmlNode.js
generated
vendored
Normal file
88
node_modules/@aws-sdk/xml-builder/dist-es/XmlNode.js
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
import { escapeAttribute } from "./escape-attribute";
|
||||
import { XmlText } from "./XmlText";
|
||||
export class XmlNode {
|
||||
name;
|
||||
children;
|
||||
attributes = {};
|
||||
static of(name, childText, withName) {
|
||||
const node = new XmlNode(name);
|
||||
if (childText !== undefined) {
|
||||
node.addChildNode(new XmlText(childText));
|
||||
}
|
||||
if (withName !== undefined) {
|
||||
node.withName(withName);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
constructor(name, children = []) {
|
||||
this.name = name;
|
||||
this.children = children;
|
||||
}
|
||||
withName(name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
addAttribute(name, value) {
|
||||
this.attributes[name] = value;
|
||||
return this;
|
||||
}
|
||||
addChildNode(child) {
|
||||
this.children.push(child);
|
||||
return this;
|
||||
}
|
||||
removeAttribute(name) {
|
||||
delete this.attributes[name];
|
||||
return this;
|
||||
}
|
||||
n(name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
c(child) {
|
||||
this.children.push(child);
|
||||
return this;
|
||||
}
|
||||
a(name, value) {
|
||||
if (value != null) {
|
||||
this.attributes[name] = value;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
cc(input, field, withName = field) {
|
||||
if (input[field] != null) {
|
||||
const node = XmlNode.of(field, input[field]).withName(withName);
|
||||
this.c(node);
|
||||
}
|
||||
}
|
||||
l(input, listName, memberName, valueProvider) {
|
||||
if (input[listName] != null) {
|
||||
const nodes = valueProvider();
|
||||
nodes.map((node) => {
|
||||
node.withName(memberName);
|
||||
this.c(node);
|
||||
});
|
||||
}
|
||||
}
|
||||
lc(input, listName, memberName, valueProvider) {
|
||||
if (input[listName] != null) {
|
||||
const nodes = valueProvider();
|
||||
const containerNode = new XmlNode(memberName);
|
||||
nodes.map((node) => {
|
||||
containerNode.c(node);
|
||||
});
|
||||
this.c(containerNode);
|
||||
}
|
||||
}
|
||||
toString() {
|
||||
const hasChildren = Boolean(this.children.length);
|
||||
let xmlText = `<${this.name}`;
|
||||
const attributes = this.attributes;
|
||||
for (const attributeName of Object.keys(attributes)) {
|
||||
const attribute = attributes[attributeName];
|
||||
if (attribute != null) {
|
||||
xmlText += ` ${attributeName}="${escapeAttribute("" + attribute)}"`;
|
||||
}
|
||||
}
|
||||
return (xmlText += !hasChildren ? "/>" : `>${this.children.map((c) => c.toString()).join("")}</${this.name}>`);
|
||||
}
|
||||
}
|
||||
10
node_modules/@aws-sdk/xml-builder/dist-es/XmlText.js
generated
vendored
Normal file
10
node_modules/@aws-sdk/xml-builder/dist-es/XmlText.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import { escapeElement } from "./escape-element";
|
||||
export class XmlText {
|
||||
value;
|
||||
constructor(value) {
|
||||
this.value = value;
|
||||
}
|
||||
toString() {
|
||||
return escapeElement("" + this.value);
|
||||
}
|
||||
}
|
||||
10
node_modules/@aws-sdk/xml-builder/dist-es/escape-attribute.js
generated
vendored
Normal file
10
node_modules/@aws-sdk/xml-builder/dist-es/escape-attribute.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
const ATTR_ESCAPE_RE = /[&<>"]/g;
|
||||
const ATTR_ESCAPE_MAP = {
|
||||
"&": "&",
|
||||
"<": "<",
|
||||
">": ">",
|
||||
'"': """,
|
||||
};
|
||||
export function escapeAttribute(value) {
|
||||
return value.replace(ATTR_ESCAPE_RE, (ch) => ATTR_ESCAPE_MAP[ch]);
|
||||
}
|
||||
15
node_modules/@aws-sdk/xml-builder/dist-es/escape-element.js
generated
vendored
Normal file
15
node_modules/@aws-sdk/xml-builder/dist-es/escape-element.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
const ELEMENT_ESCAPE_RE = /[&"'<>\r\n\u0085\u2028]/g;
|
||||
const ELEMENT_ESCAPE_MAP = {
|
||||
"&": "&",
|
||||
'"': """,
|
||||
"'": "'",
|
||||
"<": "<",
|
||||
">": ">",
|
||||
"\r": "
",
|
||||
"\n": "
",
|
||||
"\u0085": "…",
|
||||
"\u2028": "
",
|
||||
};
|
||||
export function escapeElement(value) {
|
||||
return value.replace(ELEMENT_ESCAPE_RE, (ch) => ELEMENT_ESCAPE_MAP[ch]);
|
||||
}
|
||||
3
node_modules/@aws-sdk/xml-builder/dist-es/index.js
generated
vendored
Normal file
3
node_modules/@aws-sdk/xml-builder/dist-es/index.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from "./XmlNode";
|
||||
export * from "./XmlText";
|
||||
export { parseXML } from "./xml-parser";
|
||||
1
node_modules/@aws-sdk/xml-builder/dist-es/stringable.js
generated
vendored
Normal file
1
node_modules/@aws-sdk/xml-builder/dist-es/stringable.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
57
node_modules/@aws-sdk/xml-builder/dist-es/xml-parser.browser.js
generated
vendored
Normal file
57
node_modules/@aws-sdk/xml-builder/dist-es/xml-parser.browser.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
let parser;
|
||||
export function parseXML(xmlString) {
|
||||
if (!parser) {
|
||||
parser = new DOMParser();
|
||||
}
|
||||
const xmlDocument = parser.parseFromString(xmlString, "application/xml");
|
||||
if (xmlDocument.getElementsByTagName("parsererror").length > 0) {
|
||||
throw new Error("DOMParser XML parsing error.");
|
||||
}
|
||||
const xmlToObj = (node) => {
|
||||
if (node.nodeType === Node.TEXT_NODE) {
|
||||
if (node.textContent?.trim()) {
|
||||
return node.textContent;
|
||||
}
|
||||
}
|
||||
if (node.nodeType === Node.ELEMENT_NODE) {
|
||||
const element = node;
|
||||
if (element.attributes.length === 0 && element.childNodes.length === 0) {
|
||||
return "";
|
||||
}
|
||||
const obj = {};
|
||||
const attributes = Array.from(element.attributes);
|
||||
for (const attr of attributes) {
|
||||
obj[`${attr.name}`] = attr.value;
|
||||
}
|
||||
const childNodes = Array.from(element.childNodes);
|
||||
for (const child of childNodes) {
|
||||
const childResult = xmlToObj(child);
|
||||
if (childResult != null) {
|
||||
const childName = child.nodeName;
|
||||
if (childNodes.length === 1 && attributes.length === 0 && childName === "#text") {
|
||||
return childResult;
|
||||
}
|
||||
if (obj[childName]) {
|
||||
if (Array.isArray(obj[childName])) {
|
||||
obj[childName].push(childResult);
|
||||
}
|
||||
else {
|
||||
obj[childName] = [obj[childName], childResult];
|
||||
}
|
||||
}
|
||||
else {
|
||||
obj[childName] = childResult;
|
||||
}
|
||||
}
|
||||
else if (childNodes.length === 1 && attributes.length === 0) {
|
||||
return element.textContent;
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
return {
|
||||
[xmlDocument.documentElement.nodeName]: xmlToObj(xmlDocument.documentElement),
|
||||
};
|
||||
}
|
||||
20
node_modules/@aws-sdk/xml-builder/dist-es/xml-parser.js
generated
vendored
Normal file
20
node_modules/@aws-sdk/xml-builder/dist-es/xml-parser.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
import { XMLParser } from "fast-xml-parser";
|
||||
const parser = new XMLParser({
|
||||
attributeNamePrefix: "",
|
||||
processEntities: {
|
||||
enabled: true,
|
||||
maxTotalExpansions: Infinity,
|
||||
},
|
||||
htmlEntities: true,
|
||||
ignoreAttributes: false,
|
||||
ignoreDeclaration: true,
|
||||
parseTagValue: false,
|
||||
trimValues: false,
|
||||
tagValueProcessor: (_, val) => (val.trim() === "" && val.includes("\n") ? "" : undefined),
|
||||
maxNestedTags: Infinity,
|
||||
});
|
||||
parser.addEntity("#xD", "\r");
|
||||
parser.addEntity("#10", "\n");
|
||||
export function parseXML(xmlString) {
|
||||
return parser.parse(xmlString, true);
|
||||
}
|
||||
Reference in New Issue
Block a user