Hyrax is a TypeScript toolkit whose functions are short to call and safe to call. Each one accepts its input in every shape it really comes in, types that shape exactly, and has a defined answer for every input. No runtime dependencies.
1.0.0-rc.0 is a release candidate: not on npm yet.
Nothing here is mocked. The answers are computed in your browser by the code these docs document.
Take input in the shapes it really comes in, typed exactly. The common case gets a short signature and the full form stays available. The compiler infers the generics, and the return type lists every value that can come back, fallbacks included.
Have an answer for every input the types allow. Bounds work in either order, degenerate input gives a neutral result, a missing target is a no-op, and browser code falls back on the server. Hyrax throws only for a configuration no correct program can write, because hiding a bug is worse than reporting it.
A stale example is worse than none. npm run docs:examples type-checks every example in the guides and in the TSDoc against the built package, resolved through its exports map, and runs the core ones. A trailing // => 10 is an assertion: the build fails the day clamp stops returning 10.
Run, answers asserted. The core guides and API pages. Each // => literal must equal what the code returns.
Type-checked, not run. /dom and /react, which need a browser or a component to mean anything.
Not checked. Skipped by hand, such as an example that is meant to throw.
clamp(15, 0, 10)// => 10ratio(30, 60)// => 0.5remap(5, [0, 10], [0, 100])// => 50lerp(0, 10, 0.5)// => 5toCamelCase("XMLHttpRequest")// => "xmlHttpRequest"toKebabCase("Ação rápida")// => "ação-rápida"coalesce(null, undefined, 0, "x")// => 0new Random("level-1").int(1, 100)// => 25 Import only what your runtime has. The core never touches the DOM, /dom never touches React, and /react is a thin layer over /dom. Named exports only, no side effects on import: a bundler keeps exactly what you use.
import { clamp, Random } from "@gabreusi/hyrax";Pure functions and three small classes. No DOM and no React in its types; the compiler enforces it.
Every function is its own export and nothing runs on import, so one function costs what it weighs. Each import also has a size budget that fails the build when it grows.
| You import | Scale | Costs about |
|---|---|---|
clamp | 76 B | |
listen from /dom | 85 B | |
useForceUpdate from /react | 96 B | |
hx from /react | 630 B | |
the whole of /dom | 1.1 kB | |
the whole of /react | 1.5 kB | |
Random | 3.2 kB | |
the whole core | 4.6 kB |