Comparing version 1.1.5 to 1.1.6
'use strict'; | ||
//Conversion tables for DOM Level1 structure emulation | ||
var nodeTypes = { | ||
element: 1, | ||
text: 3, | ||
cdata: 4, | ||
comment: 8 | ||
}; | ||
var nodePropertyShorthands = { | ||
tagName: 'name', | ||
childNodes: 'children', | ||
parentNode: 'parent', | ||
previousSibling: 'prev', | ||
nextSibling: 'next', | ||
nodeValue: 'data' | ||
}; | ||
//Node | ||
var Node = function (props) { | ||
for (var key in props) { | ||
if (props.hasOwnProperty(key)) | ||
this[key] = props[key]; | ||
} | ||
}; | ||
Node.prototype = { | ||
get firstChild() { | ||
var children = this.children; | ||
return children && children[0] || null; | ||
}, | ||
get lastChild() { | ||
var children = this.children; | ||
return children && children[children.length - 1] || null; | ||
}, | ||
get nodeType() { | ||
return nodeTypes[this.type] || nodeTypes.element; | ||
} | ||
}; | ||
Object.keys(nodePropertyShorthands).forEach(function (key) { | ||
var shorthand = nodePropertyShorthands[key]; | ||
Object.defineProperty(Node.prototype, key, { | ||
get: function () { | ||
return this[shorthand] || null; | ||
}, | ||
set: function (val) { | ||
this[shorthand] = val; | ||
return val; | ||
} | ||
}); | ||
}); | ||
//Node construction | ||
exports.createDocument = | ||
exports.createDocumentFragment = function () { | ||
return { | ||
return new Node({ | ||
type: 'root', | ||
@@ -13,3 +69,3 @@ name: 'root', | ||
children: [] | ||
}; | ||
}); | ||
}; | ||
@@ -30,6 +86,5 @@ | ||
return { | ||
return new Node({ | ||
type: tagName === 'script' || tagName === 'style' ? tagName : 'tag', | ||
name: tagName, | ||
tagName: tagName, | ||
namespace: namespaceURI, | ||
@@ -43,7 +98,7 @@ attribs: attribs, | ||
next: null | ||
}; | ||
}); | ||
}; | ||
exports.createCommentNode = function (data) { | ||
return { | ||
return new Node({ | ||
type: 'comment', | ||
@@ -54,7 +109,7 @@ data: data, | ||
next: null | ||
}; | ||
}); | ||
}; | ||
var createTextNode = function (value) { | ||
return { | ||
return new Node({ | ||
type: 'text', | ||
@@ -65,3 +120,3 @@ data: value, | ||
next: null | ||
} | ||
}); | ||
}; | ||
@@ -100,3 +155,3 @@ | ||
else { | ||
appendChild(document, { | ||
appendChild(document, new Node({ | ||
type: 'directive', | ||
@@ -108,3 +163,3 @@ name: '!doctype', | ||
'x-systemId': systemId | ||
}); | ||
})); | ||
} | ||
@@ -111,0 +166,0 @@ |
{ | ||
"name": "parse5", | ||
"description": "WHATWG HTML5 specification-compliant, fast and ready for production HTML parsing/serialization toolset for Node.", | ||
"version": "1.1.5", | ||
"version": "1.1.6", | ||
"author": "Ivan Nikulin <ifaaan@gmail.com> (https://github.com/inikulin)", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
375880
6135