Zero Dependencies
Generated builders have no runtime dependencies. The code is self-contained and works in any TypeScript project.
Transform your TypeScript interfaces into elegant, chainable builders with zero runtime dependencies
Transform this interface:
interface User {
id: string;
name: string;
email?: string;
role: 'admin' | 'user';
isActive: boolean;
}
Into this fluent builder:
const user = user()
.withId('123')
.withName('Alice')
.withEmail('alice@example.com')
.withRole('admin')
.withIsActive(true)
.build();
npm install -D fluent-gen-ts
npx fluent-gen-ts init
The interactive CLI will guide you through:
npx fluent-gen-ts generate ./src/types.ts User --output ./src/builders/
npx fluent-gen-ts batch
Creating test data and complex object structures in TypeScript often leads to:
fluent-gen-ts
automatically generates fluent builders that:
Every generated builder maintains full type safety throughout the chain:
const product = product()
.withId('P001') // âś“ string
.withPrice(99.99) // âś“ number
.withInStock(true) // âś“ boolean
.withCategories(['electronics', 'computers']) // âś“ string[]
.build();
Build complex nested structures with ease:
const order = order()
.withId('ORD-001')
.withCustomer(
customer().withName('John Doe').withAddress(
address().withStreet('123 Main St').withCity('New York'),
// No .build() needed - automatically handled!
),
)
.withItems([
item().withName('Laptop').withPrice(999),
item().withName('Mouse').withPrice(29),
])
.build();
Create custom plugins to extend functionality:
import { createPlugin, primitive } from 'fluent-gen-ts';
const validationPlugin = createPlugin('validation-plugin', '1.0.0')
.setDescription('Adds email validation and custom methods')
// Configure required imports
.requireImports(imports => imports.addExternal('validator', ['isEmail']))
// Transform property methods with type-safe matching
.transformPropertyMethods(builder =>
builder
.when(
ctx => ctx.property.name === 'email' && ctx.type.isPrimitive('string'),
)
.setParameter('string')
.setValidator(
`
if (value && !isEmail(value)) {
throw new Error('Invalid email format');
}
`,
)
.done(),
)
// Add custom builder methods
.addMethod(method =>
method
.name('withRandomId')
.parameter('prefix', 'string', { defaultValue: '"user"' })
.returns('this')
.implementation(
`
const id = \`\${prefix}-\${Date.now()}-\${Math.random().toString(36).substr(2, 9)}\`;
return this.withId(id);
`,
)
.jsDoc('/**\\n * Generates and sets a random ID\\n */'),
)
.build();
Generates self-contained builders with inlined utilities - perfect for standalone use.
Creates a shared common.ts
file with utilities that all builders import - ideal for generating multiple builders.
Use setup-common
to create your own customizable common utilities file.