yuku-css
v0.2.0
Published
A fast CSS parser, printer and validator, written in Zig and compiled to WebAssembly
Maintainers
Readme
yuku-css
A fast CSS parser, printer and validator, written in Zig and compiled to WebAssembly. It builds css-tree's AST, passes css-tree's own test suite, and has zero dependencies.
Up to 8.6x faster than css-tree, 8.5x faster than esbuild and 4.8x faster than Lightning CSS at parsing and printing CSS, and up to 5.4x faster than css-tree and 5.1x faster than PostCSS at parsing it, every tool installed from npm. Natively, its Zig parser is 4.1x faster than oxc's Rust CSS parser (details).
Small enough for the browser: the parser and printer are 56 KB gzipped (roughly the size of css-tree itself), against 3.7 MB for Lightning CSS's WebAssembly build.
Parsing and printing tailwind.css (3.5 MB) on Bun:

Parsing it to an AST:

Seven real-world style sheets on Bun and Node, with the method: css-parser-benchmark-js.
npm install yuku-cssUsage
import { parse, transform } from "yuku-css";
import { lexer } from "yuku-css/lexer";
const { ast, diagnostics } = parse(".card { color: red }");
transform(".card { color: red }").code; // ".card{color:red}"
lexer.matchProperty("margin", "1px foo").error; // invalid valueIt runs in Node.js 18 or newer, Bun, Deno, Workers, and browsers. See docs/api.md for the full API.
Development
bun install
bun run build # zig build, which also writes src/decode.js from the Zig layouts, then tsdown
bun run typecheck
bun run test
zig build test # the Zig tests
bun run corpus # copies the CSS of a Markless checkout into test/corpus
bun run sync # copies css-tree's test fixtures into test/csstree, as `bun run test` doesLicense
MIT
