chrome-dompath
Advanced tools
Comparing version 1.0.2 to 2.0.0
@@ -1,11 +0,3 @@ | ||
const JSDOM = require("jsdom").JSDOM; | ||
let Node; | ||
if (JSDOM) { | ||
Node = new JSDOM().window.Node; | ||
} else { | ||
Node = window.Node; | ||
} | ||
Node.prototype.nodeNameInCorrectCase = function() { | ||
const shadowRootType = this.shadowRootType(); | ||
module.exports.nodeNameInCorrectCase = function nodeNameInCorrectCase(node) { | ||
const shadowRootType = node.shadowRoot && node.shadowRoot.mode; | ||
if (shadowRootType) | ||
@@ -15,27 +7,27 @@ return '#shadow-root (' + shadowRootType + ')'; | ||
// If there is no local name, it's case sensitive | ||
if (!this.localName) | ||
return this.nodeName; | ||
if (!node.localName) | ||
return node.nodeName; | ||
// If the names are different lengths, there is a prefix and it's case sensitive | ||
if (this.localName.length !== this.nodeName.length) | ||
return this.nodeName; | ||
if (node.localName.length !== node.nodeName.length) | ||
return node.nodeName; | ||
// Return the localname, which will be case insensitive if its an html node | ||
return this.localName; | ||
return node.localName; | ||
} | ||
Node.prototype.ancestorShadowRoot = function() { | ||
return this.shadowRoot; | ||
module.exports.shadowRootType = function(node) { | ||
const ancestorShadowRoot = node.ancestorShadowRoot(); | ||
return ancestorShadowRoot ? ancestorShadowRoot.mode : null; | ||
} | ||
Node.prototype.ancestorShadowHost = function() { | ||
const ancestorShadowRoot = this.ancestorShadowRoot(); | ||
return ancestorShadowRoot ? ancestorShadowRoot.host : null; | ||
module.exports.NodeType = { | ||
ELEMENT_NODE: 1, | ||
ATTRIBUTE_NODE: 2, | ||
TEXT_NODE: 3, | ||
CDATA_SECTION_NODE: 4, | ||
PROCESSING_INSTRUCTION_NODE: 7, | ||
COMMENT_NODE: 8, | ||
DOCUMENT_NODE: 9 | ||
} | ||
Node.prototype.shadowRootType = function() { | ||
const ancestorShadowRoot = this.ancestorShadowRoot(); | ||
return ancestorShadowRoot ? ancestorShadowRoot.mode : null; | ||
} | ||
module.exports.ShadowRootTypes = { | ||
@@ -46,3 +38,1 @@ UserAgent: 'user-agent', | ||
}; | ||
module.exports.Node = Node; |
@@ -9,3 +9,3 @@ // This file taken from the ChromeDevTools repository and modified by rannn505 to make it work on JSDOM. | ||
require('css.escape'); | ||
const { Node, ShadowRootTypes } = require('./DOMNode'); | ||
const { ShadowRootTypes, nodeNameInCorrectCase, NodeType } = require('./DOMNode'); | ||
@@ -21,3 +21,3 @@ let Elements = {}; | ||
Elements.DOMPath.fullQualifiedSelector = function(node, justSelector) { | ||
if (node.nodeType !== Node.ELEMENT_NODE) | ||
if (node.nodeType !== NodeType.ELEMENT_NODE) | ||
return node.localName || node.nodeName.toLowerCase(); | ||
@@ -33,3 +33,3 @@ return Elements.DOMPath.cssPath(node, justSelector); | ||
Elements.DOMPath.cssPath = function(node, optimized) { | ||
if (node.nodeType !== Node.ELEMENT_NODE) | ||
if (node.nodeType !== NodeType.ELEMENT_NODE) | ||
return ''; | ||
@@ -60,5 +60,5 @@ | ||
while (wp) { | ||
if (wp.ancestorShadowRoot() && wp.ancestorShadowRoot().shadowRootType() !== ShadowRootTypes.Open) | ||
if (wp.shadowRoot && wp.shadowRoot.mode !== ShadowRootTypes.Open) | ||
return false; | ||
wp = wp.ancestorShadowHost(); | ||
wp = wp.shadowRoot && wp.shadowRoot.host; | ||
} | ||
@@ -74,3 +74,3 @@ return true; | ||
Elements.DOMPath.jsPath = function(node, optimized) { | ||
if (node.nodeType !== Node.ELEMENT_NODE) | ||
if (node.nodeType !== NodeType.ELEMENT_NODE) | ||
return ''; | ||
@@ -82,3 +82,3 @@ | ||
path.push(Elements.DOMPath.cssPath(wp, optimized)); | ||
wp = wp.ancestorShadowHost(); | ||
wp = wp.shadowRoot && wp.shadowRoot.host; | ||
} | ||
@@ -104,3 +104,3 @@ path.reverse(); | ||
Elements.DOMPath._cssPathStep = function(node, optimized, isTargetNode) { | ||
if (node.nodeType !== Node.ELEMENT_NODE) | ||
if (node.nodeType !== NodeType.ELEMENT_NODE) | ||
return null; | ||
@@ -114,5 +114,5 @@ | ||
if (nodeNameLower === 'body' || nodeNameLower === 'head' || nodeNameLower === 'html') | ||
return new Elements.DOMPath.Step(node.nodeNameInCorrectCase(), true); | ||
return new Elements.DOMPath.Step(nodeNameInCorrectCase(node), true); | ||
} | ||
const nodeName = node.nodeNameInCorrectCase(); | ||
const nodeName = nodeNameInCorrectCase(node); | ||
@@ -122,3 +122,3 @@ if (id) | ||
const parent = node.parentNode; | ||
if (!parent || parent.nodeType === Node.DOCUMENT_NODE) | ||
if (!parent || parent.nodeType === NodeType.DOCUMENT_NODE) | ||
return new Elements.DOMPath.Step(nodeName, true); | ||
@@ -157,3 +157,3 @@ | ||
const sibling = siblings[i]; | ||
if (sibling.nodeType !== Node.ELEMENT_NODE) | ||
if (sibling.nodeType !== NodeType.ELEMENT_NODE) | ||
continue; | ||
@@ -167,3 +167,3 @@ elementIndex += 1; | ||
continue; | ||
if (sibling.nodeNameInCorrectCase() !== nodeName) | ||
if (nodeNameInCorrectCase(sibling) !== nodeName) | ||
continue; | ||
@@ -210,3 +210,3 @@ | ||
Elements.DOMPath.xPath = function(node, optimized) { | ||
if (node.nodeType === Node.DOCUMENT_NODE) | ||
if (node.nodeType === NodeType.DOCUMENT_NODE) | ||
return '/'; | ||
@@ -242,3 +242,3 @@ | ||
switch (node.nodeType) { | ||
case Node.ELEMENT_NODE: | ||
case NodeType.ELEMENT_NODE: | ||
if (optimized && node.getAttribute('id')) | ||
@@ -248,16 +248,16 @@ return new Elements.DOMPath.Step('//*[@id="' + node.getAttribute('id') + '"]', true); | ||
break; | ||
case Node.ATTRIBUTE_NODE: | ||
case NodeType.ATTRIBUTE_NODE: | ||
ownValue = '@' + node.nodeName; | ||
break; | ||
case Node.TEXT_NODE: | ||
case Node.CDATA_SECTION_NODE: | ||
case NodeType.TEXT_NODE: | ||
case NodeType.CDATA_SECTION_NODE: | ||
ownValue = 'text()'; | ||
break; | ||
case Node.PROCESSING_INSTRUCTION_NODE: | ||
case NodeType.PROCESSING_INSTRUCTION_NODE: | ||
ownValue = 'processing-instruction()'; | ||
break; | ||
case Node.COMMENT_NODE: | ||
case NodeType.COMMENT_NODE: | ||
ownValue = 'comment()'; | ||
break; | ||
case Node.DOCUMENT_NODE: | ||
case NodeType.DOCUMENT_NODE: | ||
ownValue = ''; | ||
@@ -273,3 +273,3 @@ break; | ||
return new Elements.DOMPath.Step(ownValue, node.nodeType === Node.DOCUMENT_NODE); | ||
return new Elements.DOMPath.Step(ownValue, node.nodeType === NodeType.DOCUMENT_NODE); | ||
}; | ||
@@ -287,3 +287,3 @@ | ||
if (left.nodeType === Node.ELEMENT_NODE && right.nodeType === Node.ELEMENT_NODE) | ||
if (left.nodeType === NodeType.ELEMENT_NODE && right.nodeType === NodeType.ELEMENT_NODE) | ||
return left.localName === right.localName; | ||
@@ -295,4 +295,4 @@ | ||
// XPath treats CDATA as text nodes. | ||
const leftType = left.nodeType === Node.CDATA_SECTION_NODE ? Node.TEXT_NODE : left.nodeType; | ||
const rightType = right.nodeType === Node.CDATA_SECTION_NODE ? Node.TEXT_NODE : right.nodeType; | ||
const leftType = left.nodeType === NodeType.CDATA_SECTION_NODE ? NodeType.TEXT_NODE : left.nodeType; | ||
const rightType = right.nodeType === NodeType.CDATA_SECTION_NODE ? NodeType.TEXT_NODE : right.nodeType; | ||
return leftType === rightType; | ||
@@ -299,0 +299,0 @@ } |
{ | ||
"name": "chrome-dompath", | ||
"version": "1.0.2", | ||
"version": "2.0.0", | ||
"description": "Chrome DevTools DOMPath implementation", | ||
@@ -35,3 +35,2 @@ "main": "lib/DOMPath.js", | ||
"dependencies": { | ||
"jsdom": "^15.1.1", | ||
"css.escape": "^1.5.1" | ||
@@ -41,2 +40,3 @@ }, | ||
"chai": "^4.2.0", | ||
"jsdom": "^15.1.1", | ||
"mocha": "^6.1.4", | ||
@@ -43,0 +43,0 @@ "nyc": "^14.1.1" |
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
1
16354
4
367
- Removedjsdom@^15.1.1
- Removedabab@2.0.6(transitive)
- Removedacorn@6.4.27.4.1(transitive)
- Removedacorn-globals@4.3.4(transitive)
- Removedacorn-walk@6.2.0(transitive)
- Removedajv@6.12.6(transitive)
- Removedarray-equal@1.0.2(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedbrowser-process-hrtime@1.0.0(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removedcssom@0.3.80.4.4(transitive)
- Removedcssstyle@2.3.0(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddata-urls@1.1.0(transitive)
- Removeddeep-is@0.1.4(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removeddomexception@1.0.1(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedescodegen@1.14.3(transitive)
- Removedesprima@4.0.1(transitive)
- Removedestraverse@4.3.0(transitive)
- Removedesutils@2.0.3(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedfast-levenshtein@2.0.6(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhtml-encoding-sniffer@1.0.2(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removediconv-lite@0.4.24(transitive)
- Removedip-regex@2.1.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjsdom@15.2.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedlevn@0.3.0(transitive)
- Removedlodash@4.17.21(transitive)
- Removedlodash.sortby@4.7.0(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removednwsapi@2.2.13(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedoptionator@0.8.3(transitive)
- Removedparse5@5.1.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpn@1.1.0(transitive)
- Removedprelude-ls@1.1.2(transitive)
- Removedpsl@1.10.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedrequest-promise-core@1.1.4(transitive)
- Removedrequest-promise-native@1.0.9(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsaxes@3.1.11(transitive)
- Removedsource-map@0.6.1(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedstealthy-require@1.1.1(transitive)
- Removedsymbol-tree@3.2.4(transitive)
- Removedtough-cookie@2.5.03.0.1(transitive)
- Removedtr46@1.0.1(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removedtype-check@0.3.2(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)
- Removedw3c-hr-time@1.0.2(transitive)
- Removedw3c-xmlserializer@1.1.2(transitive)
- Removedwebidl-conversions@4.0.2(transitive)
- Removedwhatwg-encoding@1.0.5(transitive)
- Removedwhatwg-mimetype@2.3.0(transitive)
- Removedwhatwg-url@7.1.0(transitive)
- Removedword-wrap@1.2.5(transitive)
- Removedws@7.5.10(transitive)
- Removedxml-name-validator@3.0.0(transitive)
- Removedxmlchars@2.2.0(transitive)