typebox-schema-faker
Version:
Generate fake data from TypeBox schemas for testing, prototyping and development.
20 lines (19 loc) • 634 B
JavaScript
import { createContext } from './context';
import { rootFake } from './root';
/**
* Generates fake data matching the provided TypeBox schema
*
* @template T — The TypeBox schema type
* @param schema — The TypeBox schema to generate fake data for
* @returns Fake data matching the schema's static type
* @throws {TypeBoxError} When the schema type is not supported
*
* @example
* ```ts
* const nameSchema = Type.String({ minLength: 3, maxLength: 10 });
* fake(nameSchema); // "a7B9x2"
* ```
*/
export function fake(schema, options = {}) {
return rootFake(schema, createContext({ seed: options.seed }), options);
}