Gathering detailed insights and metrics for potent-tools
Gathering detailed insights and metrics for potent-tools
Gathering detailed insights and metrics for potent-tools
Gathering detailed insights and metrics for potent-tools
npm install potent-tools
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
4 Stars
52 Commits
1 Forks
2 Watching
1 Branches
1 Contributors
Updated on 27 May 2023
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
0%
4
Compared to previous week
Last month
-71.2%
17
Compared to previous month
Last year
17.5%
389
Compared to previous year
Tools for working with the DOM, CSS selectors and XPath 1.0 expressions. All functionality in this repository is derived from Firebug, and has been modified for readability and to support pseudo-DOM, unit testing and ES6 standards.
This package solves four loosely related problems:
"body.thing"
-> { element: body, class: thing }
).yarn add potent-tools
1const {
2 generators,
3 evaluators,
4 cssToXPath
5} = require('potent-tools');
6
7{ // generators: generate XPath queries from elements.
8 /*
9 * generators.getElementXPath(element)
10 * Get the XPath string for a given DOM element.
11 */
12 const xPath = generators.getElementXPath(domElement);
13 // /html/head/body/table/tr[2]/td/strong[@class='title']
14 console.log(xPath);
15
16
17 /*
18 * generators.getElementXPath(element, skipId)
19 * Get the fully qualified XPath string for a DOM element
20 * that has an ID, ignoring ID.
21 * e.g., `<html><body><div id='bob'></div></body></html>`
22 */
23 const xPath = generators.getElementXPath(
24 bobElement,
25 skipId = true
26 );
27 console.log(xPath); // /html/body/div[1]
28
29
30 const xPath = generators.getElementXPath(
31 bobElement,
32 skipId = false
33 );
34 console.log(xPath); // //*[@id='bob']
35
36
37 /*
38 * generators.getElementAttributes(element)
39 * Get all the HTML attributes on an element.
40 * This is exposed, but it is a support method for the XPath
41 * generator.
42 */
43 const attributes = generators.getElementAttributes(bobElement);
44 console.log(bobElement); // { id: 'bob' }
45}
46
47{ // evaluators: run XPath queries or CSS selectors to find elements
48 /*
49 * evaluators.getElementsByXPath(document, xpathQuery)
50 * Get elements by XPath query.
51 */
52 // element return type...
53 const elements = evaluators.getElementsByXPath(
54 document,
55 '/html/body/div'
56 );
57 console.log(elements); // [ DOMElement ]
58
59 // string return type...
60 const elements = evaluators.getElementsByXPath(
61 document,
62 '/html/body/div/text()'
63 );
64 console.log(elements); // [ "Hello world" ]
65
66 /*
67 * getElementsBySelector(document, rule)
68 * Get elements by CSS selector.
69 */
70 const elements = evaluators
71 .getElementsBySelector(
72 document,
73 'html > body > div#id'
74 );
75 console.log(elements); // [ DOMElement ]
76
77 /*
78 * evaluators.evaluateXPath(doc, xpath, contextNode, resultType)
79 * Execute a query on a document.
80 * e.g., <html><body><div id='bob'>Hello world</div></body></html>
81 */
82 const stringResult = evaluators.evaluateXPath(
83 document,
84 '/html/body/div',
85 document, // optional, defaults to the document
86 XPathResult.STRING_TYPE, // optional, defaults to ANY_TYPE.
87 );
88 console.log(stringResult); // "Hello world"
89}
90
91{ // cssToXPath: convert CSS queries to XPath queries
92 console.log(cssToXPath('html > body')); // //html>body
93}
94
95
We have some tests that document this functionality as well. It should be possible to use our builds on the web as well, as they simply ignore the polyfills if they're already present.
As the code in this repository is derived from the Firebug source code, its BSD 3-clause license applies.
I will accept pull requests which do not deviate from the intent of the original Firebug code, as the intent of this repository is simply to cleanup, standardize and package the Firebug XPath library for reuse.
yarn test
).yarn run coverage
).To build a web distribution, yarn run build
should update the files in dist/
.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/27 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
74 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More