Skip to content

Commit

Permalink
Added generateMany
Browse files Browse the repository at this point in the history
  • Loading branch information
LorisSigrist committed May 11, 2023
1 parent 8f3d72e commit 797dbc5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/good-scissors-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"zocker": minor
---

feat: added `generateMany` method
14 changes: 14 additions & 0 deletions src/lib/zocker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,20 @@ class Zocker<Z extends z.ZodSchema> {
return generate(this.schema, ctx);
}


generateMany(count: number): z.infer<Z>[] {
let previous_seed = this.seed;
const results: z.infer<Z>[] = [];

for (let i = 0; i < count; i++) {
if(previous_seed !== undefined) this.seed = previous_seed + i;
results.push(this.generate());
}

this.seed = previous_seed;
return results;
}

private clone(): Zocker<Z> {
return Object.create(
Object.getPrototypeOf(this),
Expand Down

0 comments on commit 797dbc5

Please sign in to comment.