dom-parser
Advanced tools
Comparing version 0.0.2 to 0.1.0
@@ -23,2 +23,3 @@ var | ||
fullNodeName, | ||
selfCloseTag, | ||
attributes, | ||
@@ -44,2 +45,3 @@ attrBuffer, | ||
if (startTagExp.test(tag)) { | ||
selfCloseTag = selfCloseTagExp.test(tag) || noClosingTagsExp.test(fullNodeName[1]); | ||
attributes = []; | ||
@@ -62,3 +64,4 @@ attrStr = tag.match(attrRegExp) || []; | ||
parentNode: currentObject, | ||
startTag: tag | ||
startTag: tag, | ||
selfCloseTag: selfCloseTag | ||
})); | ||
@@ -71,3 +74,3 @@ tagsCount++; | ||
if (selfCloseTagExp.test(tag) || noClosingTagsExp.test(fullNodeName[1])) { | ||
if (selfCloseTag) { | ||
tagsCount--; | ||
@@ -81,3 +84,2 @@ } | ||
else if (closeTagExp.test(tag)) { | ||
currentObject.closeTag = tag; | ||
currentObject = currentObject.parentNode; | ||
@@ -84,0 +86,0 @@ tagsCount--; |
@@ -6,4 +6,5 @@ //https://developer.mozilla.org/en-US/docs/Web/API/Element | ||
this.namespace = cfg.namespace || null; | ||
this.text = cfg.text; | ||
this.namespace = cfg.namespace || null; | ||
this.text = cfg.text; | ||
this._selfCloseTag = cfg.selfCloseTag; | ||
@@ -16,3 +17,3 @@ | ||
nodeName: { | ||
value: cfg.nodeType == 1 ? cfg.nodeName : '#text' //todo: refactor this | ||
value: cfg.nodeType == 1 ? cfg.nodeName : '#text' | ||
}, | ||
@@ -45,8 +46,46 @@ childNodes: { | ||
cNode = this.childNodes[i]; | ||
result += cNode.nodeType === 3 ? cNode.text : cNode.outerHTML(); | ||
result += cNode.nodeType === 3 ? cNode.text : cNode.outerHTML; | ||
} | ||
return result; | ||
} | ||
}, | ||
outerHTML: { | ||
get: function(){ | ||
if (this.nodeType != 3){ | ||
var | ||
str, | ||
attrs = (this.attributes.map(function(elem){ | ||
return elem.name + (elem.value ? '=' + '"'+ elem.value +'"' : ''); | ||
}) || []).join(' '), | ||
childs = ''; | ||
str = '<' + this.nodeName + (attrs ? ' ' + attrs : '') + (this._selfCloseTag ? '/' : '') + '>'; | ||
if (!this._selfCloseTag){ | ||
childs = (this._selfCloseTag ? '' : this.childNodes.map(function(child){ | ||
return child.outerHTML; | ||
}) || []).join(''); | ||
str += childs; | ||
str += '</' + this.nodeName + '>'; | ||
} | ||
} | ||
else{ | ||
str = this.textContent; | ||
} | ||
return str; | ||
} | ||
}, | ||
textContent: { | ||
get: function(){ | ||
if (this.nodeType == Node.TEXT_NODE){ | ||
return this.text; | ||
} | ||
else{ | ||
return this.childNodes.map(function(node){ | ||
return node.textContent; | ||
}).join('').replace(/\x20+/g, ' '); | ||
} | ||
} | ||
} | ||
}); | ||
@@ -106,2 +145,6 @@ } | ||
Node.ELEMENT_NODE = 1; | ||
Node.TEXT_NODE = 3; | ||
module.exports = Node; |
{ | ||
"name": "dom-parser", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "Fast dom parser based on regexps", | ||
@@ -18,3 +18,4 @@ "keywords": [ | ||
"mocha": "2.3.x", | ||
"chai": "2.1.x" | ||
"chai": "2.1.x", | ||
"dom-compare": "git://github.com/user/project.git" | ||
}, | ||
@@ -21,0 +22,0 @@ "scripts": { |
@@ -45,2 +45,4 @@ # dom-parser | ||
* innerHTML | ||
* outerHTML | ||
* textContent | ||
@@ -47,0 +49,0 @@ Implemented methods |
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
26755
15
700
61
0
3