@nibcss/core
The engine: parse attributes, resolve tokens and recipes, generate CSS. Zero dependencies, no DOM, fully deterministic.
@nibcss/core is the part that turns "p=16px; hover:bgc=#333" into CSS. It has no dependencies and
never touches the DOM, which is why the same engine runs inside the bundler plugin, the CLI, the browser
runtime and your own scripts — and why a class name is identical in all four.
You rarely install it directly: every other package depends on it. Reach for it when you are building a tool of your own.
Install#
npm i @nibcss/coreThe engine#
import { createEngine } from "@nibcss/core";
const engine = createEngine(config);
const { classNames, rules, warnings, diagnostics } = engine.process("p=16px; hover:bgc=#333");Member | What it does |
|---|---|
|
|
| every rule produced so far, as a stylesheet |
| replace the config and clear the caches |
| rule and class counts |
| the resolved config, every optional field filled in |
Everything is synchronous and deterministic: a class name is a hash of the rule it carries, so the same declaration always produces the same name — on every machine, in every build, in the browser and on the server.
Every export#
Export | What it is |
|---|---|
| identity, for editor completion in your config file |
| fill in every default |
| merge two configs one level deep — a token group adds to the palette instead of replacing it |
| the parser |
|
|
| the shorthand table and the property list |
| breakpoints |
| variants |
| value checking |
| the reset |
| diagnostics and their translations |
| the "did you mean" suggestions |
| the class-name hash (FNV-1a, base36) |
| the commented config file the tools scaffold |
Two fields that exist only for embedding#
Field | What it is |
|---|---|
| where diagnostics go; defaults to |
| a value checker. The browser runtime passes |
A build script of your own#
import { readFileSync, writeFileSync, globSync } from "node:fs";
import { createEngine } from "@nibcss/core";
import config from "./nibcss.config.ts";
const engine = createEngine({ ...config, debug: true, onWarn: (m) => console.warn(m) });
const ATTR = /\bnib\s*=\s*"([^"]*)"/g;
for (const file of globSync("src/**/*.html")) {
const source = readFileSync(file, "utf8");
for (const [, attr] of source.matchAll(ATTR)) engine.process(attr);
}
writeFileSync("dist/nib.css", engine.css());
console.log(engine.stats()); // { rules: 318, classes: 318 }