UNPKG

types-json

Version:
29 lines (28 loc) 1.09 kB
import { z } from "zod"; import { is, parse } from "../utils.js"; import { stringSchema } from "./string.js"; import { numberSchema } from "./number.js"; import { booleanSchema } from "./boolean.js"; import { nullSchema } from "./null.js"; export const jsonPrimitiveSchema = z.union([ stringSchema, numberSchema, booleanSchema, nullSchema ]); export const optionalJsonPrimitiveSchema = jsonPrimitiveSchema.optional(); export const isJSONPrimitive = is(jsonPrimitiveSchema); export const isOptionalJSONPrimitive = is(optionalJsonPrimitiveSchema); export const parseJSONPrimitive = parse(jsonPrimitiveSchema); export const jsonOrderableSchema = z.union([ stringSchema, numberSchema ]); export const optionalJsonOrderableSchema = jsonOrderableSchema.optional(); export const isJSONOrderable = is(jsonOrderableSchema); export const isOptionalJSONOrderable = is(optionalJsonOrderableSchema); export const parseJSONOrderable = parse(jsonOrderableSchema); export * from "./string.js"; export * from "./number.js"; export * from "./boolean.js"; export * from "./null.js";