typebox-schema-faker
Version:
Generate fake data from TypeBox schemas for testing, prototyping and development.
13 lines (12 loc) • 388 B
JavaScript
/**
* Generates fake data for number schemas
*/
export const fakeNumber = (schema, ctx) => {
const min = schema.minimum ?? 0;
const max = schema.maximum ?? min + 100;
const value = ctx.faker.number.float({ min, max });
if (schema.multipleOf && schema.multipleOf > 0) {
return Math.round(value / schema.multipleOf) * schema.multipleOf;
}
return value;
};