Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Factory
✓ import * as Factory from "factory.ts";
✗ import Factory from "factory.ts";
`factory.ts` exports its primary functionality as a namespace named `Factory`, which contains modules like `Sync` and `Async`, and helpers like `each`. Direct default imports will fail.
makeFactory
✓ import * as Factory from "factory.ts"; Factory.Sync.makeFactory(...);
✗ import { makeFactory } from 'factory.ts';
The `makeFactory` function for synchronous factories is located within the `Sync` module of the `Factory` namespace (`Factory.Sync.makeFactory`). It is not directly exported from the top-level package.
each
✓ import * as Factory from "factory.ts"; Factory.each(...);
✗ import { each } from 'factory.ts';
The `each` helper, used for sequence-based value generation, is directly available on the top-level `Factory` namespace for convenience. It can also be accessed via `Factory.Sync.each`.
Demonstrates creating a synchronous factory, building single instances with overrides, generating lists, and extending a factory to derive properties from others.
import * as Factory from "factory.ts";
interface Person {
id: number;
firstName: string;
lastName: string;
fullName: string;
age: number;
}
// Create a basic synchronous factory for the Person interface
const personFactory = Factory.Sync.makeFactory<Person>({
id: Factory.each((i) => i + 1), // Generate sequential IDs starting from 1
firstName: "John",
lastName: "Doe",
fullName: "John Doe", // Default full name
age: Factory.each((i) => 20 + (i % 10)), // Age cycles between 20 and 29
});
// Build a single person with default values
const defaultPerson = personFactory.build();
console.log("Default Person:", defaultPerson);
// Example: { id: 1, firstName: 'John', lastName: 'Doe', fullName: 'John Doe', age: 20 }
// Build a person overriding some properties
const janeSmith = personFactory.build({
firstName: "Jane",
lastName: "Smith"
});
console.log("Jane Smith (overridden):", janeSmith);
// Example: { id: 2, firstName: 'Jane', lastName: 'Smith', fullName: 'John Doe', age: 21 }
// Build a list of people
const threePeople = personFactory.buildList(3, { lastName: "Public" });
console.log("Three Publics:", threePeople);
/*
Example: [
{ id: 3, firstName: 'John', lastName: 'Public', fullName: 'John Doe', age: 22 },
{ id: 4, firstName: 'John', lastName: 'Public', fullName: 'John Doe', age: 23 },
{ id: 5, firstName: 'John', lastName: 'Public', fullName: 'John Doe', age: 24 }
]
*/
// Demonstrate extending a factory for derived values
const autoFullNameFactory = personFactory.withDerivation2(
["firstName", "lastName"],
"fullName",
(fName, lName) => `${fName} ${lName}`
);
const derivedPerson = autoFullNameFactory.build({
firstName: "Derived",
lastName: "Name"
});
console.log("Derived Full Name Person:", derivedPerson);
// Example: { id: 1, firstName: 'Derived', lastName: 'Name', fullName: 'Derived Name', age: 20 }
Errors
Common errors & fixes
TypeError: (0, factory_ts_1.default) is not a function
Attempting to import `Factory` as a default export (`import Factory from 'factory.ts';`) when it is exported as a namespace.
fixUse a namespace import: `import * as Factory from 'factory.ts';`
Property 'makeFactory' does not exist on type 'typeof import("factory.ts")'.
Trying to access `makeFactory` directly on the `Factory` namespace, when it is nested under `Factory.Sync` (or `Factory.Async`).
fixAccess `makeFactory` via the `Sync` module: `Factory.Sync.makeFactory(...)`
Argument of type '(...)' is not assignable to parameter of type 'never'.
Using the incorrect `withDerivationN` function (e.g., `withDerivation1`) for the number of dependent properties specified (e.g., two properties).
fixUse the `withDerivationN` function that matches the number of dependent properties you are providing (e.g., `withDerivation2` for two dependencies).
Audit
Dependencies
No dependency data recorded yet.