zod 4.5.3 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compile.cjs +19 -0
- package/index.cjs +19 -0
- package/locales/index.cjs +19 -0
- package/mini/index.cjs +19 -0
- package/package.json +8 -7
- package/src/v3/helpers/errorUtil.ts +1 -1
- package/src/v4/classic/checks.ts +0 -1
- package/src/v4/classic/external.ts +2 -0
- package/src/v4/classic/from-json-schema.ts +248 -25
- package/src/v4/classic/schemas.ts +255 -164
- package/src/v4/classic/tests/assignability.test.ts +59 -9
- package/src/v4/classic/tests/bigint.test.ts +6 -0
- package/src/v4/classic/tests/continuability.test.ts +2 -2
- package/src/v4/classic/tests/cyclic-data.test.ts +316 -0
- package/src/v4/classic/tests/default.test.ts +46 -0
- package/src/v4/classic/tests/enum.test.ts +9 -0
- package/src/v4/classic/tests/error.test.ts +130 -1
- package/src/v4/classic/tests/firstparty.test.ts +4 -0
- package/src/v4/classic/tests/from-json-schema.test.ts +157 -0
- package/src/v4/classic/tests/iban.test.ts +81 -0
- package/src/v4/classic/tests/instance-footprint.test.ts +18 -2
- package/src/v4/classic/tests/instanceof.test.ts +27 -7
- package/src/v4/classic/tests/issue-schema.test.ts +88 -56
- package/src/v4/classic/tests/object.test.ts +56 -0
- package/src/v4/classic/tests/optin-ladder.test.ts +3 -2
- package/src/v4/classic/tests/properties.test.ts +225 -0
- package/src/v4/classic/tests/recursive-types.test.ts +1 -1
- package/src/v4/classic/tests/standard-schema.test.ts +19 -0
- package/src/v4/classic/tests/string.test.ts +25 -0
- package/src/v4/classic/tests/template-literal.test.ts +33 -1
- package/src/v4/classic/tests/to-json-schema.test.ts +147 -3
- package/src/v4/classic/tests/validate.test.ts +569 -0
- package/src/v4/core/api.ts +30 -6
- package/src/v4/core/checks.ts +1 -101
- package/src/v4/core/compile.ts +193 -81
- package/src/v4/core/doc.ts +6 -2
- package/src/v4/core/errors.ts +3 -6
- package/src/v4/core/json-schema-generator.ts +2 -2
- package/src/v4/core/json-schema-processors.ts +226 -68
- package/src/v4/core/memoizer.ts +162 -36
- package/src/v4/core/parse.ts +37 -16
- package/src/v4/core/regexes.ts +10 -4
- package/src/v4/core/schemas.ts +314 -83
- package/src/v4/core/tests/cached.test.ts +54 -0
- package/src/v4/core/tests/compile-generative.test.ts +445 -0
- package/src/v4/core/tests/compile.test.ts +222 -2
- package/src/v4/core/tests/email-regex.test.ts +140 -0
- package/src/v4/core/tests/polyfill-collision.test.ts +46 -0
- package/src/v4/core/to-json-schema.ts +10 -8
- package/src/v4/core/util.ts +222 -147
- package/src/v4/core/versions.ts +2 -2
- package/src/v4/core/visit.ts +11 -0
- package/src/v4/locales/ar.ts +1 -0
- package/src/v4/locales/az.ts +1 -0
- package/src/v4/locales/be.ts +1 -0
- package/src/v4/locales/bg.ts +1 -0
- package/src/v4/locales/bn.ts +1 -0
- package/src/v4/locales/ca.ts +1 -0
- package/src/v4/locales/ckb.ts +1 -0
- package/src/v4/locales/cs.ts +1 -0
- package/src/v4/locales/da.ts +1 -0
- package/src/v4/locales/de.ts +1 -0
- package/src/v4/locales/el.ts +1 -0
- package/src/v4/locales/en.ts +1 -0
- package/src/v4/locales/eo.ts +1 -0
- package/src/v4/locales/es.ts +1 -0
- package/src/v4/locales/fa.ts +1 -0
- package/src/v4/locales/fi.ts +1 -0
- package/src/v4/locales/fr-CA.ts +1 -0
- package/src/v4/locales/fr.ts +1 -0
- package/src/v4/locales/gu.ts +1 -0
- package/src/v4/locales/he.ts +1 -0
- package/src/v4/locales/hi.ts +1 -0
- package/src/v4/locales/hr.ts +1 -0
- package/src/v4/locales/hu.ts +1 -0
- package/src/v4/locales/hy.ts +1 -0
- package/src/v4/locales/id.ts +1 -0
- package/src/v4/locales/is.ts +1 -0
- package/src/v4/locales/it.ts +1 -0
- package/src/v4/locales/ja.ts +1 -0
- package/src/v4/locales/ka.ts +1 -0
- package/src/v4/locales/km.ts +1 -0
- package/src/v4/locales/kn.ts +1 -0
- package/src/v4/locales/ko.ts +1 -0
- package/src/v4/locales/lt.ts +1 -0
- package/src/v4/locales/mk.ts +1 -0
- package/src/v4/locales/ms.ts +1 -0
- package/src/v4/locales/ne.ts +1 -0
- package/src/v4/locales/nl.ts +1 -0
- package/src/v4/locales/nn.ts +1 -0
- package/src/v4/locales/no.ts +1 -0
- package/src/v4/locales/ota.ts +1 -0
- package/src/v4/locales/pl.ts +1 -0
- package/src/v4/locales/ps.ts +1 -0
- package/src/v4/locales/pt-BR.ts +1 -0
- package/src/v4/locales/pt.ts +1 -0
- package/src/v4/locales/ro.ts +1 -0
- package/src/v4/locales/ru.ts +1 -0
- package/src/v4/locales/sk.ts +1 -0
- package/src/v4/locales/sl.ts +1 -0
- package/src/v4/locales/sv.ts +1 -0
- package/src/v4/locales/ta.ts +1 -0
- package/src/v4/locales/th.ts +1 -0
- package/src/v4/locales/tk.ts +1 -0
- package/src/v4/locales/tr.ts +1 -0
- package/src/v4/locales/uk.ts +1 -0
- package/src/v4/locales/ur.ts +1 -0
- package/src/v4/locales/uz.ts +1 -0
- package/src/v4/locales/vi.ts +1 -0
- package/src/v4/locales/yo.ts +1 -0
- package/src/v4/locales/zh-CN.ts +1 -0
- package/src/v4/locales/zh-TW.ts +1 -0
- package/src/v4/mini/checks.ts +0 -1
- package/src/v4/mini/external.ts +2 -0
- package/src/v4/mini/schemas.ts +38 -2
- package/src/v4/mini/tests/checks.test.ts +1 -1
- package/src/v4/mini/tests/computed.test.ts +11 -17
- package/src/v4/mini/tests/index.test.ts +8 -0
- package/src/v4/mini/tests/string.test.ts +16 -0
- package/v3/ZodError.cjs +19 -0
- package/v3/errors.cjs +19 -0
- package/v3/external.cjs +19 -0
- package/v3/helpers/enumUtil.cjs +19 -0
- package/v3/helpers/errorUtil.cjs +20 -1
- package/v3/helpers/errorUtil.js +1 -1
- package/v3/helpers/parseUtil.cjs +19 -0
- package/v3/helpers/partialUtil.cjs +19 -0
- package/v3/helpers/typeAliases.cjs +19 -0
- package/v3/helpers/util.cjs +19 -0
- package/v3/index.cjs +19 -0
- package/v3/standard-schema.cjs +19 -0
- package/v3/types.cjs +19 -0
- package/v4/classic/checks.cjs +20 -2
- package/v4/classic/checks.d.cts +1 -1
- package/v4/classic/checks.d.ts +1 -1
- package/v4/classic/checks.js +1 -1
- package/v4/classic/coerce.cjs +19 -0
- package/v4/classic/compat.cjs +19 -0
- package/v4/classic/deep-partial.cjs +19 -0
- package/v4/classic/errors.cjs +19 -0
- package/v4/classic/external.cjs +22 -1
- package/v4/classic/external.d.cts +1 -1
- package/v4/classic/external.d.ts +1 -1
- package/v4/classic/external.js +1 -1
- package/v4/classic/from-json-schema.cjs +264 -24
- package/v4/classic/from-json-schema.js +245 -24
- package/v4/classic/in-out.cjs +19 -0
- package/v4/classic/index.cjs +19 -0
- package/v4/classic/iso.cjs +19 -0
- package/v4/classic/parse.cjs +19 -0
- package/v4/classic/schemas.cjs +100 -31
- package/v4/classic/schemas.d.cts +17 -1
- package/v4/classic/schemas.d.ts +17 -1
- package/v4/classic/schemas.js +77 -29
- package/v4/core/api.cjs +37 -2
- package/v4/core/api.d.cts +6 -4
- package/v4/core/api.d.ts +6 -4
- package/v4/core/api.js +17 -2
- package/v4/core/checks.cjs +19 -96
- package/v4/core/checks.d.cts +1 -1
- package/v4/core/checks.d.ts +1 -1
- package/v4/core/checks.js +0 -96
- package/v4/core/compile.cjs +164 -65
- package/v4/core/compile.d.cts +18 -4
- package/v4/core/compile.d.ts +18 -4
- package/v4/core/compile.js +145 -66
- package/v4/core/core.cjs +19 -0
- package/v4/core/doc.cjs +26 -2
- package/v4/core/doc.js +7 -2
- package/v4/core/errors.cjs +21 -5
- package/v4/core/errors.js +2 -5
- package/v4/core/index.cjs +19 -0
- package/v4/core/json-schema-generator.cjs +20 -1
- package/v4/core/json-schema-generator.js +2 -2
- package/v4/core/json-schema-processors.cjs +215 -63
- package/v4/core/json-schema-processors.d.cts +17 -0
- package/v4/core/json-schema-processors.d.ts +17 -0
- package/v4/core/json-schema-processors.js +195 -64
- package/v4/core/json-schema.cjs +19 -0
- package/v4/core/memoizer.cjs +204 -36
- package/v4/core/memoizer.js +162 -36
- package/v4/core/parse.cjs +56 -16
- package/v4/core/parse.js +37 -16
- package/v4/core/regexes.cjs +29 -6
- package/v4/core/regexes.d.cts +2 -0
- package/v4/core/regexes.d.ts +2 -0
- package/v4/core/regexes.js +8 -4
- package/v4/core/registries.cjs +19 -0
- package/v4/core/schemas.cjs +285 -66
- package/v4/core/schemas.d.cts +34 -3
- package/v4/core/schemas.d.ts +34 -3
- package/v4/core/schemas.js +264 -65
- package/v4/core/standard-schema.cjs +19 -0
- package/v4/core/to-json-schema.cjs +29 -7
- package/v4/core/to-json-schema.d.cts +7 -3
- package/v4/core/to-json-schema.d.ts +7 -3
- package/v4/core/to-json-schema.js +8 -7
- package/v4/core/util.cjs +181 -143
- package/v4/core/util.d.cts +25 -4
- package/v4/core/util.d.ts +25 -4
- package/v4/core/util.js +160 -143
- package/v4/core/versions.cjs +21 -2
- package/v4/core/versions.d.cts +1 -1
- package/v4/core/versions.d.ts +1 -1
- package/v4/core/versions.js +2 -2
- package/v4/core/visit.cjs +31 -0
- package/v4/core/visit.js +12 -0
- package/v4/index.cjs +19 -0
- package/v4/locales/ar.cjs +1 -0
- package/v4/locales/ar.js +1 -0
- package/v4/locales/az.cjs +1 -0
- package/v4/locales/az.js +1 -0
- package/v4/locales/be.cjs +1 -0
- package/v4/locales/be.js +1 -0
- package/v4/locales/bg.cjs +1 -0
- package/v4/locales/bg.js +1 -0
- package/v4/locales/bn.cjs +1 -0
- package/v4/locales/bn.js +1 -0
- package/v4/locales/ca.cjs +1 -0
- package/v4/locales/ca.js +1 -0
- package/v4/locales/ckb.cjs +1 -0
- package/v4/locales/ckb.js +1 -0
- package/v4/locales/cs.cjs +1 -0
- package/v4/locales/cs.js +1 -0
- package/v4/locales/da.cjs +1 -0
- package/v4/locales/da.js +1 -0
- package/v4/locales/de.cjs +1 -0
- package/v4/locales/de.js +1 -0
- package/v4/locales/el.cjs +1 -0
- package/v4/locales/el.js +1 -0
- package/v4/locales/en.cjs +1 -0
- package/v4/locales/en.js +1 -0
- package/v4/locales/eo.cjs +1 -0
- package/v4/locales/eo.js +1 -0
- package/v4/locales/es.cjs +1 -0
- package/v4/locales/es.js +1 -0
- package/v4/locales/fa.cjs +1 -0
- package/v4/locales/fa.js +1 -0
- package/v4/locales/fi.cjs +1 -0
- package/v4/locales/fi.js +1 -0
- package/v4/locales/fr-CA.cjs +1 -0
- package/v4/locales/fr-CA.js +1 -0
- package/v4/locales/fr.cjs +1 -0
- package/v4/locales/fr.js +1 -0
- package/v4/locales/gu.cjs +1 -0
- package/v4/locales/gu.js +1 -0
- package/v4/locales/he.cjs +1 -0
- package/v4/locales/he.js +1 -0
- package/v4/locales/hi.cjs +1 -0
- package/v4/locales/hi.js +1 -0
- package/v4/locales/hr.cjs +1 -0
- package/v4/locales/hr.js +1 -0
- package/v4/locales/hu.cjs +1 -0
- package/v4/locales/hu.js +1 -0
- package/v4/locales/hy.cjs +1 -0
- package/v4/locales/hy.js +1 -0
- package/v4/locales/id.cjs +1 -0
- package/v4/locales/id.js +1 -0
- package/v4/locales/index.cjs +19 -0
- package/v4/locales/is.cjs +1 -0
- package/v4/locales/is.js +1 -0
- package/v4/locales/it.cjs +1 -0
- package/v4/locales/it.js +1 -0
- package/v4/locales/ja.cjs +1 -0
- package/v4/locales/ja.js +1 -0
- package/v4/locales/ka.cjs +1 -0
- package/v4/locales/ka.js +1 -0
- package/v4/locales/km.cjs +1 -0
- package/v4/locales/km.js +1 -0
- package/v4/locales/kn.cjs +1 -0
- package/v4/locales/kn.js +1 -0
- package/v4/locales/ko.cjs +1 -0
- package/v4/locales/ko.js +1 -0
- package/v4/locales/lt.cjs +1 -0
- package/v4/locales/lt.js +1 -0
- package/v4/locales/mk.cjs +1 -0
- package/v4/locales/mk.js +1 -0
- package/v4/locales/ms.cjs +1 -0
- package/v4/locales/ms.js +1 -0
- package/v4/locales/ne.cjs +1 -0
- package/v4/locales/ne.js +1 -0
- package/v4/locales/nl.cjs +1 -0
- package/v4/locales/nl.js +1 -0
- package/v4/locales/nn.cjs +1 -0
- package/v4/locales/nn.js +1 -0
- package/v4/locales/no.cjs +1 -0
- package/v4/locales/no.js +1 -0
- package/v4/locales/ota.cjs +1 -0
- package/v4/locales/ota.js +1 -0
- package/v4/locales/pl.cjs +1 -0
- package/v4/locales/pl.js +1 -0
- package/v4/locales/ps.cjs +1 -0
- package/v4/locales/ps.js +1 -0
- package/v4/locales/pt-BR.cjs +1 -0
- package/v4/locales/pt-BR.js +1 -0
- package/v4/locales/pt.cjs +1 -0
- package/v4/locales/pt.js +1 -0
- package/v4/locales/ro.cjs +1 -0
- package/v4/locales/ro.js +1 -0
- package/v4/locales/ru.cjs +1 -0
- package/v4/locales/ru.js +1 -0
- package/v4/locales/sk.cjs +1 -0
- package/v4/locales/sk.js +1 -0
- package/v4/locales/sl.cjs +1 -0
- package/v4/locales/sl.js +1 -0
- package/v4/locales/sv.cjs +1 -0
- package/v4/locales/sv.js +1 -0
- package/v4/locales/ta.cjs +1 -0
- package/v4/locales/ta.js +1 -0
- package/v4/locales/th.cjs +1 -0
- package/v4/locales/th.js +1 -0
- package/v4/locales/tk.cjs +1 -0
- package/v4/locales/tk.js +1 -0
- package/v4/locales/tr.cjs +1 -0
- package/v4/locales/tr.js +1 -0
- package/v4/locales/uk.cjs +1 -0
- package/v4/locales/uk.js +1 -0
- package/v4/locales/ur.cjs +1 -0
- package/v4/locales/ur.js +1 -0
- package/v4/locales/uz.cjs +1 -0
- package/v4/locales/uz.js +1 -0
- package/v4/locales/vi.cjs +1 -0
- package/v4/locales/vi.js +1 -0
- package/v4/locales/yo.cjs +1 -0
- package/v4/locales/yo.js +1 -0
- package/v4/locales/zh-CN.cjs +1 -0
- package/v4/locales/zh-CN.js +1 -0
- package/v4/locales/zh-TW.cjs +1 -0
- package/v4/locales/zh-TW.js +1 -0
- package/v4/mini/checks.cjs +20 -2
- package/v4/mini/checks.d.cts +1 -1
- package/v4/mini/checks.d.ts +1 -1
- package/v4/mini/checks.js +1 -1
- package/v4/mini/coerce.cjs +19 -0
- package/v4/mini/deep-partial.cjs +19 -0
- package/v4/mini/external.cjs +22 -1
- package/v4/mini/external.d.cts +1 -1
- package/v4/mini/external.d.ts +1 -1
- package/v4/mini/external.js +1 -1
- package/v4/mini/in-out.cjs +19 -0
- package/v4/mini/index.cjs +19 -0
- package/v4/mini/iso.cjs +19 -0
- package/v4/mini/parse.cjs +19 -0
- package/v4/mini/schemas.cjs +42 -4
- package/v4/mini/schemas.d.cts +8 -0
- package/v4/mini/schemas.d.ts +8 -0
- package/v4/mini/schemas.js +19 -2
- package/v4-mini/index.cjs +19 -0
package/v4/core/parse.cjs
CHANGED
|
@@ -72,26 +72,38 @@ const _safeParse = (_Err) => (schema, value, _ctx) => {
|
|
|
72
72
|
if (result instanceof Promise) {
|
|
73
73
|
throw new core.$ZodAsyncError();
|
|
74
74
|
}
|
|
75
|
-
return result.issues.length
|
|
76
|
-
? {
|
|
77
|
-
success: false,
|
|
78
|
-
error: new (_Err ?? errors.$ZodError)(result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config()))),
|
|
79
|
-
}
|
|
80
|
-
: { success: true, data: result.value };
|
|
75
|
+
return result.issues.length ? failure(_Err, result.issues, ctx) : { success: true, data: result.value };
|
|
81
76
|
};
|
|
82
77
|
exports._safeParse = _safeParse;
|
|
83
78
|
exports.safeParse = (0, exports._safeParse)(errors.$ZodRealError);
|
|
79
|
+
// the error is built on the first read of `error`: finalizing the issues and constructing the instance is most of a failing parse, and a caller that only branches on `success` never pays it. a getter in the literal keeps this small; the alternative, one shared accessor descriptor plus a hidden state slot, reads ~15% faster but costs ~75 B gzipped in every bundle
|
|
80
|
+
function failure(Err, issues, ctx) {
|
|
81
|
+
let error;
|
|
82
|
+
return {
|
|
83
|
+
success: false,
|
|
84
|
+
get error() {
|
|
85
|
+
if (!error) {
|
|
86
|
+
error = new Err(issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())));
|
|
87
|
+
// finalizeIssue drops `input`, so the built error holds nothing; keeping the raw issues past this point pins the parsed value for the life of the result
|
|
88
|
+
issues = undefined;
|
|
89
|
+
ctx = undefined;
|
|
90
|
+
}
|
|
91
|
+
return error;
|
|
92
|
+
},
|
|
93
|
+
set error(e) {
|
|
94
|
+
error = e;
|
|
95
|
+
// a replacement makes the getter's branch unreachable, so the captures have to go here too
|
|
96
|
+
issues = undefined;
|
|
97
|
+
ctx = undefined;
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
84
101
|
const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
|
|
85
102
|
const ctx = _ctx ? { ..._ctx, async: true } : { async: true };
|
|
86
103
|
let result = schema._zod.run({ value, issues: [] }, ctx);
|
|
87
104
|
if (result instanceof Promise)
|
|
88
105
|
result = await result;
|
|
89
|
-
return result.issues.length
|
|
90
|
-
? {
|
|
91
|
-
success: false,
|
|
92
|
-
error: new _Err(result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config()))),
|
|
93
|
-
}
|
|
94
|
-
: { success: true, data: result.value };
|
|
106
|
+
return result.issues.length ? failure(_Err, result.issues, ctx) : { success: true, data: result.value };
|
|
95
107
|
};
|
|
96
108
|
exports._safeParseAsync = _safeParseAsync;
|
|
97
109
|
exports.safeParseAsync = (0, exports._safeParseAsync)(errors.$ZodRealError);
|
|
@@ -101,12 +113,19 @@ const COMPILE_FALLBACK = /* @__PURE__ */ Symbol.for("zod.compile.fallback");
|
|
|
101
113
|
// Deliberately tiny, because v8 will not inline a body carrying the fallback's object literals and throw. Everything that is not the compiled happy path lives in validateFallback, and that split is worth ~35% on a compiled schema.
|
|
102
114
|
exports.validate = ((schema, value, _ctx) => {
|
|
103
115
|
const validator = schema._zod.bag.validator;
|
|
104
|
-
if (validator !== undefined
|
|
105
|
-
|
|
116
|
+
if (validator !== undefined) {
|
|
117
|
+
if (validator(value) !== COMPILE_INVALID)
|
|
118
|
+
return true;
|
|
119
|
+
// a definite sentinel means the runtime would reject, so skip the re-parse; a ctx can still change the answer
|
|
120
|
+
if (validator.definite === true && _ctx === undefined)
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
106
123
|
return validateFallback(schema, value, _ctx);
|
|
107
124
|
});
|
|
108
125
|
function validateFallback(schema, value, _ctx) {
|
|
109
|
-
const ctx = _ctx
|
|
126
|
+
const ctx = _ctx
|
|
127
|
+
? { ..._ctx, async: false, abortEarly: true }
|
|
128
|
+
: { async: false, abortEarly: true };
|
|
110
129
|
const fallbackRun = schema._zod.bag.fallbackRun;
|
|
111
130
|
let result;
|
|
112
131
|
if (fallbackRun) {
|
|
@@ -124,7 +143,9 @@ function validateFallback(schema, value, _ctx) {
|
|
|
124
143
|
}
|
|
125
144
|
// no fast path: the compiler keeps async parses on the runtime, because a promise-returning callback that is not declared async compiles to a throw
|
|
126
145
|
const validateAsync = async (schema, value, _ctx) => {
|
|
127
|
-
const ctx = _ctx
|
|
146
|
+
const ctx = _ctx
|
|
147
|
+
? { ..._ctx, async: true, abortEarly: true }
|
|
148
|
+
: { async: true, abortEarly: true };
|
|
128
149
|
let result = schema._zod.run({ value, issues: [] }, ctx);
|
|
129
150
|
if (result instanceof Promise)
|
|
130
151
|
result = await result;
|
|
@@ -191,3 +212,22 @@ const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
|
191
212
|
};
|
|
192
213
|
exports._safeDecodeAsync = _safeDecodeAsync;
|
|
193
214
|
exports.safeDecodeAsync = (0, exports._safeDecodeAsync)(errors.$ZodRealError);
|
|
215
|
+
|
|
216
|
+
// seal-cjs-exports
|
|
217
|
+
(function () {
|
|
218
|
+
var keys = Object.getOwnPropertyNames(exports);
|
|
219
|
+
for (var i = 0; i < keys.length; i++) {
|
|
220
|
+
var desc = Object.getOwnPropertyDescriptor(exports, keys[i]);
|
|
221
|
+
if (!desc || !desc.get || !desc.configurable) continue;
|
|
222
|
+
var value;
|
|
223
|
+
try {
|
|
224
|
+
value = desc.get();
|
|
225
|
+
} catch (e) {
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
// a circular require may not have settled this one yet, so leave it live
|
|
229
|
+
if (value === undefined) continue;
|
|
230
|
+
Object.defineProperty(exports, keys[i], { value: value, writable: false, enumerable: desc.enumerable, configurable: false });
|
|
231
|
+
}
|
|
232
|
+
Object.freeze(exports);
|
|
233
|
+
})();
|
package/v4/core/parse.js
CHANGED
|
@@ -44,25 +44,37 @@ export const _safeParse = (_Err) => (schema, value, _ctx) => {
|
|
|
44
44
|
if (result instanceof Promise) {
|
|
45
45
|
throw new core.$ZodAsyncError();
|
|
46
46
|
}
|
|
47
|
-
return result.issues.length
|
|
48
|
-
? {
|
|
49
|
-
success: false,
|
|
50
|
-
error: new (_Err ?? errors.$ZodError)(result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config()))),
|
|
51
|
-
}
|
|
52
|
-
: { success: true, data: result.value };
|
|
47
|
+
return result.issues.length ? failure(_Err, result.issues, ctx) : { success: true, data: result.value };
|
|
53
48
|
};
|
|
54
49
|
export const safeParse = /* @__PURE__*/ _safeParse(errors.$ZodRealError);
|
|
50
|
+
// the error is built on the first read of `error`: finalizing the issues and constructing the instance is most of a failing parse, and a caller that only branches on `success` never pays it. a getter in the literal keeps this small; the alternative, one shared accessor descriptor plus a hidden state slot, reads ~15% faster but costs ~75 B gzipped in every bundle
|
|
51
|
+
function failure(Err, issues, ctx) {
|
|
52
|
+
let error;
|
|
53
|
+
return {
|
|
54
|
+
success: false,
|
|
55
|
+
get error() {
|
|
56
|
+
if (!error) {
|
|
57
|
+
error = new Err(issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())));
|
|
58
|
+
// finalizeIssue drops `input`, so the built error holds nothing; keeping the raw issues past this point pins the parsed value for the life of the result
|
|
59
|
+
issues = undefined;
|
|
60
|
+
ctx = undefined;
|
|
61
|
+
}
|
|
62
|
+
return error;
|
|
63
|
+
},
|
|
64
|
+
set error(e) {
|
|
65
|
+
error = e;
|
|
66
|
+
// a replacement makes the getter's branch unreachable, so the captures have to go here too
|
|
67
|
+
issues = undefined;
|
|
68
|
+
ctx = undefined;
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
55
72
|
export const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
|
|
56
73
|
const ctx = _ctx ? { ..._ctx, async: true } : { async: true };
|
|
57
74
|
let result = schema._zod.run({ value, issues: [] }, ctx);
|
|
58
75
|
if (result instanceof Promise)
|
|
59
76
|
result = await result;
|
|
60
|
-
return result.issues.length
|
|
61
|
-
? {
|
|
62
|
-
success: false,
|
|
63
|
-
error: new _Err(result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config()))),
|
|
64
|
-
}
|
|
65
|
-
: { success: true, data: result.value };
|
|
77
|
+
return result.issues.length ? failure(_Err, result.issues, ctx) : { success: true, data: result.value };
|
|
66
78
|
};
|
|
67
79
|
export const safeParseAsync = /* @__PURE__*/ _safeParseAsync(errors.$ZodRealError);
|
|
68
80
|
// registry mirrors of the compiler's sentinels, so this module never imports the compiler
|
|
@@ -71,12 +83,19 @@ const COMPILE_FALLBACK = /* @__PURE__ */ Symbol.for("zod.compile.fallback");
|
|
|
71
83
|
// Deliberately tiny, because v8 will not inline a body carrying the fallback's object literals and throw. Everything that is not the compiled happy path lives in validateFallback, and that split is worth ~35% on a compiled schema.
|
|
72
84
|
export const validate = ((schema, value, _ctx) => {
|
|
73
85
|
const validator = schema._zod.bag.validator;
|
|
74
|
-
if (validator !== undefined
|
|
75
|
-
|
|
86
|
+
if (validator !== undefined) {
|
|
87
|
+
if (validator(value) !== COMPILE_INVALID)
|
|
88
|
+
return true;
|
|
89
|
+
// a definite sentinel means the runtime would reject, so skip the re-parse; a ctx can still change the answer
|
|
90
|
+
if (validator.definite === true && _ctx === undefined)
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
76
93
|
return validateFallback(schema, value, _ctx);
|
|
77
94
|
});
|
|
78
95
|
function validateFallback(schema, value, _ctx) {
|
|
79
|
-
const ctx = _ctx
|
|
96
|
+
const ctx = _ctx
|
|
97
|
+
? { ..._ctx, async: false, abortEarly: true }
|
|
98
|
+
: { async: false, abortEarly: true };
|
|
80
99
|
const fallbackRun = schema._zod.bag.fallbackRun;
|
|
81
100
|
let result;
|
|
82
101
|
if (fallbackRun) {
|
|
@@ -94,7 +113,9 @@ function validateFallback(schema, value, _ctx) {
|
|
|
94
113
|
}
|
|
95
114
|
// no fast path: the compiler keeps async parses on the runtime, because a promise-returning callback that is not declared async compiles to a throw
|
|
96
115
|
export const validateAsync = async (schema, value, _ctx) => {
|
|
97
|
-
const ctx = _ctx
|
|
116
|
+
const ctx = _ctx
|
|
117
|
+
? { ..._ctx, async: true, abortEarly: true }
|
|
118
|
+
: { async: true, abortEarly: true };
|
|
98
119
|
let result = schema._zod.run({ value, issues: [] }, ctx);
|
|
99
120
|
if (result instanceof Promise)
|
|
100
121
|
result = await result;
|
package/v4/core/regexes.cjs
CHANGED
|
@@ -23,8 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
27
|
-
exports.sha512_base64url = exports.sha512_base64 = exports.sha512_hex = exports.sha384_base64url = exports.sha384_base64 = exports.sha384_hex = exports.sha256_base64url = void 0;
|
|
26
|
+
exports.sha1_base64url = exports.sha1_base64 = exports.sha1_hex = exports.md5_base64url = exports.md5_base64 = exports.md5_hex = exports.hex = exports.uppercase = exports.lowercase = exports.undefined = exports.null = exports.boolean = exports.number = exports.integer = exports.bigint = exports.string = exports.anyString = exports.date = exports.iban = exports.creditCard = exports.e164 = exports.httpProtocol = exports.domain = exports.hostname = exports.base64url = exports.base64 = exports.cidrv6 = exports.cidrv4 = exports.mac = exports.ipv6 = exports.ipv4 = exports.browserEmail = exports.idnEmail = exports.unicodeEmail = exports.rfc5322Email = exports.html5Email = exports.email = exports.uuid7 = exports.uuid6 = exports.uuid4 = exports.uuid = exports.guid = exports.extendedDuration = exports.duration = exports.nanoid = exports.ksuid = exports.xid = exports.ulid = exports.cuid2 = exports.cuid = void 0;
|
|
27
|
+
exports.sha512_base64url = exports.sha512_base64 = exports.sha512_hex = exports.sha384_base64url = exports.sha384_base64 = exports.sha384_hex = exports.sha256_base64url = exports.sha256_base64 = exports.sha256_hex = void 0;
|
|
28
28
|
exports.nanoidOfLength = nanoidOfLength;
|
|
29
29
|
exports.emoji = emoji;
|
|
30
30
|
exports.time = time;
|
|
@@ -63,7 +63,7 @@ exports.uuid4 = (0, exports.uuid)(4);
|
|
|
63
63
|
exports.uuid6 = (0, exports.uuid)(6);
|
|
64
64
|
exports.uuid7 = (0, exports.uuid)(7);
|
|
65
65
|
/** Practical email validation */
|
|
66
|
-
exports.email = /^(
|
|
66
|
+
exports.email = /^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
|
|
67
67
|
/** Equivalent to the HTML5 input[type=email] validation implemented by browsers. Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/email */
|
|
68
68
|
exports.html5Email = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
69
69
|
/** The classic emailregex.com regex for RFC 5322-compliant emails */
|
|
@@ -73,8 +73,8 @@ exports.unicodeEmail = /^[^\s@"]{1,64}@[^\s@]{1,255}$/u;
|
|
|
73
73
|
exports.idnEmail = exports.unicodeEmail;
|
|
74
74
|
exports.browserEmail = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
75
75
|
// from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
|
|
76
|
-
// Single character class, not an alternation: the two properties overlap (U+1F9B0-U+1F9B3), so `(A|B)+` backtracks exponentially on a failed match.
|
|
77
|
-
const _emoji = `^[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`;
|
|
76
|
+
// Single character class, not an alternation: the two properties overlap (U+1F9B0-U+1F9B3), so `(A|B)+` backtracks exponentially on a failed match. The leading lookahead then demands one anchor — a pictograph, a regional indicator, or the enclosing keycap — because `\p{Emoji_Component}` on its own covers ASCII digits, `#`, `*`, ZWJ, variation selectors and skin tone modifiers, none of which is an emoji without a base.
|
|
77
|
+
const _emoji = `^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`;
|
|
78
78
|
function emoji() {
|
|
79
79
|
return new RegExp(_emoji, "u");
|
|
80
80
|
}
|
|
@@ -89,7 +89,7 @@ exports.cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[
|
|
|
89
89
|
exports.cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
90
90
|
// https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
|
|
91
91
|
exports.base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
|
|
92
|
-
exports.base64url = /^[A-Za-z0-9_-]
|
|
92
|
+
exports.base64url = /^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/;
|
|
93
93
|
// based on https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address
|
|
94
94
|
// export const hostname: RegExp = /^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/;
|
|
95
95
|
exports.hostname = /^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/;
|
|
@@ -99,6 +99,8 @@ exports.httpProtocol = /^https?$/;
|
|
|
99
99
|
exports.e164 = /^\+[1-9]\d{6,14}$/;
|
|
100
100
|
// Credit card shape: 12–19 digits, optionally separated by single spaces or single hyphens. ISO/IEC 7812 caps the PAN at 19 digits; 12 is the shortest issued length (Maestro).
|
|
101
101
|
exports.creditCard = /^\d(?:[ -]?\d){11,18}$/;
|
|
102
|
+
// iban electronic format: 2-letter country, check digits 02-98 (the only values `98 - remainder` can produce), 11-30 bban characters
|
|
103
|
+
exports.iban = /^[A-Z]{2}(?!00|01|99)\d{2}[A-Z0-9]{11,30}$/;
|
|
102
104
|
const dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;
|
|
103
105
|
/** Anchors a pattern source. The interpolation lives here rather than at the call site because
|
|
104
106
|
* esbuild will not drop a `@__PURE__` call whose own argument interpolates a variable, but it
|
|
@@ -134,6 +136,8 @@ function datetime(args) {
|
|
|
134
136
|
const timeRegex = args.local ? `${qualified}|${timeSource({ precision: args.precision })}` : qualified;
|
|
135
137
|
return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
|
|
136
138
|
}
|
|
139
|
+
// the unbounded form of `string()` as a literal, so every plain string shares one instance instead of building its own
|
|
140
|
+
exports.anyString = /^[\s\S]{0,}$/;
|
|
137
141
|
const string = (params) => {
|
|
138
142
|
const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
|
|
139
143
|
return new RegExp(`^${regex}$`);
|
|
@@ -182,3 +186,22 @@ exports.sha384_base64url = fixedBase64url(64);
|
|
|
182
186
|
exports.sha512_hex = /^[0-9a-fA-F]{128}$/;
|
|
183
187
|
exports.sha512_base64 = fixedBase64(86, "==");
|
|
184
188
|
exports.sha512_base64url = fixedBase64url(86);
|
|
189
|
+
|
|
190
|
+
// seal-cjs-exports
|
|
191
|
+
(function () {
|
|
192
|
+
var keys = Object.getOwnPropertyNames(exports);
|
|
193
|
+
for (var i = 0; i < keys.length; i++) {
|
|
194
|
+
var desc = Object.getOwnPropertyDescriptor(exports, keys[i]);
|
|
195
|
+
if (!desc || !desc.get || !desc.configurable) continue;
|
|
196
|
+
var value;
|
|
197
|
+
try {
|
|
198
|
+
value = desc.get();
|
|
199
|
+
} catch (e) {
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
// a circular require may not have settled this one yet, so leave it live
|
|
203
|
+
if (value === undefined) continue;
|
|
204
|
+
Object.defineProperty(exports, keys[i], { value: value, writable: false, enumerable: desc.enumerable, configurable: false });
|
|
205
|
+
}
|
|
206
|
+
Object.freeze(exports);
|
|
207
|
+
})();
|
package/v4/core/regexes.d.cts
CHANGED
|
@@ -46,6 +46,7 @@ export declare const domain: RegExp;
|
|
|
46
46
|
export declare const httpProtocol: RegExp;
|
|
47
47
|
export declare const e164: RegExp;
|
|
48
48
|
export declare const creditCard: RegExp;
|
|
49
|
+
export declare const iban: RegExp;
|
|
49
50
|
export declare const date: RegExp;
|
|
50
51
|
export declare function time(args: {
|
|
51
52
|
precision?: number | null;
|
|
@@ -55,6 +56,7 @@ export declare function datetime(args: {
|
|
|
55
56
|
offset?: boolean;
|
|
56
57
|
local?: boolean;
|
|
57
58
|
}): RegExp;
|
|
59
|
+
export declare const anyString: RegExp;
|
|
58
60
|
export declare const string: (params?: {
|
|
59
61
|
minimum?: number | undefined;
|
|
60
62
|
maximum?: number | undefined;
|
package/v4/core/regexes.d.ts
CHANGED
|
@@ -46,6 +46,7 @@ export declare const domain: RegExp;
|
|
|
46
46
|
export declare const httpProtocol: RegExp;
|
|
47
47
|
export declare const e164: RegExp;
|
|
48
48
|
export declare const creditCard: RegExp;
|
|
49
|
+
export declare const iban: RegExp;
|
|
49
50
|
export declare const date: RegExp;
|
|
50
51
|
export declare function time(args: {
|
|
51
52
|
precision?: number | null;
|
|
@@ -55,6 +56,7 @@ export declare function datetime(args: {
|
|
|
55
56
|
offset?: boolean;
|
|
56
57
|
local?: boolean;
|
|
57
58
|
}): RegExp;
|
|
59
|
+
export declare const anyString: RegExp;
|
|
58
60
|
export declare const string: (params?: {
|
|
59
61
|
minimum?: number | undefined;
|
|
60
62
|
maximum?: number | undefined;
|
package/v4/core/regexes.js
CHANGED
|
@@ -31,7 +31,7 @@ export const uuid4 = /*@__PURE__*/ uuid(4);
|
|
|
31
31
|
export const uuid6 = /*@__PURE__*/ uuid(6);
|
|
32
32
|
export const uuid7 = /*@__PURE__*/ uuid(7);
|
|
33
33
|
/** Practical email validation */
|
|
34
|
-
export const email = /^(
|
|
34
|
+
export const email = /^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
|
|
35
35
|
/** Equivalent to the HTML5 input[type=email] validation implemented by browsers. Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/email */
|
|
36
36
|
export const html5Email = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
37
37
|
/** The classic emailregex.com regex for RFC 5322-compliant emails */
|
|
@@ -41,8 +41,8 @@ export const unicodeEmail = /^[^\s@"]{1,64}@[^\s@]{1,255}$/u;
|
|
|
41
41
|
export const idnEmail = unicodeEmail;
|
|
42
42
|
export const browserEmail = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
43
43
|
// from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
|
|
44
|
-
// Single character class, not an alternation: the two properties overlap (U+1F9B0-U+1F9B3), so `(A|B)+` backtracks exponentially on a failed match.
|
|
45
|
-
const _emoji = `^[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`;
|
|
44
|
+
// Single character class, not an alternation: the two properties overlap (U+1F9B0-U+1F9B3), so `(A|B)+` backtracks exponentially on a failed match. The leading lookahead then demands one anchor — a pictograph, a regional indicator, or the enclosing keycap — because `\p{Emoji_Component}` on its own covers ASCII digits, `#`, `*`, ZWJ, variation selectors and skin tone modifiers, none of which is an emoji without a base.
|
|
45
|
+
const _emoji = `^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`;
|
|
46
46
|
export function emoji() {
|
|
47
47
|
return new RegExp(_emoji, "u");
|
|
48
48
|
}
|
|
@@ -56,7 +56,7 @@ export const cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3
|
|
|
56
56
|
export const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
57
57
|
// https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
|
|
58
58
|
export const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
|
|
59
|
-
export const base64url = /^[A-Za-z0-9_-]
|
|
59
|
+
export const base64url = /^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/;
|
|
60
60
|
// based on https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address
|
|
61
61
|
// export const hostname: RegExp = /^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/;
|
|
62
62
|
export const hostname = /^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/;
|
|
@@ -66,6 +66,8 @@ export const httpProtocol = /^https?$/;
|
|
|
66
66
|
export const e164 = /^\+[1-9]\d{6,14}$/;
|
|
67
67
|
// Credit card shape: 12–19 digits, optionally separated by single spaces or single hyphens. ISO/IEC 7812 caps the PAN at 19 digits; 12 is the shortest issued length (Maestro).
|
|
68
68
|
export const creditCard = /^\d(?:[ -]?\d){11,18}$/;
|
|
69
|
+
// iban electronic format: 2-letter country, check digits 02-98 (the only values `98 - remainder` can produce), 11-30 bban characters
|
|
70
|
+
export const iban = /^[A-Z]{2}(?!00|01|99)\d{2}[A-Z0-9]{11,30}$/;
|
|
69
71
|
const dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;
|
|
70
72
|
/** Anchors a pattern source. The interpolation lives here rather than at the call site because
|
|
71
73
|
* esbuild will not drop a `@__PURE__` call whose own argument interpolates a variable, but it
|
|
@@ -101,6 +103,8 @@ export function datetime(args) {
|
|
|
101
103
|
const timeRegex = args.local ? `${qualified}|${timeSource({ precision: args.precision })}` : qualified;
|
|
102
104
|
return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
|
|
103
105
|
}
|
|
106
|
+
// the unbounded form of `string()` as a literal, so every plain string shares one instance instead of building its own
|
|
107
|
+
export const anyString = /^[\s\S]{0,}$/;
|
|
104
108
|
export const string = (params) => {
|
|
105
109
|
const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
|
|
106
110
|
return new RegExp(`^${regex}$`);
|
package/v4/core/registries.cjs
CHANGED
|
@@ -54,3 +54,22 @@ function registry() {
|
|
|
54
54
|
}
|
|
55
55
|
(_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
|
|
56
56
|
exports.globalRegistry = globalThis.__zod_globalRegistry;
|
|
57
|
+
|
|
58
|
+
// seal-cjs-exports
|
|
59
|
+
(function () {
|
|
60
|
+
var keys = Object.getOwnPropertyNames(exports);
|
|
61
|
+
for (var i = 0; i < keys.length; i++) {
|
|
62
|
+
var desc = Object.getOwnPropertyDescriptor(exports, keys[i]);
|
|
63
|
+
if (!desc || !desc.get || !desc.configurable) continue;
|
|
64
|
+
var value;
|
|
65
|
+
try {
|
|
66
|
+
value = desc.get();
|
|
67
|
+
} catch (e) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
// a circular require may not have settled this one yet, so leave it live
|
|
71
|
+
if (value === undefined) continue;
|
|
72
|
+
Object.defineProperty(exports, keys[i], { value: value, writable: false, enumerable: desc.enumerable, configurable: false });
|
|
73
|
+
}
|
|
74
|
+
Object.freeze(exports);
|
|
75
|
+
})();
|