Installations
npm install csstoxpath
Releases
Unable to fetch releases
Developer
peteboere
Developer Guide
Module System
ESM
Min. Node Version
>=18
Typescript Support
No
Node Version
18.18.2
NPM Version
9.8.1
Statistics
7 Stars
24 Commits
1 Forks
2 Watching
1 Branches
1 Contributors
Updated on 12 Jun 2024
Bundle Size
11.27 kB
Minified
4.35 kB
Minified + Gzipped
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
2,869,493
Last day
38.9%
29,165
Compared to previous day
Last week
17.5%
139,249
Compared to previous week
Last month
40.7%
540,025
Compared to previous month
Last year
11,779.5%
2,802,016
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Dev Dependencies
3
CSS to XPath
Converts most CSS 2.1/3 selectors (see exclusions below) to equivalent XPath 1.0 expression.
See test.js
for examples.
Extension pseudos
To take advantage of the different capabilities of XPath some additional pseudo selectors have been implemented:
:text
All text matching pseudo classes normalize whitespace and ignore tags.
E.g. " my <i>string</i> "
is treated as "my string"
.
:text("foo")
Case-insensitive matching of element text:text-case("foo")
Case-sensitive:text-case
:text-contains("foo")
Case-insensitive substring matching of element text:text-contains-case("foo")
Case-sensitive:text-contains
:text-start("foo")
Case-insensitive matching of element starting text:text-start-case("foo")
Case-sensitive:text-start
:text-end("foo")
Case-insensitive matching of element ending text:text-end-case("foo")
Case-sensitive:text-end
:any
Selectors containing multiple options, any one of which will be matched:
E.g: div :any(ol, ul, dl) > *
equates to div ol > *, div ul > *, div dl > *
:comment
:comment
Select comment nodes:comment(n)
Select comment nodes at child positionn
Note: Can be combined with :text
to match based on comment text content. E.g. p > :comment:text("foo")
:childless
As :empty
but ignoring whitespace.
Aliased pseudos
:first
is aliased to:first-child
:last
is aliased to:last-child
:child
is aliased to:nth-child
:contains
is aliased to:text-contains
Author pseudos
Authored pseudos can serve as aliases to help simplify selector chains:
1/* 2 * If the `pseudos` option is set the CSS expression is 3 * preprocessed before generating the XPath expression: 4 * 5 * :radio 6 * => input[type="radio"] 7 * 8 * :element-1(Hello) 9 * => element:child(1):contains("Hello") 10 */ 11const cssToXpath = require('csstoxpath'); 12const xpathExpr = cssToXpath(':radio, :element-1(Hello)', { 13 pseudos: { 14 radio: 'input[type="radio"]', 15 [/element-(\d+)/]: (data, m) => `element:child(${m[1]}):contains("${data}")`, 16 } 17});
Limitations
The following pseudos are partially supported as they require a tag context:
:nth-of-type
:first-of-type
:last-of-type
The following pseudos are currently unsupported:
:nth-last-child
:nth-last-of-type
Dynamic pseudos are excluded as they can only be partially supported by attribute matching:
:checked
:disabled
:enabled
:required
:lang
The following cannot be implemented in XPath 1.0:
- States:
:hover
,:focus
,:active
,:visited
,:target
etc. - Elements:
::before
,::after
,::first-letter
etc.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
1 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/24 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
2.5
/10
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