From 797dbc581d0590b587fec1aec5b4e6568378d22a Mon Sep 17 00:00:00 2001 From: Loris Sigrist Date: Thu, 11 May 2023 11:37:15 +0200 Subject: [PATCH] Added `generateMany` --- .changeset/good-scissors-reply.md | 5 +++++ src/lib/zocker.ts | 14 ++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 .changeset/good-scissors-reply.md diff --git a/.changeset/good-scissors-reply.md b/.changeset/good-scissors-reply.md new file mode 100644 index 0000000..cbf6e13 --- /dev/null +++ b/.changeset/good-scissors-reply.md @@ -0,0 +1,5 @@ +--- +"zocker": minor +--- + +feat: added `generateMany` method diff --git a/src/lib/zocker.ts b/src/lib/zocker.ts index d69e378..af3ad47 100644 --- a/src/lib/zocker.ts +++ b/src/lib/zocker.ts @@ -249,6 +249,20 @@ class Zocker { return generate(this.schema, ctx); } + + generateMany(count: number): z.infer[] { + let previous_seed = this.seed; + const results: z.infer[] = []; + + 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 { return Object.create( Object.getPrototypeOf(this),