typebox-schema-faker
Version:
Generate fake data from TypeBox schemas for testing, prototyping and development.
16 lines (15 loc) • 514 B
JavaScript
/**
* Generates fake data for Uint8Array schemas
*/
export const fakeUint8Array = (schema, ctx) => {
const min = schema.minByteLength ?? 0;
const max = schema.maxByteLength ?? min + 32;
// Generate random length within constraints
const length = ctx.faker.number.int({ min, max });
// Create Uint8Array with random bytes
const array = new Uint8Array(length);
for (let i = 0; i < length; i++) {
array[i] = ctx.faker.number.int({ min: 0, max: 255 });
}
return array;
};