-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a3d764
commit 0712d80
Showing
70 changed files
with
489 additions
and
460 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
const Test = z.object({ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
test("check any inference", () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
const minTwo = z.string().array().min(2); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
test("type guard", () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
test("branded types", () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | |
const test = Deno.test; | ||
|
||
import { z } from "../index.ts"; | ||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
|
||
test("basic catch", () => { | ||
expect(z.string().catch("default").parse(undefined)).toBe("default"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | |
const test = Deno.test; | ||
|
||
import { z } from "../index.ts"; | ||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
|
||
test("basic defaults", () => { | ||
expect(z.string().default("default").parse(undefined)).toBe("default"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
test("create enum", () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
test("first party switch", () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
const args1 = z.tuple([z.string()]); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
test("generics", () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
test("instanceof", async () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
import { ZodIssueCode } from "../index.ts"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
test("nativeEnum test with consts", () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
const Test = z.object({ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
import { ZodNullable, ZodOptional } from "../index.ts"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
const fish = z.object({ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
import { Mocker } from "./Mocker.ts"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
const promSchema = z.promise( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
enum testEnum { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
const booleanRecord = z.record(z.boolean()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
import { ZodIssueCode } from "../ZodError.ts"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
import { ZodIssueCode } from "../index.ts"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
const stringToNumber = z.string().transform((arg) => parseFloat(arg)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
import { ZodError } from "../ZodError.ts"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import { util } from "../helpers/index.ts"; | ||
import * as z from "../index.ts"; | ||
test("void", () => { | ||
const v = z.void(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
export namespace enumUtil { | ||
type UnionToIntersectionFn<T> = ( | ||
T extends unknown ? (k: () => T) => void : never | ||
) extends (k: infer Intersection) => void | ||
? Intersection | ||
: never; | ||
type UnionToIntersectionFn<T> = ( | ||
T extends unknown ? (k: () => T) => void : never | ||
) extends (k: infer Intersection) => void | ||
? Intersection | ||
: never; | ||
|
||
type GetUnionLast<T> = UnionToIntersectionFn<T> extends () => infer Last | ||
? Last | ||
: never; | ||
type GetUnionLast<T> = UnionToIntersectionFn<T> extends () => infer Last | ||
? Last | ||
: never; | ||
|
||
type UnionToTuple<T, Tuple extends unknown[] = []> = [T] extends [never] | ||
? Tuple | ||
: UnionToTuple<Exclude<T, GetUnionLast<T>>, [GetUnionLast<T>, ...Tuple]>; | ||
type UnionToTuple<T, Tuple extends unknown[] = []> = [T] extends [never] | ||
? Tuple | ||
: UnionToTuple<Exclude<T, GetUnionLast<T>>, [GetUnionLast<T>, ...Tuple]>; | ||
|
||
type CastToStringTuple<T> = T extends [string, ...string[]] ? T : never; | ||
type CastToStringTuple<T> = T extends [string, ...string[]] ? T : never; | ||
|
||
export type UnionToTupleString<T> = CastToStringTuple<UnionToTuple<T>>; | ||
} | ||
export type UnionToTupleString<T> = CastToStringTuple<UnionToTuple<T>>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
export namespace errorUtil { | ||
export type ErrMessage = string | { message?: string }; | ||
export const errToObj = (message?: ErrMessage) => | ||
typeof message === "string" ? { message } : message || {}; | ||
export const toString = (message?: ErrMessage): string | undefined => | ||
typeof message === "string" ? message : message?.message; | ||
} | ||
export type ErrMessage = string | { message?: string }; | ||
export const errToObj = (message?: ErrMessage) => | ||
typeof message === "string" ? { message } : message || {}; | ||
export const toString = (message?: ErrMessage): string | undefined => | ||
typeof message === "string" ? message : message?.message; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * as enumUtil from "./enumUtil.ts"; | ||
export * as errorUtil from "./errorUtil.ts"; | ||
export * as objectUtil from "./objectUtil.ts"; | ||
export * as partialUtil from "./partialUtil.ts"; | ||
export * as util from "./util.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
export type MergeShapes<U, V> = { | ||
[k in Exclude<keyof U, keyof V>]: U[k]; | ||
} & V; | ||
|
||
// type optionalKeys<T extends object> = { | ||
// [k in keyof T]: undefined extends T[k] ? k : never; | ||
// }[keyof T]; | ||
|
||
type requiredKeys<T extends object> = { | ||
[k in keyof T]: undefined extends T[k] ? never : k; | ||
}[keyof T]; | ||
|
||
// type alkjsdf = addQuestionMarks<{ a: any }>; | ||
|
||
export type addQuestionMarks< | ||
T extends object, | ||
R extends keyof T = requiredKeys<T> | ||
// O extends keyof T = optionalKeys<T> | ||
> = Pick<Required<T>, R> & Partial<T>; | ||
// = { [k in O]?: T[k] } & { [k in R]: T[k] }; | ||
|
||
export type identity<T> = T; | ||
export type flatten<T> = identity<{ [k in keyof T]: T[k] }>; | ||
|
||
export type noNeverKeys<T> = { | ||
[k in keyof T]: [T[k]] extends [never] ? never : k; | ||
}[keyof T]; | ||
|
||
export type noNever<T> = identity<{ | ||
[k in noNeverKeys<T>]: k extends keyof T ? T[k] : never; | ||
}>; | ||
|
||
export const mergeShapes = <U, T>(first: U, second: T): T & U => { | ||
return { | ||
...first, | ||
...second, // second overwrites first | ||
}; | ||
}; | ||
|
||
export type extendShape<A, B> = flatten<Omit<A, keyof B> & B>; |
Oops, something went wrong.