Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chrome-dompath

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

chrome-dompath - npm Package Compare versions

Comparing version 1.0.2 to 2.0.0

46

lib/DOMNode.js

@@ -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"

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