UNPKG

zod-schema-faker

Version:

Generates mock data from zod schema. Powered by @faker-js/faker and randexp.js

42 lines (31 loc) 1.2 kB
import * as core from 'zod/v4/core'; import { Faker } from '@faker-js/faker'; declare type Context = { /** * The current depth in a recursive structure. */ depth: number; }; export declare function custom<T extends core.$ZodType>(schema: T, fake: Fake<T>): void; export declare type Fake<T extends core.$ZodType> = (schema: T, context: Context, fake: RootFake) => core.infer<T>; export declare function fake<T extends core.$ZodType>(schema: T): core.infer<T>; /** * Get the faker instance. */ export declare function getFaker(): Faker; /** * Create random strings that match a given regular expression. */ export declare const randexp: (pattern: string | RegExp, flags?: string) => string; declare type RootFake = <T extends core.$ZodType>(schema: T, context: Context) => core.infer<T>; /** * Sets the seed or generates a new one. * * This method is intended to allow for consistent values in tests, so you might want to use hardcoded values as the seed. */ export declare const seed: (value?: number) => void; /** * Set the faker instance to use. */ export declare function setFaker(faker: Faker): void; export { }