lib

← croot.js.org · docs · examples

Library CrootJS

Usage (via jsDelivr)

Import any module straight from jsDelivr’s GitHub CDN — no npm install, no build step:

import { getJSON, postJSON } from "https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/api.js";

Full per-module API reference: https://croot.js.org/docs/

Coding Conventions (Mandatory)

Projects using CrootJS must keep HTML, CSS, and JS in separate files, and load JS as <script type="module"> — no inline <style>/<script> blocks or onclick/style="" attributes. Full rules: https://croot.js.org/docs/conventions

Using an AI coding agent? Drop CLAUDE.md (in this repo) into your project root — Claude Code picks it up automatically.

Tests

tests/ runs the modules in a real browser — no npm. Open it through any local server:

python3 -m http.server      # from this folder, then open http://localhost:8000/tests/

or online at https://croot.js.org/lib/tests/. CI runs the same page headless in Chromium, Firefox, and WebKit on every push and tag (.github/workflows/test.yml); to do that locally: pip install playwright && python -m playwright install chromium && python tests/run.py (add firefox or webkit to pick another browser). The 3D tests need WebGL, which headless Firefox doesn’t provide without a GPU, so they show as skipped there; Chromium and WebKit run all of them.

Changes per version: CHANGELOG.md.

Editor autocomplete

Copy crootjs.d.ts into your project (next to a jsconfig.json). VS Code then knows every module imported straight from jsDelivr — any version, .js or .min.js — and shows parameter names, order, and the docs comment of each function. Since 0.0.38 the api.js options object is typed too (getJSON(url, null, { cache: { key, ttl, staleIfError, select } }) autocompletes), and getJSON<T>() types data. It is generated from the source: python3 tools/build-types.py.

Releasing

  1. For a feature or anything worth explaining, add a section at the top of CHANGELOG.md yourself: ## [x.y.z](https://github.com/crootjs/lib/releases/tag/vx.y.z) - YYYY-MM-DD, a bold title line, then the notes, and regenerate the type declarations (python3 tools/build-types.py). For a small fix you can skip this: when a push changes module code (*.js/*.css in the top folder) and the newest CHANGELOG version already has a tag, the workflow bumps the patch version itself (tools/auto-version.py), writes the CHANGELOG section from the commit subjects (so write clear ones), regenerates crootjs.d.ts, and commits both to main. Pushes that only touch docs, tests, tools or workflows never create a version.
  2. A hand-written CHANGELOG section always wins over the automatic one.
  3. Push to main. The workflow runs the tests; if they pass and the newest CHANGELOG version has no tag yet, it builds the .min.js and .min.css files and integrity.json (tools/build-min.py) into a release commit on the dist branch (parents: this main commit and the previous dist tip), creates the tag vx.y.z on it, and creates the GitHub Release from that section (tools/release.py). Pushes that don’t add a version (docs, pin bumps) create nothing.
  4. After a new release the workflow waits until jsDelivr serves lib@x.y.z (including .min.js), bumps the pins in this README, writes the version to version.json (served at https://croot.js.org/lib/version.json and shown on the landing page), and sends a lib-released repository dispatch to docs, examples and crootjs.github.io. Each of them bumps its own pins (tools/bump-pins.py, which also updates integrity hashes) and rebuilds GitHub Pages; the landing page then waits for docs and examples to go live, rebuilds sitemap.xml and llms-full.txt, runs the tests at https://croot.js.org/lib/tests/, and sends a Telegram notification.

Docs and example pages for a new feature can be pushed together with the lib change: their pins are raised automatically once the version is on jsDelivr.

One-time setup for step 4: a fine-grained personal access token (resource owner crootjs) with Contents: read and write on crootjs/docs, crootjs/examples and crootjs/crootjs.github.io, stored as the secret CROOTJS_DISPATCH_TOKEN in this repo; and, optionally, the secrets TELEGRAM_BOT_TOKEN and TELEGRAM_CHAT_ID in crootjs/crootjs.github.io. Without the token, step 4 stops after version.json with a warning; then run bump-pins (docs, examples) and release (crootjs.github.io) from the Actions tab. Left empty, their version is read from version.json.

Tagging by hand (git tag vx.y.z && git push origin vx.y.z) also works; the workflow then only adds the missing release, without step 4.