UNPKG

typebox-schema-faker

Version:

Generate fake data from TypeBox schemas for testing, prototyping and development.

12 lines (11 loc) 461 B
import { rootFake } from '../root'; import { EmptyRecursiveItem } from '../symbols'; /** * Generates fake data for array schemas */ export const fakeArray = (schema, ctx, options) => { const min = schema.minItems ?? 0; const max = schema.maxItems ?? Math.max(min + 3, 5); const length = ctx.faker.number.int({ min, max }); return Array.from({ length }, () => rootFake(schema.items, ctx, options)).filter((el) => el !== EmptyRecursiveItem); };