zx.fromConstant
Convert a blob of JSON data into a zod schema that represents that blob's least upper bound.
import { zx } from '@traversable/zod'let schema = zx.fromConstant({ abc: 'ABC', def: [1, 2, 3] })// ^? let schema: z.ZodType<{ abc: "ABC", def: [1, 2, 3] }>console.log(zx.toString(schema))// => z.object({ abc: z.literal("ABC"), def: z.tuple([ z.literal(1), z.literal(2), z.literal(3) ]) }) Copy
import { zx } from '@traversable/zod'let schema = zx.fromConstant({ abc: 'ABC', def: [1, 2, 3] })// ^? let schema: z.ZodType<{ abc: "ABC", def: [1, 2, 3] }>console.log(zx.toString(schema))// => z.object({ abc: z.literal("ABC"), def: z.tuple([ z.literal(1), z.literal(2), z.literal(3) ]) })
zx.fromConstant.writeable
Convert a blob of JSON data into a stringified zod schema that represents that blob's least upper bound.
import { zx } from '@traversable/zod'let ex_01 = zx.fromConstant.writeable({ abc: 'ABC', def: [1, 2, 3] })console.log(ex_01)// => z.object({ abc: z.literal("ABC"), def: z.tuple([ z.literal(1), z.literal(2), z.literal(3) ]) }) Copy
import { zx } from '@traversable/zod'let ex_01 = zx.fromConstant.writeable({ abc: 'ABC', def: [1, 2, 3] })console.log(ex_01)// => z.object({ abc: z.literal("ABC"), def: z.tuple([ z.literal(1), z.literal(2), z.literal(3) ]) })
zx.fromConstant
Convert a blob of JSON data into a zod schema that represents that blob's least upper bound.