@miichom/xpath2css
v0.1.1
Published
Lightweight converter that transforms XPath selectors into CSS selectors.
Maintainers
Readme
@miichom/xpath2css
A lightweight, dependency‑free utility for converting XPath selectors into CSS selectors. Ideal for scrapers, DOM utilities, testing frameworks, and environments where XPath is stored but CSS is executed.
This package is a modern TypeScript rewrite of the original Python cssify converter created by santiycr. It was later ported to JavaScript by Dither, and subsequently converted to ES2015 and CommonJS, and published to npm by svenheden.
Install
npm install --save-dev @miichom/xpath2cssBasic Usage
// npm, pnpm, yarn, bun
import { xPathToCss } from "@miichom/xpath2css";
// deno
import { xPathToCss } from "https://esm.sh/@miichom/xpath2css";
import { xPathToCss } from "npm:@miichom/xpath2css"; // or directly from npm
const xPath = '//div[@id="foo"][2]/span[@class="bar"]//a[contains(@class, "baz")]//img[1]';
const css = xPathToCss(xPath);
console.log(css) // => 'div#foo:nth-of-type(2) > span.bar a[class*=baz] img:first-of-type'Contributing
Bug reports, improvements, and new test cases are welcome. See the Contributing Guidelines for details.
License
MIT © 2015-2026 Jonathan Svenheden, 2026-present miichom
