New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

xml2node

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xml2node - npm Package Compare versions

Comparing version
1.0.1
to
1.0.2
+194
-54
dist/Xml2Node.js

@@ -10,2 +10,4 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Xml2Node = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){

},{"./src/Xml2Node.js":2,"./src/XmlNode.js":3}],2:[function(require,module,exports){
var XmlNode = require("./XmlNode.js");
var Xml2Node =

@@ -17,45 +19,8 @@ (function () {

this.parser = new DOMParser();
// this.xml=new XmlNode();
this._test();
}
Xml2Node.prototype._test = function () {
var me = this;
var xml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<opml version="2.0">' +
' <head>' +
' <title>タイトル</title>' +
' <flavor>RSSアプリ</flavor>' +
' <source>https://example.com</source>' +
' </head>' +
' <body>' +
' <outline text="挨拶">' +
' <outline text="朝は、おはよう"/>' +
' <outline text="昼は、こんにちは"/>' +
' <outline text="夜は、こんばんは"/>' +
' </outline>' +
' <outline text="お礼">' +
' <outline text="ありがとう"/>' +
' <outline text="サンキュー"/>' +
' </outline>' +
' </body>' +
'</opml>';
// alert(Face)
var jso = me.parseXML(xml);
console.log(JSON.stringify(jso));
// console.log(jso.opml[0].children.head[0].children.title[0].value);
// alert(new XQ(jso).get("opml").get("head").get("title").value());
// alert(new XmlNode(jso).get("opml").attr("version"));
// alert(new XmlNode(jso).get("opml").get("body").get("outline").get("outline", 0).attr("text"));
// alert(new XQ(jso).get("opml").get("body1").get("outline1").numOfChildren("outline"));
}
/**
* 指定されてxmlテキストをパースする
* @param xmlText XMLテキスト
* Parse specified XML text
* @param xmlText XML text
* @returns {{children: {}}}

@@ -69,3 +34,3 @@ */

var model = {};
me._parseInternally(doc.children[0], model);
me._parseInternally(doc.children[0], model, {stack: [], index: []});

@@ -77,5 +42,7 @@ return {

Xml2Node.prototype._parseInternally = function (element, model) {
Xml2Node.prototype._parseInternally = function (element, model, parentElementModel) {
var me = this;
//model["body"]=[];
//model["body"][0]={tagName:"body",value="hogehoge",children:[],attr={}};

@@ -86,18 +53,51 @@ if (!model[element.tagName]) {

var elementModel = {};
if (element.nodeName == "#comment") {
//-if element node is comment node
return;
}
if (element.nodeName == "#text") {
//-if element node is text node
var blankReplacedElementContent = element.textContent.replace(/ /g, '').replace(/\r?\n/g, '').replace(/\n/g, '').replace(/\t/g, '');
if (blankReplacedElementContent.length == 0) {
//-if text node is empty
} else {
//-if text node is not empty
parentElementModel.value = element.textContent;
}
return;
}
var elementModel =
{
tagName: null,
children: null,
attr: null
};
elementModel.tagName = element.tagName;
model[element.tagName].push(elementModel);
var isIndependentNode = !(element.children.length > 0);
var elementHasValueOrChildren = (element.children.length > 0);
if (isIndependentNode) {
if (elementHasValueOrChildren) {
elementModel.children = {};
} else {
if (element.textContent && element.textContent.length > 0) {
elementModel.value = element.textContent;
return;
}
} else {
elementModel.children = {};
}
//start of handling attributes
var attrsModel;
if (element.attributes.length > 0) {

@@ -108,2 +108,3 @@ attrsModel = {};

for (var i = 0; i < element.attributes.length; i++) {
var attr = element.attributes[i];

@@ -120,10 +121,121 @@

attrsModel[attrModel.name].push(attrModel);
}
elementModel.attr = attrsModel;
//end of handling attribute
for (var i = 0; i < element.children.length; i++) {
me._parseInternally(element.children[i], elementModel.children);
for (var i = 0; i < element.childNodes.length; i++) {
var child = element.childNodes[i];
me._parseInternally(child, elementModel.children, elementModel);
}
};
Xml2Node.prototype.generateExampleSourceCode = function (xmlText) {
var me = this;
var jsObject = me.parseXML(xmlText);
var node = new XmlNode(jsObject);
var hintCodeBase =
"var parser = new Xml2Node.Parser();\n" +
"var jsObject = parser.parseXML(xml);\n" +
"var node=new Xml2Node.Node(jsObject);\n";
var hint = {stack: [], hintCode: hintCodeBase};
me._generateExampleSourceCode(node, hint);
return hint.hintCode;
};
/**
* Generate an example of parsing XML into JS code.
* @param node
* @param hint
* @private
*/
Xml2Node.prototype._generateExampleSourceCode = function (node, hint) {
var me = this;
var printWithValue = true;
var hintCodePrefix = "console.log(node";
var hintCodeSuffix = ");";
var tagNames = node.getChildTagNames();
for (var idx = 0; idx < tagNames.length; idx++) {
var childTagName = tagNames[idx];
var childCount = node.getNumOfChildren(childTagName);
for (var i = 0; i < childCount; i++) {
var childNode = node.get(childTagName, i);
var hintStr = ".get(\"" + childNode.getTagName() + "\"";
if (childCount - 1 > 0) {
hintStr += "," + i + "";
}
hintStr += ")";
hint.stack.push(hintStr);
var _tmpStr = "";
for (var j in hint.stack) {
_tmpStr += hint.stack[j];
}
//start of handling attribute
var childNodeAttrNames = childNode.getAttrNames();
if (childNodeAttrNames.length > 0) {
for (var attrIdx in childNodeAttrNames) {
var childNodeAttrName = childNodeAttrNames[attrIdx];
var attrStr = hintCodePrefix + _tmpStr + '.attr("' + childNodeAttrName + '")';
attrStr += hintCodeSuffix;
if (printWithValue) {
attrStr += " // -> " + childNode.attr(childNodeAttrName);
}
//add attribute showing code
hint.hintCode += attrStr + "\n";
}
}
if ((typeof(childNode.value()) !== "undefined")) {
var valueStr = hintCodePrefix + _tmpStr + ".value()";
valueStr += hintCodeSuffix;
if (printWithValue) {
valueStr += " // ->" + childNode.value();
}
//add value showing code
hint.hintCode += valueStr + "\n";
}
me._generateExampleSourceCode(childNode, hint);
hint.stack.pop();
}
}
};
return Xml2Node;

@@ -135,4 +247,3 @@

module.exports = Xml2Node;
},{}],3:[function(require,module,exports){
},{"./XmlNode.js":3}],3:[function(require,module,exports){
var XmlNode =

@@ -146,2 +257,7 @@ (function () {

XmlNode.prototype.getTagName = function () {
var me = this;
return me.node.tagName;
};
XmlNode.prototype.get = function (name, index) {

@@ -165,4 +281,15 @@ var me = this;

XmlNode.prototype.numOfChildren = function (name) {
XmlNode.prototype.getChildTagNames = function () {
var me = this;
var tagNames = [];
for (var key in me.node.children) {
tagNames.push(key);
}
return tagNames;
}
XmlNode.prototype.getNumOfChildren = function (name) {
var me = this;
if (me.node.children && me.node.children[name]) {

@@ -175,8 +302,9 @@ return me.node.children[name].length;

XmlNode.prototype.hasChild = function (name) {
XmlNode.prototype.hasChildOf = function (name) {
var me = this;
return (me.numOfChildren(name) > 0);
return (me.getNumOfChildren(name) > 0);
};
XmlNode.prototype.value = function (name) {
XmlNode.prototype.value = function () {
var me = this;

@@ -210,3 +338,15 @@ return me.node.value;

XmlNode.prototype.getAttrNames = function () {
var me = this;
var attrNames = [];
if (me.node.attr) {
for (var key in me.node.attr) {
attrNames.push(key);
}
}
return attrNames;
};
return XmlNode;

@@ -213,0 +353,0 @@

@@ -0,0 +0,0 @@ var Xml2Node = require('./src/Xml2Node.js');

@@ -0,0 +0,0 @@ MIT License

{
"name": "xml2node",
"version": "1.0.1",
"version": "1.0.2",
"description": "Simple and easy XML parser",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -0,0 +0,0 @@ # Overview

@@ -30,5 +30,8 @@ var XmlNode = require("./XmlNode.js");

Xml2Node.prototype._parseInternally = function (element, model) {
Xml2Node.prototype._parseInternally = function (element, model, parentElementModel) {
var me = this;
//model["body"]=[];
//model["body"][0]={tagName:"body",value="hogehoge",children:[],attr={}};
if (!model[element.tagName]) {

@@ -38,3 +41,30 @@ model[element.tagName] = [];

var elementModel = {};
if (element.nodeName == "#comment") {
//-if element node is comment node
return;
}
if (element.nodeName == "#text") {
//-if element node is text node
var blankReplacedElementContent = element.textContent.replace(/ /g, '').replace(/\r?\n/g, '').replace(/\n/g, '').replace(/\t/g, '');
if (blankReplacedElementContent.length == 0) {
//-if text node is empty
} else {
//-if text node is not empty
parentElementModel.value = element.textContent;
}
return;
}
var elementModel =
{
tagName: null,
children: null,
attr: null
};
elementModel.tagName = element.tagName;

@@ -45,10 +75,11 @@

var isIndependentNode = !(element.children.length > 0);
var elementHasValueOrChildren = (element.children.length > 0);
if (isIndependentNode) {
if (elementHasValueOrChildren) {
elementModel.children = {};
} else {
if (element.textContent && element.textContent.length > 0) {
elementModel.value = element.textContent;
return;
}
} else {
elementModel.children = {};
}

@@ -60,2 +91,3 @@

if (element.attributes.length > 0) {

@@ -78,2 +110,3 @@ attrsModel = {};

attrsModel[attrModel.name].push(attrModel);
}

@@ -84,8 +117,6 @@ elementModel.attr = attrsModel;

for (var i = 0; i < element.children.length; i++) {
var child = element.children[i];
me._parseInternally(child, elementModel.children);
for (var i = 0; i < element.childNodes.length; i++) {
var child = element.childNodes[i];
me._parseInternally(child, elementModel.children, elementModel);
}
//

@@ -135,2 +166,3 @@

var childCount = node.getNumOfChildren(childTagName);

@@ -170,3 +202,2 @@

//add attribute showing code

@@ -177,4 +208,5 @@ hint.hintCode += attrStr + "\n";

}
if (childNode.getChildTagNames().length == 0 && (typeof(childNode.value()) !== "undefined")) {
if ((typeof(childNode.value()) !== "undefined")) {
var valueStr = hintCodePrefix + _tmpStr + ".value()";

@@ -181,0 +213,0 @@ valueStr += hintCodeSuffix;

@@ -0,0 +0,0 @@ var XmlNode =

Sorry, the diff of this file is not supported yet