index.ts
import { define, random, sequence } from "cooky-cutter";
// Define an interface (or type) for the entity
interface User {
id: number;
firstName: string;
lastName: string;
age: number;
}
// Define a factory that represents the defined interface
const user = define<User>({
id: random,
firstName: i => `Bob #${i}`,
lastName: "Smith",
age: sequence
});
// Invoke the factory a few times
console.log(user());
// => { id: 980711200, firstName: 'Bob #1', lastName: 'Smith', age: 1 }
console.log(user());
// => { id: 1345667839, firstName: 'Bob #2', lastName: 'Smith', age: 2 }
console.log(user());
// => { id: 796816401, firstName: 'Bob #3', lastName: 'Smith', age: 3 }