Skip to content

miichom/xpath2css

 
 

Repository files navigation

@miichom/xpath2css

npm node

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/xpath2css

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

About

Lightweight converter that transforms XPath selectors into CSS selectors.

Topics

Resources

License

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Contributors

No contributors

Languages

  • TypeScript 100.0%