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
superstruct/Compiled (minified)Compiled (minified)
github
GitHubGitHub
DiscordDiscord
PreferencesPreferences
schemas/libraries/superstruct/download_compiled/minified.js
code_off
View RawView Raw
Copy to clipboardCopy to clipboard
var e = class extends TypeError { constructor(e, t) { let n, { message: r, explanation: i, ...a } = e, { path: o } = e, s = o.length === 0 ? r : `At path: ${o.join(`.`)} -- ${r}`; (super(i ?? s), i != null && (this.cause = s), Object.assign(this, a), (this.name = this.constructor.name), (this.failures = () => (n ??= [e, ...t()]))); } }; function t(e) { return n(e) && typeof e[Symbol.iterator] == `function`; } function n(e) { return typeof e == `object` && !!e; } function r(e) { return n(e) && !Array.isArray(e); } function i(e) { return typeof e == `symbol` ? e.toString() : typeof e == `string` ? JSON.stringify(e) : `${e}`; } function a(e) { let { done: t, value: n } = e.next(); return t ? void 0 : n; } function o(e, t, n, r) { if (e === !0) return; e === !1 ? (e = {}) : typeof e == `string` && (e = { message: e }); let { path: a, branch: o } = t, { type: s } = n, { refinement: c, message: l = `Expected a value of type \`${s}\`${c ? ` with refinement \`${c}\`` : ``}, but received: \`${i(r)}\``, } = e; return { value: r, type: s, refinement: c, key: a[a.length - 1], path: a, branch: o, ...e, message: l, }; } function* s(e, n, r, i) { t(e) || (e = [e]); for (let t of e) { let e = o(t, n, r, i); e && (yield e); } } function* c(e, t, r = {}) { let { path: i = [], branch: a = [e], coerce: o = !1, mask: s = !1 } = r, l = { path: i, branch: a, mask: s }; o && (e = t.coercer(e, l)); let u = `valid`; for (let n of t.validator(e, l)) ((n.explanation = r.message), (u = `not_valid`), yield [n, void 0]); for (let [d, f, p] of t.entries(e, l)) { let t = c(f, p, { path: d === void 0 ? i : [...i, d], branch: d === void 0 ? a : [...a, f], coerce: o, mask: s, message: r.message, }); for (let r of t) r[0] ? ((u = r[0].refinement == null ? `not_valid` : `not_refined`), yield [r[0], void 0]) : o && ((f = r[1]), d === void 0 ? (e = f) : e instanceof Map ? e.set(d, f) : e instanceof Set ? e.add(f) : n(e) && (f !== void 0 || d in e) && (e[d] = f)); } if (u !== `not_valid`) for (let n of t.refiner(e, l)) ((n.explanation = r.message), (u = `not_refined`), yield [n, void 0]); u === `valid` && (yield [void 0, e]); } var l = class { constructor(e) { let { type: t, schema: n, validator: r, refiner: i, coercer: a = (e) => e, entries: o = function* () {}, } = e; ((this.type = t), (this.schema = n), (this.entries = o), (this.coercer = a), r ? (this.validator = (e, t) => s(r(e, t), t, this, e)) : (this.validator = () => []), i ? (this.refiner = (e, t) => s(i(e, t), t, this, e)) : (this.refiner = () => [])); } assert(e, t) { return u(e, this, t); } create(e, t) { return d(e, this, t); } is(e) { return p(e, this); } mask(e, t) { return f(e, this, t); } validate(e, t = {}) { return m(e, this, t); } }; function u(e, t, n) { let r = m(e, t, { message: n }); if (r[0]) throw r[0]; } function d(e, t, n) { let r = m(e, t, { coerce: !0, message: n }); if (r[0]) throw r[0]; return r[1]; } function f(e, t, n) { let r = m(e, t, { coerce: !0, mask: !0, message: n }); if (r[0]) throw r[0]; return r[1]; } function p(e, t) { return !m(e, t)[0]; } function m(t, n, r = {}) { let i = c(t, n, r), o = a(i); return o[0] ? [ new e(o[0], function* () { for (let e of i) e[0] && (yield e[0]); }), void 0, ] : [void 0, o[1]]; } function h(e, t) { return new l({ type: e, schema: null, validator: t }); } function g(e) { return new l({ type: `array`, schema: e, *entries(t) { if (e && Array.isArray(t)) for (let [n, r] of t.entries()) yield [n, r, e]; }, coercer(e) { return Array.isArray(e) ? e.slice() : e; }, validator(e) { return Array.isArray(e) || `Expected an array value, but received: ${i(e)}`; }, }); } function _() { return h( `date`, (e) => (e instanceof Date && !isNaN(e.getTime())) || `Expected a valid \`Date\` object, but received: ${i(e)}`, ); } function v(e) { let t = {}, n = e.map((e) => i(e)).join(); for (let n of e) t[n] = n; return new l({ type: `enums`, schema: t, validator(t) { return e.includes(t) || `Expected one of \`${n}\`, but received: ${i(t)}`; }, }); } function y() { return h(`never`, () => !1); } function b(e) { return new l({ ...e, validator: (t, n) => t === null || e.validator(t, n), refiner: (t, n) => t === null || e.refiner(t, n), }); } function x() { return h( `number`, (e) => (typeof e == `number` && !isNaN(e)) || `Expected a number, but received: ${i(e)}`, ); } function S(e) { let t = e ? Object.keys(e) : [], a = y(); return new l({ type: `object`, schema: e || null, *entries(r) { if (e && n(r)) { let n = new Set(Object.keys(r)); for (let i of t) (n.delete(i), yield [i, r[i], e[i]]); for (let e of n) yield [e, r[e], a]; } }, validator(e) { return r(e) || `Expected an object, but received: ${i(e)}`; }, coercer(t, n) { if (!r(t)) return t; let i = { ...t }; if (n.mask && e) for (let t in i) e[t] === void 0 && delete i[t]; return i; }, }); } function C() { return h(`string`, (e) => typeof e == `string` || `Expected a string, but received: ${i(e)}`); } function w(e, t, n = {}) { let { exclusive: r } = n; return E(e, `max`, (n) => r ? n < t : n <= t || `Expected a ${e.type} less than ${r ? `` : `or equal to `}${t} but received \`${n}\``, ); } function T(e, t, n = {}) { let { exclusive: r } = n; return E(e, `min`, (n) => r ? n > t : n >= t || `Expected a ${e.type} greater than ${r ? `` : `or equal to `}${t} but received \`${n}\``, ); } function E(e, t, n) { return new l({ ...e, *refiner(r, i) { yield* e.refiner(r, i); let a = s(n(r, i), i, e, r); for (let e of a) yield { ...e, refinement: t }; }, }); } function D(e, t) { return E(C(), `string with length between ${e} and ${t}`, (n) => n.length >= e && n.length <= t); } const O = E(C(), `url`, (e) => URL.canParse(e)), k = S({ id: x(), created: _(), title: D(1, 100), type: v([`jpg`, `png`]), size: x(), url: O }), A = S({ id: x(), stars: w(T(x(), 0), 5), title: D(1, 100), text: D(1, 1e3), images: g(k) }); d( {}, S({ id: x(), created: _(), title: D(1, 100), brand: D(1, 30), description: D(1, 500), price: w(T(x(), 1), 1e4), discount: b(w(T(x(), 1), 100)), quantity: w(T(x(), 0), 10), tags: g(D(1, 30)), images: g(k), ratings: g(A), }), );
Created by eskimojo for Open Circle

Preferences

Style
Theme
NPM browser
Code ligatures