Getting started
@xtandard/lib is one package with many entry points. The core (@xtandard/lib) has zero
runtime dependencies and runs anywhere JavaScript does: Node, Bun, Deno, browsers and edge
runtimes. Every other entry point wraps one area or one library, and declares that library as an
optional peer dependency. You install a peer only when you import the entry point that needs it.
Install
Section titled “Install”npm install @xtandard/lib# orbun add @xtandard/libpnpm add @xtandard/libyarn add @xtandard/libThe package ships ESM and CommonJS builds with type declarations for both, for TypeScript 5, 6
and 7. The typings of @xtandard/lib/filters/drizzle-rqb and @xtandard/lib/filters/tanstack-table
need TypeScript 5.4+ (they use NoInfer). It is marked sideEffects: false, so bundlers drop
whatever you don’t import.
Your first imports
Section titled “Your first imports”import { tryCatch, collect, wait } from "@xtandard/lib";
// Errors as values: [data, error] tuples, without try/catch at the call site.const [config, error] = tryCatch(() => JSON.parse(raw)); // sync in → sync outconst [user, fetchError] = await tryCatch(fetch("/api/me").then((r) => r.json())); // promise in → promise out
// Drain any iterable or async iterable into an array.const ids = await collect(streamOfIds());
await wait(250);tryCatch, collect and a few others are sync/async-adaptive: give them synchronous inputs
and you get a plain value back; give them a promise or async input and you get a promise. See
Sync/async-adaptive APIs.
Pick an entry point
Section titled “Pick an entry point”| You want to… | Import | Install as well |
|---|---|---|
| Handle errors, async work, iterables, disposables | @xtandard/lib |
nothing |
| Model ranges of numbers, dates, money, versions, IPs | @xtandard/lib/interval and siblings |
nothing (or the value library: dinero.js, semver, …) |
| Paginate with cursors or offsets | @xtandard/lib/pagination |
nothing (or your query builder for an adapter) |
| Filter lists from a UI, safely, on any database | @xtandard/lib/filters + an adapter |
drizzle-orm or kysely for those adapters; a validator |
| Keep typed state in the URL with TanStack Router | @xtandard/lib/tanstack |
react, @tanstack/react-router |
| Use Temporal, ULIDs, DataLoader, unstorage, Sonner, React hooks | Integrations | the library you’re integrating |
The full list, with each entry’s peers, is on Entry points.
Optional peer dependencies
Section titled “Optional peer dependencies”Every peer is listed in peerDependenciesMeta as optional, so your package manager won’t install
them or warn about them. Import an entry point without its peer and you get a “module not found”
error at build time, which tells you exactly what to add:
# using @xtandard/lib/filters/drizzle and @xtandard/lib/filters/valibotnpm install drizzle-orm valibot @js-temporal/polyfillTypeScript
Section titled “TypeScript”The library is written in strict TypeScript and its types carry most of the documentation: hover
any export in your editor to read its JSDoc. The API reference is generated from the
same source. Use "moduleResolution": "bundler" or "node16"/"nodenext" so the subpath exports
(@xtandard/lib/filters/drizzle, …) resolve.
Versioning
Section titled “Versioning”@xtandard/lib stays on 0.x, following standard semver within it: features and breaking
changes bump the minor version, fixes bump the patch. Breaking changes are always flagged in the
changelog. Because ^0.x ranges accept new minors, pin an exact or
~0.x version if you want to opt in to breaking changes by hand.
Where next
Section titled “Where next”- Browse the core utilities.
- Follow a tutorial: a filterable, paginated list.
- Play with the filters and interval playgrounds.