Skip to content

Commit

Permalink
fix: number with min/max.
Browse files Browse the repository at this point in the history
  • Loading branch information
Akira Higuchi committed Aug 5, 2022
1 parent 35998b7 commit d4fb129
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
with:
fetch-depth: 0

- name: Setup NodeJS 14
- name: Setup NodeJS 16
uses: actions/setup-node@v2
with:
node-version: 14
node-version: 16

- name: Install dependencies
run: npm ci
Expand Down
4 changes: 4 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ describe("make empty", () => {

it("number", () => {
expect(make(z.number())).toBe(0);
expect(make(z.number().min(10))).toBe(10);
expect(make(z.number().max(100))).toBe(100);
expect(make(z.number().min(10).max(100))).toBe(10);
expect(make(z.number().max(100).min(10))).toBe(100);
});

it("bigint", () => {
Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ function make<T extends ZodTypeAny>(schema: T): unknown {
case "ZodString":
return "";
case "ZodNumber":
for(const check of (def.checks || [])) {
if (["min", "max"].includes(check.kind)) {
return check.value;
}
}
return 0;
case "ZodBigInt":
return 0;
case "ZodBoolean":
Expand Down

0 comments on commit d4fb129

Please sign in to comment.