LogoLogo

Schema Benchmarks

    • home
      Home

    • download_2
      Download

    • timer
      Initialization
    • check_circle
      Validation
    • output_circle
      Parsing
    • swap_horiz
      Codec
    • schema
      Standard Schema
    • data_object
      JSON Schema
    • format_quote
      String

    • error
      Stack

    • deployed_code
      Libraries

    • article
      Blog
Expand sidebarExpand sidebar
zod/mini/Compiled (minified)Compiled (minified)
github
GitHubGitHub
DiscordDiscord
PreferencesPreferences
schemas/libraries/zod/mini/download_compiled/minified.js
code_off
View RawView Raw
Copy to clipboardCopy to clipboard
var e; function t(e, t, n) { function r(n, r) { if ( (n._zod || Object.defineProperty(n, "_zod", { value: { def: r, constr: o, traits: new Set() }, enumerable: !1, }), n._zod.traits.has(e)) ) return; (n._zod.traits.add(e), t(n, r)); let i = o.prototype, a = Object.keys(i); for (let e = 0; e < a.length; e++) { let t = a[e]; t in n || (n[t] = i[t].bind(n)); } } let i = n?.Parent ?? Object; class a extends i {} Object.defineProperty(a, "name", { value: e }); function o(e) { var t; let i = n?.Parent ? new a() : this; (r(i, e), (t = i._zod).deferred ?? (t.deferred = [])); for (let e of i._zod.deferred) e(); return i; } return ( Object.defineProperty(o, "init", { value: r }), Object.defineProperty(o, Symbol.hasInstance, { value: (t) => (n?.Parent && t instanceof n.Parent ? !0 : t?._zod?.traits?.has(e)), }), Object.defineProperty(o, "name", { value: e }), o ); } var n = class extends Error { constructor() { super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`); } }; (e = globalThis).__zod_globalConfig ?? (e.__zod_globalConfig = {}); const r = globalThis.__zod_globalConfig; function i(e) { return (e && Object.assign(r, e), r); } function a(e) { let t = Object.values(e).filter((e) => typeof e == `number`); return Object.entries(e) .filter(([e, n]) => t.indexOf(+e) === -1) .map(([e, t]) => t); } function o(e, t) { return typeof t == `bigint` ? t.toString() : t; } function s(e) { return { get value() { { let t = e(); return (Object.defineProperty(this, "value", { value: t }), t); } }, }; } function c(e) { return e == null; } function l(e) { let t = +!!e.startsWith(`^`), n = e.endsWith(`$`) ? e.length - 1 : e.length; return e.slice(t, n); } const u = Symbol(`evaluating`); function d(e, t, n) { let r; Object.defineProperty(e, t, { get() { if (r !== u) return (r === void 0 && ((r = u), (r = n())), r); }, set(n) { Object.defineProperty(e, t, { value: n }); }, configurable: !0, }); } const f = `captureStackTrace` in Error ? Error.captureStackTrace : (...e) => {}; function ee(e) { return typeof e == `object` && !!e && !Array.isArray(e); } const te = new Set([`string`, `number`, `symbol`]); function ne(e) { return e.replace(/[.*+?^${}()|[\]\\]/g, `\\$&`); } function re(e, t, n) { let r = new e._zod.constr(t ?? e._zod.def); return ((!t || n?.parent) && (r._zod.parent = e), r); } function p(e) { let t = e; if (!t) return {}; if (typeof t == `string`) return { error: () => t }; if (t?.message !== void 0) { if (t?.error !== void 0) throw Error("Cannot specify both `message` and `error` params"); t.error = t.message; } return (delete t.message, typeof t.error == `string` ? { ...t, error: () => t.error } : t); } function ie(e) { return Object.keys(e).filter( (t) => e[t]._zod.optin === `optional` && e[t]._zod.optout === `optional`, ); } (-Number.MAX_VALUE, Number.MAX_VALUE); function m(e, t = 0) { if (e.aborted === !0) return !0; for (let n = t; n < e.issues.length; n++) if (e.issues[n]?.continue !== !0) return !0; return !1; } function h(e, t = 0) { if (e.aborted === !0) return !0; for (let n = t; n < e.issues.length; n++) if (e.issues[n]?.continue === !1) return !0; return !1; } function g(e, t) { return t.map((t) => { var n; return ((n = t).path ?? (n.path = []), t.path.unshift(e), t); }); } function _(e) { return typeof e == `string` ? e : e?.message; } function v(e, t, n) { let r = e.message ? e.message : (_(e.inst?._zod.def?.error?.(e)) ?? _(t?.error?.(e)) ?? _(n.customError?.(e)) ?? _(n.localeError?.(e)) ?? `Invalid input`), { inst: i, continue: a, input: o, ...s } = e; return ((s.path ??= []), (s.message = r), t?.reportInput && (s.input = o), s); } function y(e) { return Array.isArray(e) ? `array` : typeof e == `string` ? `string` : `unknown`; } const b = (e, t) => { ((e.name = `$ZodError`), Object.defineProperty(e, "_zod", { value: e._zod, enumerable: !1 }), Object.defineProperty(e, "issues", { value: t, enumerable: !1 }), (e.message = JSON.stringify(t, o, 2)), Object.defineProperty(e, "toString", { value: () => e.message, enumerable: !1 })); }, x = t(`$ZodError`, b), S = t(`$ZodError`, b, { Parent: Error }), C = ((e) => (t, r, a, o) => { let s = a ? { ...a, async: !1 } : { async: !1 }, c = t._zod.run({ value: r, issues: [] }, s); if (c instanceof Promise) throw new n(); if (c.issues.length) { let t = new (o?.Err ?? e)(c.issues.map((e) => v(e, s, i()))); throw (f(t, o?.callee), t); } return c.value; })(S), w = ((e) => async (t, n, r, a) => { let o = r ? { ...r, async: !0 } : { async: !0 }, s = t._zod.run({ value: n, issues: [] }, o); if ((s instanceof Promise && (s = await s), s.issues.length)) { let t = new (a?.Err ?? e)(s.issues.map((e) => v(e, o, i()))); throw (f(t, a?.callee), t); } return s.value; })(S), T = ((e) => (t, r, a) => { let o = a ? { ...a, async: !1 } : { async: !1 }, s = t._zod.run({ value: r, issues: [] }, o); if (s instanceof Promise) throw new n(); return s.issues.length ? { success: !1, error: new (e ?? x)(s.issues.map((e) => v(e, o, i()))) } : { success: !0, data: s.value }; })(S), E = ((e) => async (t, n, r) => { let a = r ? { ...r, async: !0 } : { async: !0 }, o = t._zod.run({ value: n, issues: [] }, a); return ( o instanceof Promise && (o = await o), o.issues.length ? { success: !1, error: new e(o.issues.map((e) => v(e, a, i()))) } : { success: !0, data: o.value } ); })(S), ae = /^https?$/, oe = (e) => { let t = e ? `[\\s\\S]{${e?.minimum ?? 0},${e?.maximum ?? ``}}` : `[\\s\\S]*`; return RegExp(`^${t}$`); }, se = /^-?\d+(?:\.\d+)?$/, D = t(`$ZodCheck`, (e, t) => { var n; ((e._zod ??= {}), (e._zod.def = t), (n = e._zod).onattach ?? (n.onattach = [])); }), O = { number: `number`, bigint: `bigint`, object: `date` }, ce = t(`$ZodCheckLessThan`, (e, t) => { D.init(e, t); let n = O[typeof t.value]; (e._zod.onattach.push((e) => { let n = e._zod.bag, r = (t.inclusive ? n.maximum : n.exclusiveMaximum) ?? 1 / 0; t.value < r && (t.inclusive ? (n.maximum = t.value) : (n.exclusiveMaximum = t.value)); }), (e._zod.check = (r) => { (t.inclusive ? r.value <= t.value : r.value < t.value) || r.issues.push({ origin: n, code: `too_big`, maximum: typeof t.value == `object` ? t.value.getTime() : t.value, input: r.value, inclusive: t.inclusive, inst: e, continue: !t.abort, }); })); }), le = t(`$ZodCheckGreaterThan`, (e, t) => { D.init(e, t); let n = O[typeof t.value]; (e._zod.onattach.push((e) => { let n = e._zod.bag, r = (t.inclusive ? n.minimum : n.exclusiveMinimum) ?? -1 / 0; t.value > r && (t.inclusive ? (n.minimum = t.value) : (n.exclusiveMinimum = t.value)); }), (e._zod.check = (r) => { (t.inclusive ? r.value >= t.value : r.value > t.value) || r.issues.push({ origin: n, code: `too_small`, minimum: typeof t.value == `object` ? t.value.getTime() : t.value, input: r.value, inclusive: t.inclusive, inst: e, continue: !t.abort, }); })); }), ue = t(`$ZodCheckMaxLength`, (e, t) => { var n; (D.init(e, t), (n = e._zod.def).when ?? (n.when = (e) => { let t = e.value; return !c(t) && t.length !== void 0; }), e._zod.onattach.push((e) => { let n = e._zod.bag.maximum ?? 1 / 0; t.maximum < n && (e._zod.bag.maximum = t.maximum); }), (e._zod.check = (n) => { let r = n.value; if (r.length <= t.maximum) return; let i = y(r); n.issues.push({ origin: i, code: `too_big`, maximum: t.maximum, inclusive: !0, input: r, inst: e, continue: !t.abort, }); })); }), de = t(`$ZodCheckMinLength`, (e, t) => { var n; (D.init(e, t), (n = e._zod.def).when ?? (n.when = (e) => { let t = e.value; return !c(t) && t.length !== void 0; }), e._zod.onattach.push((e) => { let n = e._zod.bag.minimum ?? -1 / 0; t.minimum > n && (e._zod.bag.minimum = t.minimum); }), (e._zod.check = (n) => { let r = n.value; if (r.length >= t.minimum) return; let i = y(r); n.issues.push({ origin: i, code: `too_small`, minimum: t.minimum, inclusive: !0, input: r, inst: e, continue: !t.abort, }); })); }), fe = t(`$ZodCheckStringFormat`, (e, t) => { var n, r; (D.init(e, t), e._zod.onattach.push((e) => { let n = e._zod.bag; ((n.format = t.format), t.pattern && ((n.patterns ??= new Set()), n.patterns.add(t.pattern))); }), t.pattern ? ((n = e._zod).check ?? (n.check = (n) => { ((t.pattern.lastIndex = 0), !t.pattern.test(n.value) && n.issues.push({ origin: `string`, code: `invalid_format`, format: t.format, input: n.value, ...(t.pattern ? { pattern: t.pattern.toString() } : {}), inst: e, continue: !t.abort, })); })) : ((r = e._zod).check ?? (r.check = () => {}))); }), pe = { major: 4, minor: 4, patch: 3 }, k = t(`$ZodType`, (e, t) => { var r; ((e ??= {}), (e._zod.def = t), (e._zod.bag = e._zod.bag || {}), (e._zod.version = pe)); let i = [...(e._zod.def.checks ?? [])]; e._zod.traits.has(`$ZodCheck`) && i.unshift(e); for (let t of i) for (let n of t._zod.onattach) n(e); if (i.length === 0) ((r = e._zod).deferred ?? (r.deferred = []), e._zod.deferred?.push(() => { e._zod.run = e._zod.parse; })); else { let t = (e, t, r) => { let i = m(e), a; for (let o of t) { if (o._zod.def.when) { if (h(e) || !o._zod.def.when(e)) continue; } else if (i) continue; let t = e.issues.length, s = o._zod.check(e); if (s instanceof Promise && r?.async === !1) throw new n(); if (a || s instanceof Promise) a = (a ?? Promise.resolve()).then(async () => { (await s, e.issues.length !== t && (i ||= m(e, t))); }); else { if (e.issues.length === t) continue; i ||= m(e, t); } } return a ? a.then(() => e) : e; }, r = (r, a, o) => { if (m(r)) return ((r.aborted = !0), r); let s = t(a, i, o); if (s instanceof Promise) { if (o.async === !1) throw new n(); return s.then((t) => e._zod.parse(t, o)); } return e._zod.parse(s, o); }; e._zod.run = (a, o) => { if (o.skipChecks) return e._zod.parse(a, o); if (o.direction === `backward`) { let t = e._zod.parse({ value: a.value, issues: [] }, { ...o, skipChecks: !0 }); return t instanceof Promise ? t.then((e) => r(e, a, o)) : r(t, a, o); } let s = e._zod.parse(a, o); if (s instanceof Promise) { if (o.async === !1) throw new n(); return s.then((e) => t(e, i, o)); } return t(s, i, o); }; } d(e, `~standard`, () => ({ validate: (t) => { try { let n = T(e, t); return n.success ? { value: n.data } : { issues: n.error?.issues }; } catch { return E(e, t).then((e) => (e.success ? { value: e.data } : { issues: e.error?.issues })); } }, vendor: `zod`, version: 1, })); }), A = t(`$ZodString`, (e, t) => { (k.init(e, t), (e._zod.pattern = [...(e?._zod.bag?.patterns ?? [])].pop() ?? oe(e._zod.bag)), (e._zod.parse = (n, r) => { if (t.coerce) try { n.value = String(n.value); } catch {} return ( typeof n.value == `string` || n.issues.push({ expected: `string`, code: `invalid_type`, input: n.value, inst: e }), n ); })); }), j = t(`$ZodStringFormat`, (e, t) => { (fe.init(e, t), A.init(e, t)); }), M = t(`$ZodURL`, (e, t) => { (j.init(e, t), (e._zod.check = (n) => { try { let r = n.value.trim(); if (!t.normalize && t.protocol?.source === ae.source && !/^https?:\/\//i.test(r)) { n.issues.push({ code: `invalid_format`, format: `url`, note: `Invalid URL format`, input: n.value, inst: e, continue: !t.abort, }); return; } let i = new URL(r); (t.hostname && ((t.hostname.lastIndex = 0), t.hostname.test(i.hostname) || n.issues.push({ code: `invalid_format`, format: `url`, note: `Invalid hostname`, pattern: t.hostname.source, input: n.value, inst: e, continue: !t.abort, })), t.protocol && ((t.protocol.lastIndex = 0), t.protocol.test(i.protocol.endsWith(`:`) ? i.protocol.slice(0, -1) : i.protocol) || n.issues.push({ code: `invalid_format`, format: `url`, note: `Invalid protocol`, pattern: t.protocol.source, input: n.value, inst: e, continue: !t.abort, })), t.normalize ? (n.value = i.href) : (n.value = r)); return; } catch { n.issues.push({ code: `invalid_format`, format: `url`, input: n.value, inst: e, continue: !t.abort, }); } })); }), N = t(`$ZodNumber`, (e, t) => { (k.init(e, t), (e._zod.pattern = e._zod.bag.pattern ?? se), (e._zod.parse = (n, r) => { if (t.coerce) try { n.value = Number(n.value); } catch {} let i = n.value; if (typeof i == `number` && !Number.isNaN(i) && Number.isFinite(i)) return n; let a = typeof i == `number` ? Number.isNaN(i) ? `NaN` : Number.isFinite(i) ? void 0 : `Infinity` : void 0; return ( n.issues.push({ expected: `number`, code: `invalid_type`, input: i, inst: e, ...(a ? { received: a } : {}), }), n ); })); }), P = t(`$ZodDate`, (e, t) => { (k.init(e, t), (e._zod.parse = (n, r) => { if (t.coerce) try { n.value = new Date(n.value); } catch {} let i = n.value, a = i instanceof Date; return ( (a && !Number.isNaN(i.getTime())) || n.issues.push({ expected: `date`, code: `invalid_type`, input: i, ...(a ? { received: `Invalid Date` } : {}), inst: e, }), n ); })); }); function F(e, t, n) { (e.issues.length && t.issues.push(...g(n, e.issues)), (t.value[n] = e.value)); } const I = t(`$ZodArray`, (e, t) => { (k.init(e, t), (e._zod.parse = (n, r) => { let i = n.value; if (!Array.isArray(i)) return (n.issues.push({ expected: `array`, code: `invalid_type`, input: i, inst: e }), n); n.value = Array(i.length); let a = []; for (let e = 0; e < i.length; e++) { let o = i[e], s = t.element._zod.run({ value: o, issues: [] }, r); s instanceof Promise ? a.push(s.then((t) => F(t, n, e))) : F(s, n, e); } return a.length ? Promise.all(a).then(() => n) : n; })); }); function L(e, t, n, r, i, a) { let o = n in r; if (e.issues.length) { if (i && a && !o) return; t.issues.push(...g(n, e.issues)); } if (!o && !i) { e.issues.length || t.issues.push({ code: `invalid_type`, expected: `nonoptional`, input: void 0, path: [n] }); return; } e.value === void 0 ? o && (t.value[n] = void 0) : (t.value[n] = e.value); } function R(e) { let t = Object.keys(e.shape); for (let n of t) if (!e.shape?.[n]?._zod?.traits?.has(`$ZodType`)) throw Error(`Invalid element at key "${n}": expected a Zod schema`); let n = ie(e.shape); return { ...e, keys: t, keySet: new Set(t), numKeys: t.length, optionalKeys: new Set(n) }; } function z(e, t, n, r, i, a) { let o = [], s = i.keySet, c = i.catchall._zod, l = c.def.type, u = c.optin === `optional`, d = c.optout === `optional`; for (let i in t) { if (i === `__proto__` || s.has(i)) continue; if (l === `never`) { o.push(i); continue; } let a = c.run({ value: t[i], issues: [] }, r); a instanceof Promise ? e.push(a.then((e) => L(e, n, i, t, u, d))) : L(a, n, i, t, u, d); } return ( o.length && n.issues.push({ code: `unrecognized_keys`, keys: o, input: t, inst: a }), e.length ? Promise.all(e).then(() => n) : n ); } const B = t(`$ZodObject`, (e, t) => { if ((k.init(e, t), !Object.getOwnPropertyDescriptor(t, `shape`)?.get)) { let e = t.shape; Object.defineProperty(t, "shape", { get: () => { let n = { ...e }; return (Object.defineProperty(t, "shape", { value: n }), n); }, }); } let n = s(() => R(t)); d(e._zod, `propValues`, () => { let e = t.shape, n = {}; for (let t in e) { let r = e[t]._zod; if (r.values) { n[t] ?? (n[t] = new Set()); for (let e of r.values) n[t].add(e); } } return n; }); let r = ee, i = t.catchall, a; e._zod.parse = (t, o) => { a ??= n.value; let s = t.value; if (!r(s)) return (t.issues.push({ expected: `object`, code: `invalid_type`, input: s, inst: e }), t); t.value = {}; let c = [], l = a.shape; for (let e of a.keys) { let n = l[e], r = n._zod.optin === `optional`, i = n._zod.optout === `optional`, a = n._zod.run({ value: s[e], issues: [] }, o); a instanceof Promise ? c.push(a.then((n) => L(n, t, e, s, r, i))) : L(a, t, e, s, r, i); } return i ? z(c, s, t, o, n.value, e) : c.length ? Promise.all(c).then(() => t) : t; }; }), me = t(`$ZodEnum`, (e, t) => { k.init(e, t); let n = a(t.entries), r = new Set(n); ((e._zod.values = r), (e._zod.pattern = RegExp( `^(${n .filter((e) => te.has(typeof e)) .map((e) => (typeof e == `string` ? ne(e) : e.toString())) .join(`|`)})$`, )), (e._zod.parse = (t, i) => { let a = t.value; return ( r.has(a) || t.issues.push({ code: `invalid_value`, values: n, input: a, inst: e }), t ); })); }), he = t(`$ZodNullable`, (e, t) => { (k.init(e, t), d(e._zod, `optin`, () => t.innerType._zod.optin), d(e._zod, `optout`, () => t.innerType._zod.optout), d(e._zod, `pattern`, () => { let e = t.innerType._zod.pattern; return e ? RegExp(`^(${l(e.source)}|null)$`) : void 0; }), d(e._zod, `values`, () => t.innerType._zod.values ? new Set([...t.innerType._zod.values, null]) : void 0, ), (e._zod.parse = (e, n) => (e.value === null ? e : t.innerType._zod.run(e, n)))); }); function ge(e, t) { return new e({ type: `string`, ...p(t) }); } function _e(e, t) { return new e({ type: `string`, format: `url`, check: `string_format`, abort: !1, ...p(t) }); } function ve(e, t) { return new e({ type: `number`, checks: [], ...p(t) }); } function ye(e, t) { return new e({ type: `date`, ...p(t) }); } function V(e, t) { return new ce({ check: `less_than`, ...p(t), value: e, inclusive: !0 }); } function H(e, t) { return new le({ check: `greater_than`, ...p(t), value: e, inclusive: !0 }); } function U(e, t) { return new ue({ check: `max_length`, ...p(t), maximum: e }); } function W(e, t) { return new de({ check: `min_length`, ...p(t), minimum: e }); } const G = t(`ZodMiniType`, (e, t) => { if (!e._zod) throw Error(`Uninitialized schema in ZodMiniType.`); (k.init(e, t), (e.def = t), (e.type = t.type), (e.parse = (t, n) => C(e, t, n, { callee: e.parse })), (e.safeParse = (t, n) => T(e, t, n)), (e.parseAsync = async (t, n) => w(e, t, n, { callee: e.parseAsync })), (e.safeParseAsync = async (t, n) => E(e, t, n)), (e.check = (...n) => e.clone( { ...t, checks: [ ...(t.checks ?? []), ...n.map((e) => typeof e == `function` ? { _zod: { check: e, def: { check: `custom` }, onattach: [] } } : e, ), ], }, { parent: !0 }, )), (e.with = e.check), (e.clone = (t, n) => re(e, t, n)), (e.brand = () => e), (e.register = (t, n) => (t.add(e, n), e)), (e.apply = (t) => t(e))); }), K = t(`ZodMiniString`, (e, t) => { (A.init(e, t), G.init(e, t)); }); function q(e) { return ge(K, e); } const be = t(`ZodMiniStringFormat`, (e, t) => { (j.init(e, t), K.init(e, t)); }), xe = t(`ZodMiniURL`, (e, t) => { (M.init(e, t), be.init(e, t)); }); function Se(e) { return _e(xe, e); } const Ce = t(`ZodMiniNumber`, (e, t) => { (N.init(e, t), G.init(e, t)); }); function J(e) { return ve(Ce, e); } const we = t(`ZodMiniDate`, (e, t) => { (P.init(e, t), G.init(e, t)); }); function Y(e) { return ye(we, e); } const Te = t(`ZodMiniArray`, (e, t) => { (I.init(e, t), G.init(e, t)); }); function X(e, t) { return new Te({ type: `array`, element: e, ...p(t) }); } const Z = t(`ZodMiniObject`, (e, t) => { (B.init(e, t), G.init(e, t), d(e, `shape`, () => t.shape)); }); function Q(e, t) { let n = { type: `object`, shape: e ?? {}, ...p(t) }; return new Z(n); } const Ee = t(`ZodMiniEnum`, (e, t) => { (me.init(e, t), G.init(e, t), (e.options = Object.values(t.entries))); }); function De(e, t) { let n = Array.isArray(e) ? Object.fromEntries(e.map((e) => [e, e])) : e; return new Ee({ type: `enum`, entries: n, ...p(t) }); } const Oe = t(`ZodMiniNullable`, (e, t) => { (he.init(e, t), G.init(e, t)); }); function ke(e) { return new Oe({ type: `nullable`, innerType: e }); } const $ = Q({ id: J(), created: Y(), title: q().check(W(1), U(100)), type: De([`jpg`, `png`]), size: J(), url: Se(), }), Ae = Q({ id: J(), stars: J().check(H(0), V(5)), title: q().check(W(1), U(100)), text: q().check(W(1), U(1e3)), images: X($), }); Q({ id: J(), created: Y(), title: q().check(W(1), U(100)), brand: q().check(W(1), U(30)), description: q().check(W(1), U(500)), price: J().check(H(1), V(1e4)), discount: ke(J().check(H(1), V(100))), quantity: J().check(H(0), V(10)), tags: X(q().check(W(1), U(30))), images: X($), ratings: X(Ae), }).parse({});
Created by eskimojo for Open Circle

Preferences

Style
Theme
NPM browser
Code ligatures