LogoLogo

Schema Benchmarks

    • home
      Home

    • download_2
      Download

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

    • error
      Stack

  • JSON Schema

    • data_object
      Schema to JSON
    • code
      JSON to Schema
    • verified
      Compliance

    • deployed_code
      Libraries

    • article
      Blog
Expand sidebarExpand sidebar
@remix-run/data-schema/Compiled (minified)Compiled (minified)
github
GitHubGitHub
DiscordDiscord
PreferencesPreferences
Created by eskimojo for Open Circle

Preferences

Style
Theme
NPM browser
Code ligatures
schemas/libraries/@remix-run/data-schema/download_compiled/index/minified.js
code_off
View RawView Raw
Copy to clipboardCopy to clipboard
schemas/libraries/@remix-run/data-schema/download_compiled/index/minified.js
code_off
View RawView Raw
Copy to clipboardCopy to clipboard
schemas/libraries/@remix-run/data-schema/download_compiled/index/minified.js
code_off
View RawView Raw
Copy to clipboardCopy to clipboard
schemas/libraries/@remix-run/data-schema/download_compiled/index/minified.js
code_off
View RawView Raw
Copy to clipboardCopy to clipboard
function e(t) { let n = { "~standard": { version: 1, vendor: `data-schema`, validate(e, n) { return t(e, { path: [], options: n, }); }, }, "~run"(e, n) { return t(e, n); }, pipe(...t) { return t.length === 0 ? n : e(function (e, r) { let i = n[`~run`](e, r); if (i.issues) return i; for (let e of t) if (!e.check(i.value)) return e.code ? { issues: [ o(r, { code: e.code, defaultMessage: e.message ?? `Check failed`, input: i.value, values: e.values, }), ], } : { issues: [ s( e.message ?? `Check failed`, r.path, ), ], }; return i; }); }, refine(t, r) { return e(function (e, i) { let a = n[`~run`](e, i); return a.issues || t(a.value) ? a : r === void 0 ? { issues: [ o(i, { code: `refine.failed`, defaultMessage: `Refinement failed`, input: a.value, }), ], } : { issues: [s(r, i.path)], }; }); }, transform(t) { return e(function (e, r) { let i = n[`~run`](e, r); return i.issues ? i : { value: t(i.value) }; }); }, }; return n; } function t(e) { let t = e?.libraryOptions?.abortEarly; return !!(e?.abortEarly ?? t); } function n(e, t) { return e.length === 0 ? [t] : [...e, t]; } function r(e) { let t = e?.libraryOptions?.errorMap; if (typeof e?.errorMap == `function`) return e.errorMap; if (typeof t == `function`) return t; } function i(e) { let t = e?.libraryOptions?.locale; if (typeof e?.locale == `string`) return e.locale; if (typeof t == `string`) return t; } function a(e, t) { let n = r(e); return n ? (n(t) ?? t.defaultMessage) : t.defaultMessage; } function o(e, t) { let n = t.path ?? e.path; return s( a(e.options, { code: t.code, defaultMessage: t.defaultMessage, path: n, values: t.values, input: t.input, locale: i(e.options), }), n, ); } function s(e, t) { return !t || t.length === 0 ? { message: e } : { message: e, path: t }; } function c(e, t, n) { return n?.code ? { issues: [ s( a(n.parseOptions, { code: n.code, defaultMessage: e, path: t, values: n.values, input: n.input, locale: i(n.parseOptions), }), t, ), ], } : { issues: [s(e, t)] }; } function l(r) { return e(function (e, i) { if (!Array.isArray(e)) return c( `Expected array`, i.path, { code: `type.array`, input: e, parseOptions: i.options, }, ); let a = t(i.options), o = [], s = [], l = 0; for (let t of e) { let e = r[`~run`](t, { path: n(i.path, l), options: i.options, }); if (e.issues) { if (a) return e; o.push(...e.issues); } else s.push(e.value); l += 1; } return o.length > 0 ? { issues: o } : { value: s }; }); } function u(t) { return e(function (e, n) { for (let n of t) if (e === n) return { value: e }; return c( `Expected one of: ` + t.map(String).join(`, `), n.path, { code: `enum.invalid_value`, input: e, values: { values: [...t] }, parseOptions: n.options, }, ); }); } function d(t) { return e(function (e, n) { return e instanceof t ? { value: e } : c( `Expected instance of ` + t.name, n.path, { code: `instanceof.invalid_type`, input: e, values: { constructorName: t.name, }, parseOptions: n.options, }, ); }); } function f(t) { return e(function (e, n) { return e === null ? { value: null } : t[`~run`](e, n); }); } function p() { return e(function (e, t) { return typeof e != `number` || !Number.isFinite(e) ? c(`Expected number`, t.path, { code: `type.number`, input: e, parseOptions: t.options, }) : { value: e }; }); } function m(r, i) { return e(function (e, a) { if ( typeof e != `object` || !e || Array.isArray(e) ) return c( `Expected object`, a.path, { code: `type.object`, input: e, parseOptions: a.options, }, ); let s = t(a.options), l = [], u = {}, d = e, f = i?.unknownKeys ?? `strip`; for (let e of Object.keys(r)) { let t = r[e][`~run`](d[e], { path: n(a.path, e), options: a.options, }); if (t.issues) { if (s) return t; l.push(...t.issues); } else (Object.prototype.hasOwnProperty.call( d, e, ) || t.value !== void 0) && (u[e] = t.value); } if ( f === `passthrough` || f === `error` ) { for (let e in d) if ( Object.prototype.hasOwnProperty.call( d, e, ) && !Object.prototype.hasOwnProperty.call( r, e, ) ) { if (f === `passthrough`) u[e] = d[e]; else { let t = o(a, { code: `object.unknown_key`, defaultMessage: `Unknown key`, input: d[e], path: n(a.path, e), values: { key: e }, }); if (s) return { issues: [t] }; l.push(t); } } } return l.length > 0 ? { issues: l } : { value: u }; }); } function h() { return e(function (e, t) { return typeof e == `string` ? { value: e } : c(`Expected string`, t.path, { code: `type.string`, input: e, parseOptions: t.options, }); }); } var g = class extends Error { issues; constructor( e, t = `Validation failed`, ) { (super(t), (this.name = `ValidationError`), (this.issues = e)); } }; function _(e, t, n) { let r = e[`~standard`].validate(t, n); if (r.issues) throw new g(r.issues); return r.value; } function v(e) { return { check(t) { return t.length >= e; }, code: `string.min_length`, values: { min: e }, message: `Expected at least ` + String(e) + ` characters`, }; } function y(e) { return { check(t) { return t.length <= e; }, code: `string.max_length`, values: { max: e }, message: `Expected at most ` + String(e) + ` characters`, }; } function b() { return { check(e) { try { return (new URL(e), !0); } catch { return !1; } }, code: `string.url`, message: `Expected valid URL`, }; } function x(e) { return { check(t) { return t >= e; }, code: `number.min`, values: { min: e }, message: `Expected number greater than or equal to ` + String(e), }; } function S(e) { return { check(t) { return t <= e; }, code: `number.max`, values: { max: e }, message: `Expected number less than or equal to ` + String(e), }; } const C = m({ id: p(), created: d(Date), title: h().pipe(v(1), y(100)), type: u([`jpg`, `png`]), size: p(), url: h().pipe(b()), }), w = m({ id: p(), stars: p().pipe(x(1), S(5)), title: h().pipe(v(1), y(100)), text: h().pipe(v(1), y(1e3)), images: l(C), }); _( m({ id: p(), created: d(Date), title: h().pipe(v(1), y(100)), brand: h().pipe(v(1), y(30)), description: h().pipe(v(1), y(500)), price: p().pipe(x(1), S(1e4)), discount: f(p().pipe(x(1), S(100))), quantity: p().pipe(x(0), S(10)), tags: l(h().pipe(v(1), y(30))), images: l(C), ratings: l(w), }), {}, );
function e(t) { let n = { "~standard": { version: 1, vendor: `data-schema`, validate(e, n) { return t(e, { path: [], options: n }); }, }, "~run"(e, n) { return t(e, n); }, pipe(...t) { return t.length === 0 ? n : e(function (e, r) { let i = n[`~run`](e, r); if (i.issues) return i; for (let e of t) if (!e.check(i.value)) return e.code ? { issues: [ o(r, { code: e.code, defaultMessage: e.message ?? `Check failed`, input: i.value, values: e.values, }), ], } : { issues: [ s( e.message ?? `Check failed`, r.path, ), ], }; return i; }); }, refine(t, r) { return e(function (e, i) { let a = n[`~run`](e, i); return a.issues || t(a.value) ? a : r === void 0 ? { issues: [ o(i, { code: `refine.failed`, defaultMessage: `Refinement failed`, input: a.value, }), ], } : { issues: [s(r, i.path)] }; }); }, transform(t) { return e(function (e, r) { let i = n[`~run`](e, r); return i.issues ? i : { value: t(i.value) }; }); }, }; return n; } function t(e) { let t = e?.libraryOptions?.abortEarly; return !!(e?.abortEarly ?? t); } function n(e, t) { return e.length === 0 ? [t] : [...e, t]; } function r(e) { let t = e?.libraryOptions?.errorMap; if (typeof e?.errorMap == `function`) return e.errorMap; if (typeof t == `function`) return t; } function i(e) { let t = e?.libraryOptions?.locale; if (typeof e?.locale == `string`) return e.locale; if (typeof t == `string`) return t; } function a(e, t) { let n = r(e); return n ? (n(t) ?? t.defaultMessage) : t.defaultMessage; } function o(e, t) { let n = t.path ?? e.path; return s( a(e.options, { code: t.code, defaultMessage: t.defaultMessage, path: n, values: t.values, input: t.input, locale: i(e.options), }), n, ); } function s(e, t) { return !t || t.length === 0 ? { message: e } : { message: e, path: t }; } function c(e, t, n) { return n?.code ? { issues: [ s( a(n.parseOptions, { code: n.code, defaultMessage: e, path: t, values: n.values, input: n.input, locale: i(n.parseOptions), }), t, ), ], } : { issues: [s(e, t)] }; } function l(r) { return e(function (e, i) { if (!Array.isArray(e)) return c(`Expected array`, i.path, { code: `type.array`, input: e, parseOptions: i.options, }); let a = t(i.options), o = [], s = [], l = 0; for (let t of e) { let e = r[`~run`](t, { path: n(i.path, l), options: i.options, }); if (e.issues) { if (a) return e; o.push(...e.issues); } else s.push(e.value); l += 1; } return o.length > 0 ? { issues: o } : { value: s }; }); } function u(t) { return e(function (e, n) { for (let n of t) if (e === n) return { value: e }; return c( `Expected one of: ` + t.map(String).join(`, `), n.path, { code: `enum.invalid_value`, input: e, values: { values: [...t] }, parseOptions: n.options, }, ); }); } function d(t) { return e(function (e, n) { return e instanceof t ? { value: e } : c(`Expected instance of ` + t.name, n.path, { code: `instanceof.invalid_type`, input: e, values: { constructorName: t.name }, parseOptions: n.options, }); }); } function f(t) { return e(function (e, n) { return e === null ? { value: null } : t[`~run`](e, n); }); } function p() { return e(function (e, t) { return typeof e != `number` || !Number.isFinite(e) ? c(`Expected number`, t.path, { code: `type.number`, input: e, parseOptions: t.options, }) : { value: e }; }); } function m(r, i) { return e(function (e, a) { if (typeof e != `object` || !e || Array.isArray(e)) return c(`Expected object`, a.path, { code: `type.object`, input: e, parseOptions: a.options, }); let s = t(a.options), l = [], u = {}, d = e, f = i?.unknownKeys ?? `strip`; for (let e of Object.keys(r)) { let t = r[e][`~run`](d[e], { path: n(a.path, e), options: a.options, }); if (t.issues) { if (s) return t; l.push(...t.issues); } else (Object.prototype.hasOwnProperty.call(d, e) || t.value !== void 0) && (u[e] = t.value); } if (f === `passthrough` || f === `error`) { for (let e in d) if ( Object.prototype.hasOwnProperty.call(d, e) && !Object.prototype.hasOwnProperty.call(r, e) ) { if (f === `passthrough`) u[e] = d[e]; else { let t = o(a, { code: `object.unknown_key`, defaultMessage: `Unknown key`, input: d[e], path: n(a.path, e), values: { key: e }, }); if (s) return { issues: [t] }; l.push(t); } } } return l.length > 0 ? { issues: l } : { value: u }; }); } function h() { return e(function (e, t) { return typeof e == `string` ? { value: e } : c(`Expected string`, t.path, { code: `type.string`, input: e, parseOptions: t.options, }); }); } var g = class extends Error { issues; constructor(e, t = `Validation failed`) { (super(t), (this.name = `ValidationError`), (this.issues = e)); } }; function _(e, t, n) { let r = e[`~standard`].validate(t, n); if (r.issues) throw new g(r.issues); return r.value; } function v(e) { return { check(t) { return t.length >= e; }, code: `string.min_length`, values: { min: e }, message: `Expected at least ` + String(e) + ` characters`, }; } function y(e) { return { check(t) { return t.length <= e; }, code: `string.max_length`, values: { max: e }, message: `Expected at most ` + String(e) + ` characters`, }; } function b() { return { check(e) { try { return (new URL(e), !0); } catch { return !1; } }, code: `string.url`, message: `Expected valid URL`, }; } function x(e) { return { check(t) { return t >= e; }, code: `number.min`, values: { min: e }, message: `Expected number greater than or equal to ` + String(e), }; } function S(e) { return { check(t) { return t <= e; }, code: `number.max`, values: { max: e }, message: `Expected number less than or equal to ` + String(e), }; } const C = m({ id: p(), created: d(Date), title: h().pipe(v(1), y(100)), type: u([`jpg`, `png`]), size: p(), url: h().pipe(b()), }), w = m({ id: p(), stars: p().pipe(x(1), S(5)), title: h().pipe(v(1), y(100)), text: h().pipe(v(1), y(1e3)), images: l(C), }); _( m({ id: p(), created: d(Date), title: h().pipe(v(1), y(100)), brand: h().pipe(v(1), y(30)), description: h().pipe(v(1), y(500)), price: p().pipe(x(1), S(1e4)), discount: f(p().pipe(x(1), S(100))), quantity: p().pipe(x(0), S(10)), tags: l(h().pipe(v(1), y(30))), images: l(C), ratings: l(w), }), {}, );
function e(t) { let n = { "~standard": { version: 1, vendor: `data-schema`, validate(e, n) { return t(e, { path: [], options: n }); }, }, "~run"(e, n) { return t(e, n); }, pipe(...t) { return t.length === 0 ? n : e(function (e, r) { let i = n[`~run`](e, r); if (i.issues) return i; for (let e of t) if (!e.check(i.value)) return e.code ? { issues: [ o(r, { code: e.code, defaultMessage: e.message ?? `Check failed`, input: i.value, values: e.values, }), ], } : { issues: [s(e.message ?? `Check failed`, r.path)] }; return i; }); }, refine(t, r) { return e(function (e, i) { let a = n[`~run`](e, i); return a.issues || t(a.value) ? a : r === void 0 ? { issues: [ o(i, { code: `refine.failed`, defaultMessage: `Refinement failed`, input: a.value, }), ], } : { issues: [s(r, i.path)] }; }); }, transform(t) { return e(function (e, r) { let i = n[`~run`](e, r); return i.issues ? i : { value: t(i.value) }; }); }, }; return n; } function t(e) { let t = e?.libraryOptions?.abortEarly; return !!(e?.abortEarly ?? t); } function n(e, t) { return e.length === 0 ? [t] : [...e, t]; } function r(e) { let t = e?.libraryOptions?.errorMap; if (typeof e?.errorMap == `function`) return e.errorMap; if (typeof t == `function`) return t; } function i(e) { let t = e?.libraryOptions?.locale; if (typeof e?.locale == `string`) return e.locale; if (typeof t == `string`) return t; } function a(e, t) { let n = r(e); return n ? (n(t) ?? t.defaultMessage) : t.defaultMessage; } function o(e, t) { let n = t.path ?? e.path; return s( a(e.options, { code: t.code, defaultMessage: t.defaultMessage, path: n, values: t.values, input: t.input, locale: i(e.options), }), n, ); } function s(e, t) { return !t || t.length === 0 ? { message: e } : { message: e, path: t }; } function c(e, t, n) { return n?.code ? { issues: [ s( a(n.parseOptions, { code: n.code, defaultMessage: e, path: t, values: n.values, input: n.input, locale: i(n.parseOptions), }), t, ), ], } : { issues: [s(e, t)] }; } function l(r) { return e(function (e, i) { if (!Array.isArray(e)) return c(`Expected array`, i.path, { code: `type.array`, input: e, parseOptions: i.options, }); let a = t(i.options), o = [], s = [], l = 0; for (let t of e) { let e = r[`~run`](t, { path: n(i.path, l), options: i.options }); if (e.issues) { if (a) return e; o.push(...e.issues); } else s.push(e.value); l += 1; } return o.length > 0 ? { issues: o } : { value: s }; }); } function u(t) { return e(function (e, n) { for (let n of t) if (e === n) return { value: e }; return c(`Expected one of: ` + t.map(String).join(`, `), n.path, { code: `enum.invalid_value`, input: e, values: { values: [...t] }, parseOptions: n.options, }); }); } function d(t) { return e(function (e, n) { return e instanceof t ? { value: e } : c(`Expected instance of ` + t.name, n.path, { code: `instanceof.invalid_type`, input: e, values: { constructorName: t.name }, parseOptions: n.options, }); }); } function f(t) { return e(function (e, n) { return e === null ? { value: null } : t[`~run`](e, n); }); } function p() { return e(function (e, t) { return typeof e != `number` || !Number.isFinite(e) ? c(`Expected number`, t.path, { code: `type.number`, input: e, parseOptions: t.options, }) : { value: e }; }); } function m(r, i) { return e(function (e, a) { if (typeof e != `object` || !e || Array.isArray(e)) return c(`Expected object`, a.path, { code: `type.object`, input: e, parseOptions: a.options, }); let s = t(a.options), l = [], u = {}, d = e, f = i?.unknownKeys ?? `strip`; for (let e of Object.keys(r)) { let t = r[e][`~run`](d[e], { path: n(a.path, e), options: a.options }); if (t.issues) { if (s) return t; l.push(...t.issues); } else (Object.prototype.hasOwnProperty.call(d, e) || t.value !== void 0) && (u[e] = t.value); } if (f === `passthrough` || f === `error`) { for (let e in d) if ( Object.prototype.hasOwnProperty.call(d, e) && !Object.prototype.hasOwnProperty.call(r, e) ) { if (f === `passthrough`) u[e] = d[e]; else { let t = o(a, { code: `object.unknown_key`, defaultMessage: `Unknown key`, input: d[e], path: n(a.path, e), values: { key: e }, }); if (s) return { issues: [t] }; l.push(t); } } } return l.length > 0 ? { issues: l } : { value: u }; }); } function h() { return e(function (e, t) { return typeof e == `string` ? { value: e } : c(`Expected string`, t.path, { code: `type.string`, input: e, parseOptions: t.options, }); }); } var g = class extends Error { issues; constructor(e, t = `Validation failed`) { (super(t), (this.name = `ValidationError`), (this.issues = e)); } }; function _(e, t, n) { let r = e[`~standard`].validate(t, n); if (r.issues) throw new g(r.issues); return r.value; } function v(e) { return { check(t) { return t.length >= e; }, code: `string.min_length`, values: { min: e }, message: `Expected at least ` + String(e) + ` characters`, }; } function y(e) { return { check(t) { return t.length <= e; }, code: `string.max_length`, values: { max: e }, message: `Expected at most ` + String(e) + ` characters`, }; } function b() { return { check(e) { try { return (new URL(e), !0); } catch { return !1; } }, code: `string.url`, message: `Expected valid URL`, }; } function x(e) { return { check(t) { return t >= e; }, code: `number.min`, values: { min: e }, message: `Expected number greater than or equal to ` + String(e), }; } function S(e) { return { check(t) { return t <= e; }, code: `number.max`, values: { max: e }, message: `Expected number less than or equal to ` + String(e), }; } const C = m({ id: p(), created: d(Date), title: h().pipe(v(1), y(100)), type: u([`jpg`, `png`]), size: p(), url: h().pipe(b()), }), w = m({ id: p(), stars: p().pipe(x(1), S(5)), title: h().pipe(v(1), y(100)), text: h().pipe(v(1), y(1e3)), images: l(C), }); _( m({ id: p(), created: d(Date), title: h().pipe(v(1), y(100)), brand: h().pipe(v(1), y(30)), description: h().pipe(v(1), y(500)), price: p().pipe(x(1), S(1e4)), discount: f(p().pipe(x(1), S(100))), quantity: p().pipe(x(0), S(10)), tags: l(h().pipe(v(1), y(30))), images: l(C), ratings: l(w), }), {}, );
function e(t) { let n = { "~standard": { version: 1, vendor: `data-schema`, validate(e, n) { return t(e, { path: [], options: n }); }, }, "~run"(e, n) { return t(e, n); }, pipe(...t) { return t.length === 0 ? n : e(function (e, r) { let i = n[`~run`](e, r); if (i.issues) return i; for (let e of t) if (!e.check(i.value)) return e.code ? { issues: [ o(r, { code: e.code, defaultMessage: e.message ?? `Check failed`, input: i.value, values: e.values, }), ], } : { issues: [s(e.message ?? `Check failed`, r.path)] }; return i; }); }, refine(t, r) { return e(function (e, i) { let a = n[`~run`](e, i); return a.issues || t(a.value) ? a : r === void 0 ? { issues: [ o(i, { code: `refine.failed`, defaultMessage: `Refinement failed`, input: a.value, }), ], } : { issues: [s(r, i.path)] }; }); }, transform(t) { return e(function (e, r) { let i = n[`~run`](e, r); return i.issues ? i : { value: t(i.value) }; }); }, }; return n; } function t(e) { let t = e?.libraryOptions?.abortEarly; return !!(e?.abortEarly ?? t); } function n(e, t) { return e.length === 0 ? [t] : [...e, t]; } function r(e) { let t = e?.libraryOptions?.errorMap; if (typeof e?.errorMap == `function`) return e.errorMap; if (typeof t == `function`) return t; } function i(e) { let t = e?.libraryOptions?.locale; if (typeof e?.locale == `string`) return e.locale; if (typeof t == `string`) return t; } function a(e, t) { let n = r(e); return n ? (n(t) ?? t.defaultMessage) : t.defaultMessage; } function o(e, t) { let n = t.path ?? e.path; return s( a(e.options, { code: t.code, defaultMessage: t.defaultMessage, path: n, values: t.values, input: t.input, locale: i(e.options), }), n, ); } function s(e, t) { return !t || t.length === 0 ? { message: e } : { message: e, path: t }; } function c(e, t, n) { return n?.code ? { issues: [ s( a(n.parseOptions, { code: n.code, defaultMessage: e, path: t, values: n.values, input: n.input, locale: i(n.parseOptions), }), t, ), ], } : { issues: [s(e, t)] }; } function l(r) { return e(function (e, i) { if (!Array.isArray(e)) return c(`Expected array`, i.path, { code: `type.array`, input: e, parseOptions: i.options }); let a = t(i.options), o = [], s = [], l = 0; for (let t of e) { let e = r[`~run`](t, { path: n(i.path, l), options: i.options }); if (e.issues) { if (a) return e; o.push(...e.issues); } else s.push(e.value); l += 1; } return o.length > 0 ? { issues: o } : { value: s }; }); } function u(t) { return e(function (e, n) { for (let n of t) if (e === n) return { value: e }; return c(`Expected one of: ` + t.map(String).join(`, `), n.path, { code: `enum.invalid_value`, input: e, values: { values: [...t] }, parseOptions: n.options, }); }); } function d(t) { return e(function (e, n) { return e instanceof t ? { value: e } : c(`Expected instance of ` + t.name, n.path, { code: `instanceof.invalid_type`, input: e, values: { constructorName: t.name }, parseOptions: n.options, }); }); } function f(t) { return e(function (e, n) { return e === null ? { value: null } : t[`~run`](e, n); }); } function p() { return e(function (e, t) { return typeof e != `number` || !Number.isFinite(e) ? c(`Expected number`, t.path, { code: `type.number`, input: e, parseOptions: t.options }) : { value: e }; }); } function m(r, i) { return e(function (e, a) { if (typeof e != `object` || !e || Array.isArray(e)) return c(`Expected object`, a.path, { code: `type.object`, input: e, parseOptions: a.options, }); let s = t(a.options), l = [], u = {}, d = e, f = i?.unknownKeys ?? `strip`; for (let e of Object.keys(r)) { let t = r[e][`~run`](d[e], { path: n(a.path, e), options: a.options }); if (t.issues) { if (s) return t; l.push(...t.issues); } else (Object.prototype.hasOwnProperty.call(d, e) || t.value !== void 0) && (u[e] = t.value); } if (f === `passthrough` || f === `error`) { for (let e in d) if ( Object.prototype.hasOwnProperty.call(d, e) && !Object.prototype.hasOwnProperty.call(r, e) ) { if (f === `passthrough`) u[e] = d[e]; else { let t = o(a, { code: `object.unknown_key`, defaultMessage: `Unknown key`, input: d[e], path: n(a.path, e), values: { key: e }, }); if (s) return { issues: [t] }; l.push(t); } } } return l.length > 0 ? { issues: l } : { value: u }; }); } function h() { return e(function (e, t) { return typeof e == `string` ? { value: e } : c(`Expected string`, t.path, { code: `type.string`, input: e, parseOptions: t.options }); }); } var g = class extends Error { issues; constructor(e, t = `Validation failed`) { (super(t), (this.name = `ValidationError`), (this.issues = e)); } }; function _(e, t, n) { let r = e[`~standard`].validate(t, n); if (r.issues) throw new g(r.issues); return r.value; } function v(e) { return { check(t) { return t.length >= e; }, code: `string.min_length`, values: { min: e }, message: `Expected at least ` + String(e) + ` characters`, }; } function y(e) { return { check(t) { return t.length <= e; }, code: `string.max_length`, values: { max: e }, message: `Expected at most ` + String(e) + ` characters`, }; } function b() { return { check(e) { try { return (new URL(e), !0); } catch { return !1; } }, code: `string.url`, message: `Expected valid URL`, }; } function x(e) { return { check(t) { return t >= e; }, code: `number.min`, values: { min: e }, message: `Expected number greater than or equal to ` + String(e), }; } function S(e) { return { check(t) { return t <= e; }, code: `number.max`, values: { max: e }, message: `Expected number less than or equal to ` + String(e), }; } const C = m({ id: p(), created: d(Date), title: h().pipe(v(1), y(100)), type: u([`jpg`, `png`]), size: p(), url: h().pipe(b()), }), w = m({ id: p(), stars: p().pipe(x(1), S(5)), title: h().pipe(v(1), y(100)), text: h().pipe(v(1), y(1e3)), images: l(C), }); _( m({ id: p(), created: d(Date), title: h().pipe(v(1), y(100)), brand: h().pipe(v(1), y(30)), description: h().pipe(v(1), y(500)), price: p().pipe(x(1), S(1e4)), discount: f(p().pipe(x(1), S(100))), quantity: p().pipe(x(0), S(10)), tags: l(h().pipe(v(1), y(30))), images: l(C), ratings: l(w), }), {}, );