New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

easy-xml-parser

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easy-xml-parser - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

1

lib/index.d.ts
export declare const xmlToJson: (xmlString: string) => any;
export declare const jsonToXml: (obj: any) => string;
"use strict";
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
Object.defineProperty(exports, "__esModule", { value: true });
// tslint:disable-next-line: no-var-requires
var xmldoc = require("xmldoc");
var xmldoc_1 = require("xmldoc");
exports.xmlToJson = function (xmlString) {
var document = new xmldoc.XmlDocument(xmlString);
var document = new xmldoc_1.XmlDocument(xmlString);
var parseNodeValue = function (node) {

@@ -11,3 +17,3 @@ var nodeObj = {};

if (node.val.trim().length > 0) {
nodeObj.text = node.val;
return node.val;
}

@@ -35,1 +41,66 @@ node.children.forEach(function (children) {

};
var literalTypes = ["string", "number", "bigint", "boolean"];
exports.jsonToXml = function (obj) {
function objEntries(entryObj) {
return Object.entries(entryObj).filter(function (_a) {
var key = _a[0], value = _a[1];
return typeof value !== "function" && typeof value !== "symbol";
});
}
function escapeString(str) {
return str
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
}
function prepareEntries(entries) {
return objEntries(entries).map(prepareEntry);
}
function prepareEntry(_a) {
var name = _a[0], value = _a[1];
var attr = [];
var children = [];
var type = typeof value;
if (value === null || value === undefined) {
return "<" + name + " />";
}
if (literalTypes.includes(type)) {
if (type === "string") {
return "<" + name + ">" + escapeString(value) + "</" + name + ">";
}
else {
return "<" + name + ">" + value + "</" + name + ">";
}
}
if (Array.isArray(value)) {
return value.map(function (val) { return prepareEntry([name, val]); }).join("");
}
if (type === "object") {
objEntries(value).forEach(function (_a) {
var key = _a[0], val = _a[1];
if (literalTypes.includes(typeof val) || val === null || val === undefined) {
attr.push([key, val + ""]);
}
else if (Array.isArray(val)) {
val.forEach(function (v) { return children.push(prepareEntry([key, v])); });
}
else if (typeof val === "object") {
prepareEntries(val).forEach(function (str) { return children.push(str); });
}
});
}
var attributes = attr.map(function (_a) {
var key = _a[0], val = _a[1];
return key + "=\"" + escapeString(val) + "\"";
});
if (children.length > 0) {
return "<" + __spreadArrays([name], attributes).join(" ") + ">" + children.join("") + "</" + name + ">";
}
else {
return "<" + __spreadArrays([name], attributes).join(" ") + " />";
}
}
return prepareEntries(obj).join("");
};

2

package.json
{
"name": "easy-xml-parser",
"version": "1.0.1",
"version": "1.0.2",
"description": "An ultimate tool to parse XMl int JSON format, with awesome result.",

@@ -5,0 +5,0 @@ "author": "Profesor08",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc