A type-safe, lazily-loaded factory library for Deno, inspired by Ruby's FactoryBot.
Build structured mock data for testing with zero config and full type safety.
From jsr.io:
import {
build,
buildMany,
define,
defineAsync,
} from "jsr:@twigo/lithium_factory";From GitHub (if not yet published):
import {
build,
buildMany,
define,
defineAsync,
} from "https://deno.land/x/lithium_factory/src/mod.ts";- ✅ Fully typed with generics
- 🌀 Lazy-loads
./factories/{name}.tsautomatically - 🔁 Sync and async factory support
- 🎯 Build single or multiple entities
- 🧱 Extensible structure for sequences, traits (coming soon)
lithium_factory/
├── src/
│ ├── builder.ts
│ ├── errors.ts
│ └── registry.ts
├── factories/ # Your user-defined factories
├── tests/
├── .github/workflows/ci.yml
├── deno.json
├── mod.ts
└── README.md
// factories/user.ts
import { build, buildMany, define } from "./mod.ts";
type User = { id: number; name: string };
define<User>("user", () => ({
id: 1,
name: "John Doe",
}));const user = await build<User>("user");
// { id: 1, name: "John Doe" }
const userOverride = await build<User>("user", { name: "Jane" });
// { id: 1, name: "Jane" }
const users = await buildMany<User>("user", 3);
// [
// { id: 1, name: "John Doe" },
// { id: 1, name: "John Doe" },
// { id: 1, name: "John Doe" }
//]{
"tasks": {
"fmt": "deno fmt",
"lint": "deno lint",
"test": "deno test --allow-read --allow-net",
"coverage": "deno coverage --lcov > coverage.lcov"
}
}Run with:
deno task testIncluded .github/workflows/ci.yml runs:
deno fmtdeno lintdeno testdeno coverage
-
Log in to JSR:
deno publish --dry-run
-
If all checks pass:
deno publish
- Support for sequences
- Traits & associations
- CLI integration
MIT – Made with ❤️ by @nywton