isomorphic-xml2js
Advanced tools
Comparing version
@@ -0,1 +1,4 @@ | ||
### 0.1.3 2018-06-06 | ||
- Target ES5 in order to support create-react-app | ||
### 0.1.2 2018-05-22 | ||
@@ -2,0 +5,0 @@ - Minor fixes to type definitions |
@@ -1,8 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const parser_1 = require("./parser"); | ||
exports.Parser = parser_1.Parser; | ||
exports.parseString = parser_1.parseString; | ||
const builder_1 = require("./builder"); | ||
exports.Builder = builder_1.Builder; | ||
import { Parser, parseString } from "./parser"; | ||
import { Builder } from "./builder"; | ||
export { Parser, parseString, Builder }; | ||
//# sourceMappingURL=browser.js.map |
@@ -1,14 +0,13 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const options_1 = require("./options"); | ||
const doc = document.implementation.createDocument(null, null, null); | ||
const serializer = new XMLSerializer(); | ||
class Builder { | ||
constructor(opts) { | ||
this.opts = options_1.overrideDefaultsWith(opts); | ||
import { overrideDefaultsWith, defaultAttrkey, defaultCharkey, defaultChildkey } from "./options"; | ||
var doc = document.implementation.createDocument(null, null, null); | ||
var serializer = new XMLSerializer(); | ||
var Builder = /** @class */ (function () { | ||
function Builder(opts) { | ||
this.opts = overrideDefaultsWith(opts); | ||
} | ||
buildAttributes(attrs) { | ||
const result = []; | ||
for (const key of Object.keys(attrs)) { | ||
const attr = doc.createAttribute(key); | ||
Builder.prototype.buildAttributes = function (attrs) { | ||
var result = []; | ||
for (var _i = 0, _a = Object.keys(attrs); _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
var attr = doc.createAttribute(key); | ||
attr.value = attrs[key].toString(); | ||
@@ -18,7 +17,7 @@ result.push(attr); | ||
return result; | ||
} | ||
buildNode(obj, context) { | ||
const attrkey = this.opts.attrkey || options_1.defaultAttrkey; | ||
const charkey = this.opts.charkey || options_1.defaultCharkey; | ||
const childkey = this.opts.childkey || options_1.defaultChildkey; | ||
}; | ||
Builder.prototype.buildNode = function (obj, context) { | ||
var attrkey = this.opts.attrkey || defaultAttrkey; | ||
var charkey = this.opts.charkey || defaultCharkey; | ||
var childkey = this.opts.childkey || defaultChildkey; | ||
if (obj == undefined) { | ||
@@ -28,3 +27,3 @@ obj = this.opts.emptyTag || ''; | ||
if (typeof obj === "string" || typeof obj === "number" || typeof obj === "boolean") { | ||
const elem = doc.createElement(context.elementName); | ||
var elem = doc.createElement(context.elementName); | ||
elem.textContent = obj.toString(); | ||
@@ -34,5 +33,7 @@ return [elem]; | ||
else if (Array.isArray(obj)) { | ||
const result = []; | ||
for (const arrayElem of obj) { | ||
for (const child of this.buildNode(arrayElem, context)) { | ||
var result = []; | ||
for (var _i = 0, obj_1 = obj; _i < obj_1.length; _i++) { | ||
var arrayElem = obj_1[_i]; | ||
for (var _a = 0, _b = this.buildNode(arrayElem, context); _a < _b.length; _a++) { | ||
var child = _b[_a]; | ||
result.push(child); | ||
@@ -44,6 +45,8 @@ } | ||
else if (typeof obj === "object") { | ||
const elem = doc.createElement(context.elementName); | ||
for (const key of Object.keys(obj)) { | ||
var elem = doc.createElement(context.elementName); | ||
for (var _c = 0, _d = Object.keys(obj); _c < _d.length; _c++) { | ||
var key = _d[_c]; | ||
if (key === attrkey) { | ||
for (const attr of this.buildAttributes(obj[key])) { | ||
for (var _e = 0, _f = this.buildAttributes(obj[key]); _e < _f.length; _e++) { | ||
var attr = _f[_e]; | ||
elem.attributes.setNamedItem(attr); | ||
@@ -53,5 +56,7 @@ } | ||
else if (key === childkey && !(this.opts.explicitChildren && this.opts.preserveChildrenOrder)) { | ||
const children = obj[childkey]; | ||
for (const childElementKey of Object.keys(children)) { | ||
for (const child of this.buildNode(children[childElementKey], { elementName: childElementKey })) { | ||
var children = obj[childkey]; | ||
for (var _g = 0, _h = Object.keys(children); _g < _h.length; _g++) { | ||
var childElementKey = _h[_g]; | ||
for (var _j = 0, _k = this.buildNode(children[childElementKey], { elementName: childElementKey }); _j < _k.length; _j++) { | ||
var child = _k[_j]; | ||
elem.appendChild(child); | ||
@@ -65,3 +70,4 @@ } | ||
else { | ||
for (const child of this.buildNode(obj[key], { elementName: key })) { | ||
for (var _l = 0, _m = this.buildNode(obj[key], { elementName: key }); _l < _m.length; _l++) { | ||
var child = _m[_l]; | ||
elem.appendChild(child); | ||
@@ -74,11 +80,13 @@ } | ||
else { | ||
throw new Error(`Illegal value passed to buildObject: ${obj}`); | ||
throw new Error("Illegal value passed to buildObject: " + obj); | ||
} | ||
} | ||
buildObject(obj) { | ||
const rootName = this.opts.rootName || "root"; | ||
}; | ||
Builder.prototype.buildObject = function (obj) { | ||
var rootName = this.opts.rootName || "root"; | ||
if (Array.isArray(obj)) { | ||
const mergedObj = {}; | ||
for (const arrayElem of obj) { | ||
for (const key of Object.keys(arrayElem)) { | ||
var mergedObj = {}; | ||
for (var _i = 0, obj_2 = obj; _i < obj_2.length; _i++) { | ||
var arrayElem = obj_2[_i]; | ||
for (var _a = 0, _b = Object.keys(arrayElem); _a < _b.length; _a++) { | ||
var key = _b[_a]; | ||
if (!mergedObj[key]) { | ||
@@ -92,4 +100,4 @@ mergedObj[key] = []; | ||
} | ||
const keys = Object.keys(obj); | ||
let dom; | ||
var keys = Object.keys(obj); | ||
var dom; | ||
if (keys.length <= 1 && !this.opts.rootName && this.opts.explicitRoot) { | ||
@@ -101,12 +109,13 @@ dom = this.buildNode(obj[keys[0]] || '', { elementName: keys[0] || rootName })[0]; | ||
} | ||
let xmlString = serializer.serializeToString(dom); | ||
const xmldec = this.opts.xmldec; | ||
var xmlString = serializer.serializeToString(dom); | ||
var xmldec = this.opts.xmldec; | ||
if (xmldec && !this.opts.headless) { | ||
let declaration = `<?xml version="${xmldec.version}" encoding="${xmldec.encoding}" standalone="${xmldec.standalone ? "yes" : "no"}"?>`; | ||
var declaration = "<?xml version=\"" + xmldec.version + "\" encoding=\"" + xmldec.encoding + "\" standalone=\"" + (xmldec.standalone ? "yes" : "no") + "\"?>"; | ||
xmlString = declaration + xmlString; | ||
} | ||
return xmlString; | ||
} | ||
} | ||
exports.Builder = Builder; | ||
}; | ||
return Builder; | ||
}()); | ||
export { Builder }; | ||
//# sourceMappingURL=builder.js.map |
@@ -1,4 +0,10 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const defaultOptions = { | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
var defaultOptions = { | ||
explicitRoot: true, | ||
@@ -14,10 +20,9 @@ explicitArray: true, | ||
}; | ||
exports.defaultCharkey = "_"; | ||
exports.defaultAttrkey = "$"; | ||
exports.defaultChildkey = "$$"; | ||
function overrideDefaultsWith(userOptions) { | ||
export var defaultCharkey = "_"; | ||
export var defaultAttrkey = "$"; | ||
export var defaultChildkey = "$$"; | ||
export function overrideDefaultsWith(userOptions) { | ||
// Ideally we would just use some generic deep merge thing here but don't want to pull in dependencies | ||
return Object.assign({}, defaultOptions, userOptions, { xmldec: Object.assign({}, defaultOptions.xmldec, (userOptions && userOptions.xmldec)) }); | ||
return __assign({}, defaultOptions, userOptions, { xmldec: __assign({}, defaultOptions.xmldec, (userOptions && userOptions.xmldec)) }); | ||
} | ||
exports.overrideDefaultsWith = overrideDefaultsWith; | ||
//# sourceMappingURL=options.js.map |
@@ -1,5 +0,11 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const options_1 = require("./options"); | ||
let errorNS; | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
import { overrideDefaultsWith, defaultAttrkey, defaultCharkey, defaultChildkey } from "./options"; | ||
var errorNS; | ||
try { | ||
@@ -13,3 +19,3 @@ errorNS = new DOMParser().parseFromString('INVALID', 'text/xml').getElementsByTagName("parsererror")[0].namespaceURI; | ||
if (errorNS) { | ||
const parserErrors = dom.getElementsByTagNameNS(errorNS, "parsererror"); | ||
var parserErrors = dom.getElementsByTagNameNS(errorNS, "parsererror"); | ||
if (parserErrors.length) { | ||
@@ -20,3 +26,3 @@ throw new Error(parserErrors.item(0).innerHTML); | ||
} | ||
function parseString(xml, options, callback) { | ||
export function parseString(xml, options, callback) { | ||
if (typeof options === "function") { | ||
@@ -28,22 +34,21 @@ callback = options; | ||
} | ||
exports.parseString = parseString; | ||
function isElement(node) { | ||
return !!node.attributes; | ||
} | ||
class Parser { | ||
constructor(opts) { | ||
this.opts = options_1.overrideDefaultsWith(opts); | ||
var Parser = /** @class */ (function () { | ||
function Parser(opts) { | ||
this.opts = overrideDefaultsWith(opts); | ||
} | ||
tagName(nodeName) { | ||
return this.opts.tagNameProcessors.reduce((str, fn) => fn(str), this.opts.normalizeTags ? nodeName.toLowerCase() : nodeName); | ||
} | ||
parseString(xml, callback) { | ||
const parser = new DOMParser(); | ||
let obj; | ||
Parser.prototype.tagName = function (nodeName) { | ||
return this.opts.tagNameProcessors.reduce(function (str, fn) { return fn(str); }, this.opts.normalizeTags ? nodeName.toLowerCase() : nodeName); | ||
}; | ||
Parser.prototype.parseString = function (xml, callback) { | ||
var parser = new DOMParser(); | ||
var obj; | ||
try { | ||
const dom = parser.parseFromString(xml, "application/xml"); | ||
var dom = parser.parseFromString(xml, "application/xml"); | ||
throwIfError(dom); | ||
if (this.opts.explicitRoot) { | ||
const childName = this.tagName(dom.documentElement.nodeName); | ||
obj = { [childName]: this.domToObject(dom.childNodes[0]) }; | ||
var childName = this.tagName(dom.documentElement.nodeName); | ||
obj = (_a = {}, _a[childName] = this.domToObject(dom.childNodes[0]), _a); | ||
} | ||
@@ -59,15 +64,16 @@ else { | ||
callback(null, obj); | ||
} | ||
var _a; | ||
}; | ||
; | ||
parseAttributes(node) { | ||
Parser.prototype.parseAttributes = function (node) { | ||
if (this.opts.ignoreAttrs || !isElement(node) || !node.hasAttributes()) { | ||
return undefined; | ||
} | ||
const namespaceKey = (this.opts.attrkey || options_1.defaultAttrkey) + "ns"; | ||
const attrsObject = {}; | ||
var namespaceKey = (this.opts.attrkey || defaultAttrkey) + "ns"; | ||
var attrsObject = {}; | ||
if (isElement(node) && node.hasAttributes()) { | ||
for (let i = 0; i < node.attributes.length; i++) { | ||
const attr = node.attributes[i]; | ||
const attrName = this.opts.attrNameProcessors.reduce((str, fn) => fn(str), attr.nodeName); | ||
const attrValue = this.opts.attrValueProcessors.reduce((str, fn) => fn(str), attr.nodeValue); | ||
for (var i = 0; i < node.attributes.length; i++) { | ||
var attr = node.attributes[i]; | ||
var attrName = this.opts.attrNameProcessors.reduce(function (str, fn) { return fn(str); }, attr.nodeName); | ||
var attrValue = this.opts.attrValueProcessors.reduce(function (str, fn) { return fn(str); }, attr.nodeValue); | ||
if (this.opts.xmlns) { | ||
@@ -82,17 +88,17 @@ attrsObject[attrName] = { value: attrValue, local: attr.localName, uri: attr.namespaceURI }; | ||
return attrsObject; | ||
} | ||
domToObject(node) { | ||
}; | ||
Parser.prototype.domToObject = function (node) { | ||
if (node.childNodes.length === 0 && !(isElement(node) && node.hasAttributes())) { | ||
return this.opts.emptyTag; | ||
} | ||
const attrsObject = this.parseAttributes(node); | ||
const childkey = this.opts.childkey || options_1.defaultChildkey; | ||
const charkey = this.opts.charkey || options_1.defaultCharkey; | ||
let result = {}; | ||
let allTextContent = ''; | ||
for (let i = 0; i < node.childNodes.length; i++) { | ||
const child = node.childNodes[i]; | ||
var attrsObject = this.parseAttributes(node); | ||
var childkey = this.opts.childkey || defaultChildkey; | ||
var charkey = this.opts.charkey || defaultCharkey; | ||
var result = {}; | ||
var allTextContent = ''; | ||
for (var i = 0; i < node.childNodes.length; i++) { | ||
var child = node.childNodes[i]; | ||
if (child.nodeType === Node.TEXT_NODE || child.nodeType === Node.CDATA_SECTION_NODE) { | ||
const nodeValue = child.nodeValue || ''; | ||
const textContent = this.opts.normalize | ||
var nodeValue = child.nodeValue || ''; | ||
var textContent = this.opts.normalize | ||
? nodeValue.replace(/\n[ ]+\b/g, ' ').trim() | ||
@@ -103,3 +109,3 @@ : this.opts.trim | ||
allTextContent += textContent; | ||
const addTextChild = this.opts.explicitChildren && | ||
var addTextChild = this.opts.explicitChildren && | ||
this.opts.preserveChildrenOrder && | ||
@@ -112,8 +118,8 @@ this.opts.charsAsChildren && | ||
} | ||
result[childkey].push({ "#name": "__text__", [charkey]: textContent }); | ||
result[childkey].push((_a = { "#name": "__text__" }, _a[charkey] = textContent, _a)); | ||
} | ||
} | ||
else { | ||
const childObject = this.domToObject(child); | ||
const childName = this.tagName(child.nodeName); | ||
var childObject = this.domToObject(child); | ||
var childName = this.tagName(child.nodeName); | ||
if (!result[childName]) { | ||
@@ -133,6 +139,6 @@ result[childName] = this.opts.explicitArray ? [this.domToObject(child)] : this.domToObject(child); | ||
if (typeof childObject === "object") { | ||
result[childkey].push(Object.assign({ "#name": childName }, childObject)); | ||
result[childkey].push(__assign({ "#name": childName }, childObject)); | ||
} | ||
else { | ||
result[childkey].push({ "#name": childName, [charkey]: childObject }); | ||
result[childkey].push((_b = { "#name": childName }, _b[charkey] = childObject, _b)); | ||
} | ||
@@ -144,11 +150,11 @@ } | ||
// Consider passing down the processed tag name instead of recomputing it | ||
const childName = this.tagName(node.nodeName); | ||
return this.opts.valueProcessors.reduce((str, fn) => fn(str, childName), allTextContent); | ||
var childName_1 = this.tagName(node.nodeName); | ||
return this.opts.valueProcessors.reduce(function (str, fn) { return fn(str, childName_1); }, allTextContent); | ||
} | ||
// TODO: can this logic be simplified? | ||
const useExplicitChildrenObj = (this.opts.explicitChildren || this.opts.childkey) && | ||
var useExplicitChildrenObj = (this.opts.explicitChildren || this.opts.childkey) && | ||
!this.opts.preserveChildrenOrder && | ||
(Object.keys(result).length > 0 || (allTextContent && this.opts.charsAsChildren)); | ||
if (useExplicitChildrenObj) { | ||
result = { [childkey]: result }; | ||
result = (_c = {}, _c[childkey] = result, _c); | ||
} | ||
@@ -164,3 +170,3 @@ if ((allTextContent && this.opts.includeWhiteChars) || allTextContent.trim()) { | ||
if (this.opts.xmlns) { | ||
const namespaceKey = (this.opts.attrkey || options_1.defaultAttrkey) + "ns"; | ||
var namespaceKey = (this.opts.attrkey || defaultAttrkey) + "ns"; | ||
result[namespaceKey] = { local: node.localName, uri: node.namespaceURI }; | ||
@@ -171,3 +177,4 @@ } | ||
if (this.opts.explicitArray) { | ||
for (const key of Object.keys(attrsObject)) { | ||
for (var _i = 0, _d = Object.keys(attrsObject); _i < _d.length; _i++) { | ||
var key = _d[_i]; | ||
result[key] = [attrsObject[key]]; | ||
@@ -177,13 +184,15 @@ } | ||
else { | ||
result = Object.assign({}, result, attrsObject); | ||
result = __assign({}, result, attrsObject); | ||
} | ||
} | ||
else { | ||
result[this.opts.attrkey || options_1.defaultAttrkey] = attrsObject; | ||
result[this.opts.attrkey || defaultAttrkey] = attrsObject; | ||
} | ||
} | ||
return result; | ||
} | ||
} | ||
exports.Parser = Parser; | ||
var _a, _b, _c; | ||
}; | ||
return Parser; | ||
}()); | ||
export { Parser }; | ||
//# sourceMappingURL=parser.js.map |
@@ -1,7 +0,5 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.normalize = (str) => str.toLowerCase(); | ||
exports.firstCharLowerCase = (str) => str.charAt(0).toLowerCase() + str.slice(1); | ||
exports.stripPrefix = (str) => str.replace(/(?!xmlns)^.*:/, ''); | ||
exports.parseNumbers = (str) => { | ||
export var normalize = function (str) { return str.toLowerCase(); }; | ||
export var firstCharLowerCase = function (str) { return str.charAt(0).toLowerCase() + str.slice(1); }; | ||
export var stripPrefix = function (str) { return str.replace(/(?!xmlns)^.*:/, ''); }; | ||
export var parseNumbers = function (str) { | ||
if (!isNaN(str)) { | ||
@@ -12,3 +10,3 @@ str = str % 1 === 0 ? parseInt(str, 10) : parseFloat(str); | ||
}; | ||
exports.parseBooleans = (str) => { | ||
export var parseBooleans = function (str) { | ||
if (/^(?:true|false)$/i.test(str)) { | ||
@@ -15,0 +13,0 @@ str = str.toLowerCase() === 'true'; |
{ | ||
"name": "isomorphic-xml2js", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "XML parsing for browser and node.js", | ||
"main": "dist/lib/index.js", | ||
"main": "index.js", | ||
"browser": "dist/lib/browser.js", | ||
@@ -10,3 +10,3 @@ "types": "typings/lib/index.js", | ||
"build": "run-p build:nodejs build:browser", | ||
"build:nodejs": "tsc", | ||
"build:nodejs": "tsc -p tsconfig.es5.json", | ||
"build:browser": "webpack", | ||
@@ -35,4 +35,2 @@ "prepare": "npm run build", | ||
"@types/node": "^10.0.2", | ||
"@types/webpack": "^4.1.4", | ||
"@types/webpack-dev-middleware": "^2.0.1", | ||
"coffee-loader": "^0.9.0", | ||
@@ -56,5 +54,5 @@ "coffeescript": "^2.3.0", | ||
"dependencies": { | ||
"xml2js": "^0.4.19", | ||
"@types/xml2js": "^0.4.2" | ||
"@types/xml2js": "^0.4.2", | ||
"xml2js": "^0.4.19" | ||
} | ||
} |
@@ -11,4 +11,2 @@ # isomorphic-xml2js | ||
Note that the JavaScript in this library is targeting ES2017. If you want to target an earlier ES version when bundling, make sure you use something like [babel](https://github.com/babel/babel) in your bundler. | ||
## Limitations | ||
@@ -15,0 +13,0 @@ |
@@ -1,2 +0,2 @@ | ||
var xml2js=function(e){var t={};function s(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,s),o.l=!0,o.exports}return s.m=e,s.c=t,s.d=function(e,t,r){s.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},s.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="",s(s.s=3)}([function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const r={explicitRoot:!0,explicitArray:!0,emptyTag:"",strict:!0,tagNameProcessors:[],valueProcessors:[],attrNameProcessors:[],attrValueProcessors:[],xmldec:{version:"1.0",encoding:"UTF-8",standalone:!0}};t.defaultCharkey="_",t.defaultAttrkey="$",t.defaultChildkey="$$",t.overrideDefaultsWith=function(e){return Object.assign({},r,e,{xmldec:Object.assign({},r.xmldec,e&&e.xmldec)})}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const r=s(0),o=document.implementation.createDocument(null,null,null),i=new XMLSerializer;t.Builder=class{constructor(e){this.opts=r.overrideDefaultsWith(e)}buildAttributes(e){const t=[];for(const s of Object.keys(e)){const r=o.createAttribute(s);r.value=e[s].toString(),t.push(r)}return t}buildNode(e,t){const s=this.opts.attrkey||r.defaultAttrkey,i=this.opts.charkey||r.defaultCharkey,n=this.opts.childkey||r.defaultChildkey;if(void 0==e&&(e=this.opts.emptyTag||""),"string"==typeof e||"number"==typeof e||"boolean"==typeof e){const s=o.createElement(t.elementName);return s.textContent=e.toString(),[s]}if(Array.isArray(e)){const s=[];for(const r of e)for(const e of this.buildNode(r,t))s.push(e);return s}if("object"==typeof e){const r=o.createElement(t.elementName);for(const t of Object.keys(e))if(t===s)for(const s of this.buildAttributes(e[t]))r.attributes.setNamedItem(s);else if(t!==n||this.opts.explicitChildren&&this.opts.preserveChildrenOrder)if(t===i)r.appendChild(document.createTextNode(e[t]));else for(const s of this.buildNode(e[t],{elementName:t}))r.appendChild(s);else{const t=e[n];for(const e of Object.keys(t))for(const s of this.buildNode(t[e],{elementName:e}))r.appendChild(s)}return[r]}throw new Error(`Illegal value passed to buildObject: ${e}`)}buildObject(e){const t=this.opts.rootName||"root";if(Array.isArray(e)){const t={};for(const s of e)for(const e of Object.keys(s))t[e]||(t[e]=[]),t[e].push(s[e]);e=t}const s=Object.keys(e);let r;r=s.length<=1&&!this.opts.rootName&&this.opts.explicitRoot?this.buildNode(e[s[0]]||"",{elementName:s[0]||t})[0]:this.buildNode(e,{elementName:t})[0];let o=i.serializeToString(r);const n=this.opts.xmldec;return n&&!this.opts.headless&&(o=`<?xml version="${n.version}" encoding="${n.encoding}" standalone="${n.standalone?"yes":"no"}"?>`+o),o}}},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const r=s(0);let o;try{o=(new DOMParser).parseFromString("INVALID","text/xml").getElementsByTagName("parsererror")[0].namespaceURI}catch(e){}function i(e){return!!e.attributes}t.parseString=function(e,t,s){"function"==typeof t&&(s=t,t=void 0),new n(t).parseString(e,s)};class n{constructor(e){this.opts=r.overrideDefaultsWith(e)}tagName(e){return this.opts.tagNameProcessors.reduce((e,t)=>t(e),this.opts.normalizeTags?e.toLowerCase():e)}parseString(e,t){const s=new DOMParser;let r;try{const i=s.parseFromString(e,"application/xml");if(function(e){if(o){const t=e.getElementsByTagNameNS(o,"parsererror");if(t.length)throw new Error(t.item(0).innerHTML)}}(i),this.opts.explicitRoot){r={[this.tagName(i.documentElement.nodeName)]:this.domToObject(i.childNodes[0])}}else r=this.domToObject(i.childNodes[0])}catch(e){return void t(e)}t(null,r)}parseAttributes(e){if(this.opts.ignoreAttrs||!i(e)||!e.hasAttributes())return;this.opts.attrkey||r.defaultAttrkey;const t={};if(i(e)&&e.hasAttributes())for(let s=0;s<e.attributes.length;s++){const r=e.attributes[s],o=this.opts.attrNameProcessors.reduce((e,t)=>t(e),r.nodeName),i=this.opts.attrValueProcessors.reduce((e,t)=>t(e),r.nodeValue);this.opts.xmlns?t[o]={value:i,local:r.localName,uri:r.namespaceURI}:t[o]=i}return t}domToObject(e){if(!(0!==e.childNodes.length||i(e)&&e.hasAttributes()))return this.opts.emptyTag;const t=this.parseAttributes(e),s=this.opts.childkey||r.defaultChildkey,o=this.opts.charkey||r.defaultCharkey;let n={},a="";for(let t=0;t<e.childNodes.length;t++){const r=e.childNodes[t];if(r.nodeType===Node.TEXT_NODE||r.nodeType===Node.CDATA_SECTION_NODE){const e=r.nodeValue||"",t=this.opts.normalize?e.replace(/\n[ ]+\b/g," ").trim():this.opts.trim?e.trim():e;a+=t,this.opts.explicitChildren&&this.opts.preserveChildrenOrder&&this.opts.charsAsChildren&&(this.opts.includeWhiteChars||t.trim())&&(n[s]||(n[s]=[]),n[s].push({"#name":"__text__",[o]:t}))}else{const e=this.domToObject(r),t=this.tagName(r.nodeName);n[t]?Array.isArray(n[t])?n[t].push(e):n[t]=[n[t],this.domToObject(r)]:n[t]=this.opts.explicitArray?[this.domToObject(r)]:this.domToObject(r),this.opts.explicitChildren&&this.opts.preserveChildrenOrder&&(n[s]||(n[s]=[]),"object"==typeof e?n[s].push(Object.assign({"#name":t},e)):n[s].push({"#name":t,[o]:e}))}}if(!(0!==Object.keys(n).length||t||this.opts.explicitCharkey||this.opts.charkey||this.opts.xmlns)){const t=this.tagName(e.nodeName);return this.opts.valueProcessors.reduce((e,s)=>s(e,t),a)}const l=(this.opts.explicitChildren||this.opts.childkey)&&!this.opts.preserveChildrenOrder&&(Object.keys(n).length>0||a&&this.opts.charsAsChildren);if(l&&(n={[s]:n}),(a&&this.opts.includeWhiteChars||a.trim())&&(l&&this.opts.charsAsChildren?n[s][o]=a:n[o]=a),this.opts.xmlns){n[(this.opts.attrkey||r.defaultAttrkey)+"ns"]={local:e.localName,uri:e.namespaceURI}}if(t)if(this.opts.mergeAttrs)if(this.opts.explicitArray)for(const e of Object.keys(t))n[e]=[t[e]];else n=Object.assign({},n,t);else n[this.opts.attrkey||r.defaultAttrkey]=t;return n}}t.Parser=n},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const r=s(2);t.Parser=r.Parser,t.parseString=r.parseString;const o=s(1);t.Builder=o.Builder}]); | ||
var xml2js=function(t){var e={};function r(s){if(e[s])return e[s].exports;var o=e[s]={i:s,l:!1,exports:{}};return t[s].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,s){r.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:s})},r.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";r.r(e);var s=Object.assign||function(t){for(var e,r=1,s=arguments.length;r<s;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},o={explicitRoot:!0,explicitArray:!0,emptyTag:"",strict:!0,tagNameProcessors:[],valueProcessors:[],attrNameProcessors:[],attrValueProcessors:[],xmldec:{version:"1.0",encoding:"UTF-8",standalone:!0}};function i(t){return s({},o,t,{xmldec:s({},o.xmldec,t&&t.xmldec)})}var n,a=Object.assign||function(t){for(var e,r=1,s=arguments.length;r<s;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t};try{n=(new DOMParser).parseFromString("INVALID","text/xml").getElementsByTagName("parsererror")[0].namespaceURI}catch(t){}function l(t,e,r){"function"==typeof e&&(r=e,e=void 0),new h(e).parseString(t,r)}function c(t){return!!t.attributes}var h=function(){function t(t){this.opts=i(t)}return t.prototype.tagName=function(t){return this.opts.tagNameProcessors.reduce(function(t,e){return e(t)},this.opts.normalizeTags?t.toLowerCase():t)},t.prototype.parseString=function(t,e){var r,s,o=new DOMParser;try{var i=o.parseFromString(t,"application/xml");if(function(t){if(n){var e=t.getElementsByTagNameNS(n,"parsererror");if(e.length)throw new Error(e.item(0).innerHTML)}}(i),this.opts.explicitRoot)(s={})[this.tagName(i.documentElement.nodeName)]=this.domToObject(i.childNodes[0]),r=s;else r=this.domToObject(i.childNodes[0])}catch(t){return void e(t)}e(null,r)},t.prototype.parseAttributes=function(t){if(!this.opts.ignoreAttrs&&c(t)&&t.hasAttributes()){this.opts.attrkey;var e={};if(c(t)&&t.hasAttributes())for(var r=0;r<t.attributes.length;r++){var s=t.attributes[r],o=this.opts.attrNameProcessors.reduce(function(t,e){return e(t)},s.nodeName),i=this.opts.attrValueProcessors.reduce(function(t,e){return e(t)},s.nodeValue);this.opts.xmlns?e[o]={value:i,local:s.localName,uri:s.namespaceURI}:e[o]=i}return e}},t.prototype.domToObject=function(t){if(!(0!==t.childNodes.length||c(t)&&t.hasAttributes()))return this.opts.emptyTag;for(var e=this.parseAttributes(t),r=this.opts.childkey||"$$",s=this.opts.charkey||"_",o={},i="",n=0;n<t.childNodes.length;n++){var l=t.childNodes[n];if(l.nodeType===Node.TEXT_NODE||l.nodeType===Node.CDATA_SECTION_NODE){var h=l.nodeValue||"",p=this.opts.normalize?h.replace(/\n[ ]+\b/g," ").trim():this.opts.trim?h.trim():h;i+=p,this.opts.explicitChildren&&this.opts.preserveChildrenOrder&&this.opts.charsAsChildren&&(this.opts.includeWhiteChars||p.trim())&&(o[r]||(o[r]=[]),o[r].push(((f={"#name":"__text__"})[s]=p,f)))}else{var u=this.domToObject(l),d=this.tagName(l.nodeName);o[d]?Array.isArray(o[d])?o[d].push(u):o[d]=[o[d],this.domToObject(l)]:o[d]=this.opts.explicitArray?[this.domToObject(l)]:this.domToObject(l),this.opts.explicitChildren&&this.opts.preserveChildrenOrder&&(o[r]||(o[r]=[]),"object"==typeof u?o[r].push(a({"#name":d},u)):o[r].push(((v={"#name":d})[s]=u,v)))}}if(!(0!==Object.keys(o).length||e||this.opts.explicitCharkey||this.opts.charkey||this.opts.xmlns)){var m=this.tagName(t.nodeName);return this.opts.valueProcessors.reduce(function(t,e){return e(t,m)},i)}var f,v,y,g=(this.opts.explicitChildren||this.opts.childkey)&&!this.opts.preserveChildrenOrder&&(Object.keys(o).length>0||i&&this.opts.charsAsChildren);(g&&((y={})[r]=o,o=y),(i&&this.opts.includeWhiteChars||i.trim())&&(g&&this.opts.charsAsChildren?o[r][s]=i:o[s]=i),this.opts.xmlns)&&(o[(this.opts.attrkey||"$")+"ns"]={local:t.localName,uri:t.namespaceURI});if(e)if(this.opts.mergeAttrs)if(this.opts.explicitArray)for(var b=0,N=Object.keys(e);b<N.length;b++){var O=N[b];o[O]=[e[O]]}else o=a({},o,e);else o[this.opts.attrkey||"$"]=e;return o},t}(),p=document.implementation.createDocument(null,null,null),u=new XMLSerializer,d=function(){function t(t){this.opts=i(t)}return t.prototype.buildAttributes=function(t){for(var e=[],r=0,s=Object.keys(t);r<s.length;r++){var o=s[r],i=p.createAttribute(o);i.value=t[o].toString(),e.push(i)}return e},t.prototype.buildNode=function(t,e){var r=this.opts.attrkey||"$",s=this.opts.charkey||"_",o=this.opts.childkey||"$$";if(void 0==t&&(t=this.opts.emptyTag||""),"string"==typeof t||"number"==typeof t||"boolean"==typeof t)return(d=p.createElement(e.elementName)).textContent=t.toString(),[d];if(Array.isArray(t)){for(var i=[],n=0,a=t;n<a.length;n++)for(var l=a[n],c=0,h=this.buildNode(l,e);c<h.length;c++){var u=h[c];i.push(u)}return i}if("object"==typeof t){for(var d=p.createElement(e.elementName),m=0,f=Object.keys(t);m<f.length;m++){var v=f[m];if(v===r)for(var y=0,g=this.buildAttributes(t[v]);y<g.length;y++){var b=g[y];d.attributes.setNamedItem(b)}else if(v!==o||this.opts.explicitChildren&&this.opts.preserveChildrenOrder)if(v===s)d.appendChild(document.createTextNode(t[v]));else for(var N=0,O=this.buildNode(t[v],{elementName:v});N<O.length;N++){u=O[N];d.appendChild(u)}else for(var x=t[o],j=0,A=Object.keys(x);j<A.length;j++)for(var T=A[j],C=0,k=this.buildNode(x[T],{elementName:T});C<k.length;C++){var u=k[C];d.appendChild(u)}}return[d]}throw new Error("Illegal value passed to buildObject: "+t)},t.prototype.buildObject=function(t){var e=this.opts.rootName||"root";if(Array.isArray(t)){for(var r={},s=0,o=t;s<o.length;s++)for(var i=o[s],n=0,a=Object.keys(i);n<a.length;n++){var l=a[n];r[l]||(r[l]=[]),r[l].push(i[l])}t=r}var c,h=Object.keys(t);c=h.length<=1&&!this.opts.rootName&&this.opts.explicitRoot?this.buildNode(t[h[0]]||"",{elementName:h[0]||e})[0]:this.buildNode(t,{elementName:e})[0];var p=u.serializeToString(c),d=this.opts.xmldec;d&&!this.opts.headless&&(p='<?xml version="'+d.version+'" encoding="'+d.encoding+'" standalone="'+(d.standalone?"yes":"no")+'"?>'+p);return p},t}();r.d(e,"Parser",function(){return h}),r.d(e,"parseString",function(){return l}),r.d(e,"Builder",function(){return d})}]); | ||
//# sourceMappingURL=xml2jsBundle.js.map |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
28235
4.76%21
-8.7%18
5.88%443
4.48%0
-100%22
-8.33%