https://github.com/gburtini/css-xpath
npm module for translating CSS rules in to XPath expressions
https://github.com/gburtini/css-xpath
css-selector xpath-query
Last synced: 5 months ago
JSON representation
npm module for translating CSS rules in to XPath expressions
- Host: GitHub
- URL: https://github.com/gburtini/css-xpath
- Owner: gburtini
- Created: 2017-05-20T20:25:38.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-20T20:33:20.000Z (about 9 years ago)
- Last Synced: 2025-10-30T10:46:27.369Z (8 months ago)
- Topics: css-selector, xpath-query
- Language: JavaScript
- Size: 10.7 KB
- Stars: 2
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
css-xpath
====================
[](https://travis-ci.org/gburtini/css-xpath) [](https://snyk.io/test/github/gburtini/css-xpath) [](https://badge.fury.io/js/css-xpath)
Single method library for converting CSS selectors to XPath queries. This forked out of the [Potent Tools](http://github.com/gburtini/Potent-Tools-for-XPath) project, where we are playing archaeologist and recovering some useful but abandoned Firebug code.
Installation
------------
`yarn add css-xpath`
Usage
-----
```js
const cssXPath = require('css-xpath');
cssXPath('html > body') // '//html/body'
```
That's the whole library. Take in a CSS selector, output an XPath query. To see some example outputs, [consult the tests](test/cssXPath.spec.js).
They're unexposed, but if you want, there's some [regular expressions](src/patterns.js) that might be interesting if you're trying to parse CSS yourself. They are not exposed,
Bugs
----
Please submit a pull request with a failing test or create an issue if you get unexpected results. Our current perspective is that any valid XPath query that has the same selector semantics is a correct result, but in general, we do produce and prefer simpler queries to unnecessarily complex ones.
License
-------
As the code in this repository is derived from the Firebug source code, its [BSD 3-clause license](https://github.com/firebug/firebug/blob/master/extension/license.txt) applies.