zod 3.26.0-canary.20250616T222346 → 3.26.0-canary.20250618T044324

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.
@@ -69,6 +69,8 @@ const errorMap = (issue, _ctx) => {
69
69
  message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
70
70
  else if (issue.type === "number")
71
71
  message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
72
+ else if (issue.type === "bigint")
73
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
72
74
  else if (issue.type === "date")
73
75
  message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
74
76
  else
@@ -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.ZodOptional = exports.ZodTransform = exports.ZodFile = exports.ZodLiteral = exports.ZodEnum = exports.ZodSet = exports.ZodMap = exports.ZodRecord = exports.ZodTuple = exports.ZodIntersection = exports.ZodDiscriminatedUnion = exports.ZodUnion = exports.ZodObject = exports.ZodArray = exports.ZodDate = exports.ZodVoid = exports.ZodNever = exports.ZodUnknown = exports.ZodAny = exports.ZodNull = exports.ZodUndefined = exports.ZodSymbol = exports.ZodBigIntFormat = exports.ZodBigInt = exports.ZodBoolean = exports.ZodNumberFormat = exports.ZodNumber = exports.ZodJWT = exports.ZodE164 = exports.ZodBase64URL = exports.ZodBase64 = exports.ZodCIDRv6 = exports.ZodCIDRv4 = exports.ZodIPv6 = exports.ZodIPv4 = exports.ZodKSUID = exports.ZodXID = exports.ZodULID = exports.ZodCUID2 = exports.ZodCUID = exports.ZodNanoID = exports.ZodEmoji = exports.ZodURL = exports.ZodUUID = exports.ZodGUID = exports.ZodEmail = exports.ZodStringFormat = exports.ZodString = exports._ZodString = exports.ZodType = void 0;
27
- exports.stringbool = exports.ZodCustom = exports.ZodPromise = exports.ZodLazy = exports.ZodTemplateLiteral = exports.ZodReadonly = exports.ZodPipe = exports.ZodNaN = exports.ZodCatch = exports.ZodSuccess = exports.ZodNonOptional = exports.ZodPrefault = exports.ZodDefault = exports.ZodNullable = void 0;
26
+ exports.ZodTransform = exports.ZodFile = exports.ZodLiteral = exports.ZodEnum = exports.ZodSet = exports.ZodMap = exports.ZodRecord = exports.ZodTuple = exports.ZodIntersection = exports.ZodDiscriminatedUnion = exports.ZodUnion = exports.ZodObject = exports.ZodArray = exports.ZodDate = exports.ZodVoid = exports.ZodNever = exports.ZodUnknown = exports.ZodAny = exports.ZodNull = exports.ZodUndefined = exports.ZodSymbol = exports.ZodBigIntFormat = exports.ZodBigInt = exports.ZodBoolean = exports.ZodNumberFormat = exports.ZodNumber = exports.ZodCustomStringFormat = exports.ZodJWT = exports.ZodE164 = exports.ZodBase64URL = exports.ZodBase64 = exports.ZodCIDRv6 = exports.ZodCIDRv4 = exports.ZodIPv6 = exports.ZodIPv4 = exports.ZodKSUID = exports.ZodXID = exports.ZodULID = exports.ZodCUID2 = exports.ZodCUID = exports.ZodNanoID = exports.ZodEmoji = exports.ZodURL = exports.ZodUUID = exports.ZodGUID = exports.ZodEmail = exports.ZodStringFormat = exports.ZodString = exports._ZodString = exports.ZodType = void 0;
27
+ exports.stringbool = exports.ZodCustom = exports.ZodPromise = exports.ZodLazy = exports.ZodTemplateLiteral = exports.ZodReadonly = exports.ZodPipe = exports.ZodNaN = exports.ZodCatch = exports.ZodSuccess = exports.ZodNonOptional = exports.ZodPrefault = exports.ZodDefault = exports.ZodNullable = exports.ZodOptional = void 0;
28
28
  exports.string = string;
29
29
  exports.email = email;
30
30
  exports.guid = guid;
@@ -48,6 +48,7 @@ exports.base64 = base64;
48
48
  exports.base64url = base64url;
49
49
  exports.e164 = e164;
50
50
  exports.jwt = jwt;
51
+ exports.stringFormat = stringFormat;
51
52
  exports.number = number;
52
53
  exports.int = int;
53
54
  exports.float32 = float32;
@@ -407,6 +408,14 @@ exports.ZodJWT = core.$constructor("ZodJWT", (inst, def) => {
407
408
  function jwt(params) {
408
409
  return core._jwt(exports.ZodJWT, params);
409
410
  }
411
+ exports.ZodCustomStringFormat = core.$constructor("ZodCustomStringFormat", (inst, def) => {
412
+ // ZodStringFormat.init(inst, def);
413
+ core.$ZodCustomStringFormat.init(inst, def);
414
+ exports.ZodStringFormat.init(inst, def);
415
+ });
416
+ function stringFormat(format, fnOrRegex, _params = {}) {
417
+ return core._stringFormat(exports.ZodCustomStringFormat, format, fnOrRegex, _params);
418
+ }
410
419
  exports.ZodNumber = core.$constructor("ZodNumber", (inst, def) => {
411
420
  core.$ZodNumber.init(inst, def);
412
421
  exports.ZodType.init(inst, def);
@@ -136,6 +136,7 @@ exports._promise = _promise;
136
136
  exports._custom = _custom;
137
137
  exports._refine = _refine;
138
138
  exports._stringbool = _stringbool;
139
+ exports._stringFormat = _stringFormat;
139
140
  const checks = __importStar(require("./checks.js"));
140
141
  const schemas = __importStar(require("./schemas.js"));
141
142
  const util = __importStar(require("./util.js"));
@@ -1019,3 +1020,19 @@ function _stringbool(Classes, _params) {
1019
1020
  });
1020
1021
  return outerPipe;
1021
1022
  }
1023
+ function _stringFormat(Class, format, fnOrRegex, _params = {}) {
1024
+ const params = util.normalizeParams(_params);
1025
+ const def = {
1026
+ ...util.normalizeParams(_params),
1027
+ check: "string_format",
1028
+ type: "string",
1029
+ format,
1030
+ fn: typeof fnOrRegex === "function" ? fnOrRegex : (val) => fnOrRegex.test(val),
1031
+ ...params,
1032
+ };
1033
+ if (fnOrRegex instanceof RegExp) {
1034
+ def.pattern = fnOrRegex;
1035
+ }
1036
+ const inst = new Class(def);
1037
+ return inst;
1038
+ }
@@ -403,7 +403,9 @@ exports.$ZodCheckLengthEquals = core.$constructor("$ZodCheckLengthEquals", (inst
403
403
  const tooBig = length > def.length;
404
404
  payload.issues.push({
405
405
  origin,
406
- ...(tooBig ? { code: "too_big", maximum: def.length } : { code: "too_small", minimum: def.length }),
406
+ ...(tooBig
407
+ ? { code: "too_big", maximum: def.length, exact: true }
408
+ : { code: "too_small", minimum: def.length, exact: true }),
407
409
  input: payload.value,
408
410
  inst,
409
411
  continue: !def.abort,
@@ -411,7 +413,7 @@ exports.$ZodCheckLengthEquals = core.$constructor("$ZodCheckLengthEquals", (inst
411
413
  };
412
414
  });
413
415
  exports.$ZodCheckStringFormat = core.$constructor("$ZodCheckStringFormat", (inst, def) => {
414
- var _a;
416
+ var _a, _b;
415
417
  exports.$ZodCheck.init(inst, def);
416
418
  inst._zod.onattach.push((inst) => {
417
419
  const bag = inst._zod.bag;
@@ -421,22 +423,23 @@ exports.$ZodCheckStringFormat = core.$constructor("$ZodCheckStringFormat", (inst
421
423
  bag.patterns.add(def.pattern);
422
424
  }
423
425
  });
424
- (_a = inst._zod).check ?? (_a.check = (payload) => {
425
- if (!def.pattern)
426
- throw new Error("Not implemented.");
427
- def.pattern.lastIndex = 0;
428
- if (def.pattern.test(payload.value))
429
- return;
430
- payload.issues.push({
431
- origin: "string",
432
- code: "invalid_format",
433
- format: def.format,
434
- input: payload.value,
435
- ...(def.pattern ? { pattern: def.pattern.toString() } : {}),
436
- inst,
437
- continue: !def.abort,
426
+ if (def.pattern)
427
+ (_a = inst._zod).check ?? (_a.check = (payload) => {
428
+ def.pattern.lastIndex = 0;
429
+ if (def.pattern.test(payload.value))
430
+ return;
431
+ payload.issues.push({
432
+ origin: "string",
433
+ code: "invalid_format",
434
+ format: def.format,
435
+ input: payload.value,
436
+ ...(def.pattern ? { pattern: def.pattern.toString() } : {}),
437
+ inst,
438
+ continue: !def.abort,
439
+ });
438
440
  });
439
- });
441
+ else
442
+ (_b = inst._zod).check ?? (_b.check = () => { });
440
443
  });
441
444
  exports.$ZodCheckRegex = core.$constructor("$ZodCheckRegex", (inst, def) => {
442
445
  exports.$ZodCheckStringFormat.init(inst, def);
@@ -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.$ZodEnum = exports.$ZodSet = exports.$ZodMap = exports.$ZodRecord = exports.$ZodTuple = exports.$ZodIntersection = exports.$ZodDiscriminatedUnion = exports.$ZodUnion = exports.$ZodObject = exports.$ZodArray = exports.$ZodDate = exports.$ZodVoid = exports.$ZodNever = exports.$ZodUnknown = exports.$ZodAny = exports.$ZodNull = exports.$ZodUndefined = exports.$ZodSymbol = exports.$ZodBigIntFormat = exports.$ZodBigInt = exports.$ZodBoolean = exports.$ZodNumberFormat = exports.$ZodNumber = exports.$ZodJWT = exports.$ZodE164 = exports.$ZodBase64URL = exports.$ZodBase64 = exports.$ZodCIDRv6 = exports.$ZodCIDRv4 = exports.$ZodIPv6 = exports.$ZodIPv4 = exports.$ZodISODuration = exports.$ZodISOTime = exports.$ZodISODate = exports.$ZodISODateTime = exports.$ZodKSUID = exports.$ZodXID = exports.$ZodULID = exports.$ZodCUID2 = exports.$ZodCUID = exports.$ZodNanoID = exports.$ZodEmoji = exports.$ZodURL = exports.$ZodEmail = exports.$ZodUUID = exports.$ZodGUID = exports.$ZodStringFormat = exports.$ZodString = exports.clone = exports.$ZodType = void 0;
27
- exports.$ZodCustom = exports.$ZodLazy = exports.$ZodPromise = exports.$ZodTemplateLiteral = exports.$ZodReadonly = exports.$ZodPipe = exports.$ZodNaN = exports.$ZodCatch = exports.$ZodSuccess = exports.$ZodNonOptional = exports.$ZodPrefault = exports.$ZodDefault = exports.$ZodNullable = exports.$ZodOptional = exports.$ZodTransform = exports.$ZodFile = exports.$ZodLiteral = void 0;
26
+ exports.$ZodSet = exports.$ZodMap = exports.$ZodRecord = exports.$ZodTuple = exports.$ZodIntersection = exports.$ZodDiscriminatedUnion = exports.$ZodUnion = exports.$ZodObject = exports.$ZodArray = exports.$ZodDate = exports.$ZodVoid = exports.$ZodNever = exports.$ZodUnknown = exports.$ZodAny = exports.$ZodNull = exports.$ZodUndefined = exports.$ZodSymbol = exports.$ZodBigIntFormat = exports.$ZodBigInt = exports.$ZodBoolean = exports.$ZodNumberFormat = exports.$ZodNumber = exports.$ZodCustomStringFormat = exports.$ZodJWT = exports.$ZodE164 = exports.$ZodBase64URL = exports.$ZodBase64 = exports.$ZodCIDRv6 = exports.$ZodCIDRv4 = exports.$ZodIPv6 = exports.$ZodIPv4 = exports.$ZodISODuration = exports.$ZodISOTime = exports.$ZodISODate = exports.$ZodISODateTime = exports.$ZodKSUID = exports.$ZodXID = exports.$ZodULID = exports.$ZodCUID2 = exports.$ZodCUID = exports.$ZodNanoID = exports.$ZodEmoji = exports.$ZodURL = exports.$ZodEmail = exports.$ZodUUID = exports.$ZodGUID = exports.$ZodStringFormat = exports.$ZodString = exports.clone = exports.$ZodType = void 0;
27
+ exports.$ZodCustom = exports.$ZodLazy = exports.$ZodPromise = exports.$ZodTemplateLiteral = exports.$ZodReadonly = exports.$ZodPipe = exports.$ZodNaN = exports.$ZodCatch = exports.$ZodSuccess = exports.$ZodNonOptional = exports.$ZodPrefault = exports.$ZodDefault = exports.$ZodNullable = exports.$ZodOptional = exports.$ZodTransform = exports.$ZodFile = exports.$ZodLiteral = exports.$ZodEnum = void 0;
28
28
  exports.isValidBase64 = isValidBase64;
29
29
  exports.isValidBase64URL = isValidBase64URL;
30
30
  exports.isValidJWT = isValidJWT;
@@ -434,6 +434,20 @@ exports.$ZodJWT = core.$constructor("$ZodJWT", (inst, def) => {
434
434
  });
435
435
  };
436
436
  });
437
+ exports.$ZodCustomStringFormat = core.$constructor("$ZodCustomStringFormat", (inst, def) => {
438
+ exports.$ZodStringFormat.init(inst, def);
439
+ inst._zod.check = (payload) => {
440
+ if (def.fn(payload.value))
441
+ return;
442
+ payload.issues.push({
443
+ code: "invalid_format",
444
+ format: def.format,
445
+ input: payload.value,
446
+ inst,
447
+ continue: !def.abort,
448
+ });
449
+ };
450
+ });
437
451
  exports.$ZodNumber = core.$constructor("$ZodNumber", (inst, def) => {
438
452
  exports.$ZodType.init(inst, def);
439
453
  inst._zod.pattern = inst._zod.bag.pattern ?? regexes.number;
@@ -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.ZodMiniNullable = exports.ZodMiniOptional = exports.ZodMiniTransform = exports.ZodMiniFile = exports.ZodMiniLiteral = exports.ZodMiniEnum = exports.ZodMiniSet = exports.ZodMiniMap = exports.ZodMiniRecord = exports.ZodMiniTuple = exports.ZodMiniIntersection = exports.ZodMiniDiscriminatedUnion = exports.ZodMiniUnion = exports.ZodMiniObject = exports.ZodMiniArray = exports.ZodMiniDate = exports.ZodMiniVoid = exports.ZodMiniNever = exports.ZodMiniUnknown = exports.ZodMiniAny = exports.ZodMiniNull = exports.ZodMiniUndefined = exports.ZodMiniSymbol = exports.ZodMiniBigIntFormat = exports.ZodMiniBigInt = exports.ZodMiniBoolean = exports.ZodMiniNumberFormat = exports.ZodMiniNumber = exports.ZodMiniJWT = exports.ZodMiniE164 = exports.ZodMiniBase64URL = exports.ZodMiniBase64 = exports.ZodMiniCIDRv6 = exports.ZodMiniCIDRv4 = exports.ZodMiniIPv6 = exports.ZodMiniIPv4 = exports.ZodMiniKSUID = exports.ZodMiniXID = exports.ZodMiniULID = exports.ZodMiniCUID2 = exports.ZodMiniCUID = exports.ZodMiniNanoID = exports.ZodMiniEmoji = exports.ZodMiniURL = exports.ZodMiniUUID = exports.ZodMiniGUID = exports.ZodMiniEmail = exports.ZodMiniStringFormat = exports.ZodMiniString = exports.ZodMiniType = void 0;
27
- exports.stringbool = exports.ZodMiniCustom = exports.ZodMiniPromise = exports.ZodMiniLazy = exports.ZodMiniTemplateLiteral = exports.ZodMiniReadonly = exports.ZodMiniPipe = exports.ZodMiniNaN = exports.ZodMiniCatch = exports.ZodMiniSuccess = exports.ZodMiniNonOptional = exports.ZodMiniPrefault = exports.ZodMiniDefault = void 0;
26
+ exports.ZodMiniOptional = exports.ZodMiniTransform = exports.ZodMiniFile = exports.ZodMiniLiteral = exports.ZodMiniEnum = exports.ZodMiniSet = exports.ZodMiniMap = exports.ZodMiniRecord = exports.ZodMiniTuple = exports.ZodMiniIntersection = exports.ZodMiniDiscriminatedUnion = exports.ZodMiniUnion = exports.ZodMiniObject = exports.ZodMiniArray = exports.ZodMiniDate = exports.ZodMiniVoid = exports.ZodMiniNever = exports.ZodMiniUnknown = exports.ZodMiniAny = exports.ZodMiniNull = exports.ZodMiniUndefined = exports.ZodMiniSymbol = exports.ZodMiniBigIntFormat = exports.ZodMiniBigInt = exports.ZodMiniBoolean = exports.ZodMiniNumberFormat = exports.ZodMiniNumber = exports.ZodMiniCustomStringFormat = exports.ZodMiniJWT = exports.ZodMiniE164 = exports.ZodMiniBase64URL = exports.ZodMiniBase64 = exports.ZodMiniCIDRv6 = exports.ZodMiniCIDRv4 = exports.ZodMiniIPv6 = exports.ZodMiniIPv4 = exports.ZodMiniKSUID = exports.ZodMiniXID = exports.ZodMiniULID = exports.ZodMiniCUID2 = exports.ZodMiniCUID = exports.ZodMiniNanoID = exports.ZodMiniEmoji = exports.ZodMiniURL = exports.ZodMiniUUID = exports.ZodMiniGUID = exports.ZodMiniEmail = exports.ZodMiniStringFormat = exports.ZodMiniString = exports.ZodMiniType = void 0;
27
+ exports.stringbool = exports.ZodMiniCustom = exports.ZodMiniPromise = exports.ZodMiniLazy = exports.ZodMiniTemplateLiteral = exports.ZodMiniReadonly = exports.ZodMiniPipe = exports.ZodMiniNaN = exports.ZodMiniCatch = exports.ZodMiniSuccess = exports.ZodMiniNonOptional = exports.ZodMiniPrefault = exports.ZodMiniDefault = exports.ZodMiniNullable = void 0;
28
28
  exports.string = string;
29
29
  exports.email = email;
30
30
  exports.guid = guid;
@@ -48,6 +48,7 @@ exports.base64 = base64;
48
48
  exports.base64url = base64url;
49
49
  exports.e164 = e164;
50
50
  exports.jwt = jwt;
51
+ exports.stringFormat = stringFormat;
51
52
  exports.number = number;
52
53
  exports.int = int;
53
54
  exports.float32 = float32;
@@ -295,6 +296,13 @@ exports.ZodMiniJWT = core.$constructor("ZodMiniJWT", (inst, def) => {
295
296
  function jwt(params) {
296
297
  return core._jwt(exports.ZodMiniJWT, params);
297
298
  }
299
+ exports.ZodMiniCustomStringFormat = core.$constructor("ZodMiniCustomStringFormat", (inst, def) => {
300
+ core.$ZodCustomStringFormat.init(inst, def);
301
+ exports.ZodMiniStringFormat.init(inst, def);
302
+ });
303
+ function stringFormat(format, fnOrRegex, _params = {}) {
304
+ return core._stringFormat(exports.ZodMiniCustomStringFormat, format, fnOrRegex, _params);
305
+ }
298
306
  exports.ZodMiniNumber = core.$constructor("ZodMiniNumber", (inst, def) => {
299
307
  core.$ZodNumber.init(inst, def);
300
308
  exports.ZodMiniType.init(inst, def);
@@ -67,6 +67,8 @@ const errorMap = (issue, _ctx) => {
67
67
  message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
68
68
  else if (issue.type === "number")
69
69
  message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
70
+ else if (issue.type === "bigint")
71
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
70
72
  else if (issue.type === "date")
71
73
  message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
72
74
  else
@@ -300,6 +300,14 @@ export const ZodJWT = /*@__PURE__*/ core.$constructor("ZodJWT", (inst, def) => {
300
300
  export function jwt(params) {
301
301
  return core._jwt(ZodJWT, params);
302
302
  }
303
+ export const ZodCustomStringFormat = /*@__PURE__*/ core.$constructor("ZodCustomStringFormat", (inst, def) => {
304
+ // ZodStringFormat.init(inst, def);
305
+ core.$ZodCustomStringFormat.init(inst, def);
306
+ ZodStringFormat.init(inst, def);
307
+ });
308
+ export function stringFormat(format, fnOrRegex, _params = {}) {
309
+ return core._stringFormat(ZodCustomStringFormat, format, fnOrRegex, _params);
310
+ }
303
311
  export const ZodNumber = /*@__PURE__*/ core.$constructor("ZodNumber", (inst, def) => {
304
312
  core.$ZodNumber.init(inst, def);
305
313
  ZodType.init(inst, def);
@@ -887,3 +887,19 @@ export function _stringbool(Classes, _params) {
887
887
  });
888
888
  return outerPipe;
889
889
  }
890
+ export function _stringFormat(Class, format, fnOrRegex, _params = {}) {
891
+ const params = util.normalizeParams(_params);
892
+ const def = {
893
+ ...util.normalizeParams(_params),
894
+ check: "string_format",
895
+ type: "string",
896
+ format,
897
+ fn: typeof fnOrRegex === "function" ? fnOrRegex : (val) => fnOrRegex.test(val),
898
+ ...params,
899
+ };
900
+ if (fnOrRegex instanceof RegExp) {
901
+ def.pattern = fnOrRegex;
902
+ }
903
+ const inst = new Class(def);
904
+ return inst;
905
+ }
@@ -377,7 +377,9 @@ export const $ZodCheckLengthEquals = /*@__PURE__*/ core.$constructor("$ZodCheckL
377
377
  const tooBig = length > def.length;
378
378
  payload.issues.push({
379
379
  origin,
380
- ...(tooBig ? { code: "too_big", maximum: def.length } : { code: "too_small", minimum: def.length }),
380
+ ...(tooBig
381
+ ? { code: "too_big", maximum: def.length, exact: true }
382
+ : { code: "too_small", minimum: def.length, exact: true }),
381
383
  input: payload.value,
382
384
  inst,
383
385
  continue: !def.abort,
@@ -385,7 +387,7 @@ export const $ZodCheckLengthEquals = /*@__PURE__*/ core.$constructor("$ZodCheckL
385
387
  };
386
388
  });
387
389
  export const $ZodCheckStringFormat = /*@__PURE__*/ core.$constructor("$ZodCheckStringFormat", (inst, def) => {
388
- var _a;
390
+ var _a, _b;
389
391
  $ZodCheck.init(inst, def);
390
392
  inst._zod.onattach.push((inst) => {
391
393
  const bag = inst._zod.bag;
@@ -395,22 +397,23 @@ export const $ZodCheckStringFormat = /*@__PURE__*/ core.$constructor("$ZodCheckS
395
397
  bag.patterns.add(def.pattern);
396
398
  }
397
399
  });
398
- (_a = inst._zod).check ?? (_a.check = (payload) => {
399
- if (!def.pattern)
400
- throw new Error("Not implemented.");
401
- def.pattern.lastIndex = 0;
402
- if (def.pattern.test(payload.value))
403
- return;
404
- payload.issues.push({
405
- origin: "string",
406
- code: "invalid_format",
407
- format: def.format,
408
- input: payload.value,
409
- ...(def.pattern ? { pattern: def.pattern.toString() } : {}),
410
- inst,
411
- continue: !def.abort,
400
+ if (def.pattern)
401
+ (_a = inst._zod).check ?? (_a.check = (payload) => {
402
+ def.pattern.lastIndex = 0;
403
+ if (def.pattern.test(payload.value))
404
+ return;
405
+ payload.issues.push({
406
+ origin: "string",
407
+ code: "invalid_format",
408
+ format: def.format,
409
+ input: payload.value,
410
+ ...(def.pattern ? { pattern: def.pattern.toString() } : {}),
411
+ inst,
412
+ continue: !def.abort,
413
+ });
412
414
  });
413
- });
415
+ else
416
+ (_b = inst._zod).check ?? (_b.check = () => { });
414
417
  });
415
418
  export const $ZodCheckRegex = /*@__PURE__*/ core.$constructor("$ZodCheckRegex", (inst, def) => {
416
419
  $ZodCheckStringFormat.init(inst, def);
@@ -403,6 +403,20 @@ export const $ZodJWT = /*@__PURE__*/ core.$constructor("$ZodJWT", (inst, def) =>
403
403
  });
404
404
  };
405
405
  });
406
+ export const $ZodCustomStringFormat = /*@__PURE__*/ core.$constructor("$ZodCustomStringFormat", (inst, def) => {
407
+ $ZodStringFormat.init(inst, def);
408
+ inst._zod.check = (payload) => {
409
+ if (def.fn(payload.value))
410
+ return;
411
+ payload.issues.push({
412
+ code: "invalid_format",
413
+ format: def.format,
414
+ input: payload.value,
415
+ inst,
416
+ continue: !def.abort,
417
+ });
418
+ };
419
+ });
406
420
  export const $ZodNumber = /*@__PURE__*/ core.$constructor("$ZodNumber", (inst, def) => {
407
421
  $ZodType.init(inst, def);
408
422
  inst._zod.pattern = inst._zod.bag.pattern ?? regexes.number;
@@ -183,6 +183,13 @@ export const ZodMiniJWT = /*@__PURE__*/ core.$constructor("ZodMiniJWT", (inst, d
183
183
  export function jwt(params) {
184
184
  return core._jwt(ZodMiniJWT, params);
185
185
  }
186
+ export const ZodMiniCustomStringFormat = /*@__PURE__*/ core.$constructor("ZodMiniCustomStringFormat", (inst, def) => {
187
+ core.$ZodCustomStringFormat.init(inst, def);
188
+ ZodMiniStringFormat.init(inst, def);
189
+ });
190
+ export function stringFormat(format, fnOrRegex, _params = {}) {
191
+ return core._stringFormat(ZodMiniCustomStringFormat, format, fnOrRegex, _params);
192
+ }
186
193
  export const ZodMiniNumber = /*@__PURE__*/ core.$constructor("ZodMiniNumber", (inst, def) => {
187
194
  core.$ZodNumber.init(inst, def);
188
195
  ZodMiniType.init(inst, def);
@@ -151,7 +151,7 @@ export interface ZodString extends _ZodString<core.$ZodStringInternals<string>>
151
151
  }
152
152
  export declare const ZodString: core.$constructor<ZodString>;
153
153
  export declare function string(params?: string | core.$ZodStringParams): ZodString;
154
- export interface ZodStringFormat<Format extends core.$ZodStringFormats = core.$ZodStringFormats> extends _ZodString<core.$ZodStringFormatInternals<Format>> {
154
+ export interface ZodStringFormat<Format extends string = string> extends _ZodString<core.$ZodStringFormatInternals<Format>> {
155
155
  }
156
156
  export declare const ZodStringFormat: core.$constructor<ZodStringFormat>;
157
157
  export interface ZodEmail extends ZodStringFormat<"email"> {
@@ -252,6 +252,11 @@ export interface ZodJWT extends ZodStringFormat<"jwt"> {
252
252
  }
253
253
  export declare const ZodJWT: core.$constructor<ZodJWT>;
254
254
  export declare function jwt(params?: string | core.$ZodJWTParams): ZodJWT;
255
+ export interface ZodCustomStringFormat<Format extends string = string> extends ZodStringFormat<Format>, core.$ZodCustomStringFormat<Format> {
256
+ _zod: core.$ZodCustomStringFormatInternals<Format>;
257
+ }
258
+ export declare const ZodCustomStringFormat: core.$constructor<ZodCustomStringFormat>;
259
+ export declare function stringFormat<Format extends string>(format: Format, fnOrRegex: ((arg: string) => util.MaybeAsync<unknown>) | RegExp, _params?: string | core.$ZodStringFormatParams): ZodCustomStringFormat<Format>;
255
260
  export interface _ZodNumber<Internals extends core.$ZodNumberInternals = core.$ZodNumberInternals> extends _ZodType<Internals> {
256
261
  gt(value: number, params?: string | core.$ZodCheckGreaterThanParams): this;
257
262
  /** Identical to .min() */
@@ -19,6 +19,8 @@ export type CheckTypeParams<T extends schemas.$ZodType & checks.$ZodCheck = sche
19
19
  export type $ZodStringParams = TypeParams<schemas.$ZodString<string>, "coerce">;
20
20
  export declare function _string<T extends schemas.$ZodString>(Class: util.SchemaClass<T>, params?: string | $ZodStringParams): T;
21
21
  export declare function _coercedString<T extends schemas.$ZodString>(Class: util.SchemaClass<T>, params?: string | $ZodStringParams): T;
22
+ export type $ZodStringFormatParams = CheckTypeParams<schemas.$ZodStringFormat, "format" | "coerce">;
23
+ export type $ZodCheckStringFormatParams = CheckParams<checks.$ZodCheckStringFormat, "format">;
22
24
  export type $ZodEmailParams = StringFormatParams<schemas.$ZodEmail>;
23
25
  export type $ZodCheckEmailParams = CheckStringFormatParams<schemas.$ZodEmail>;
24
26
  export declare function _email<T extends schemas.$ZodEmail>(Class: util.SchemaClass<T>, params?: string | $ZodEmailParams | $ZodCheckEmailParams): T;
@@ -279,3 +281,4 @@ export declare function _stringbool(Classes: {
279
281
  Transform?: typeof schemas.$ZodTransform;
280
282
  String?: typeof schemas.$ZodString;
281
283
  }, _params?: string | $ZodStringBoolParams): schemas.$ZodPipe<schemas.$ZodPipe<schemas.$ZodString, schemas.$ZodTransform<boolean, string>>, schemas.$ZodBoolean<boolean>>;
284
+ export declare function _stringFormat<Format extends string>(Class: typeof schemas.$ZodCustomStringFormat, format: Format, fnOrRegex: ((arg: string) => util.MaybeAsync<unknown>) | RegExp, _params?: string | $ZodStringFormatParams): schemas.$ZodCustomStringFormat<Format>;
@@ -157,7 +157,7 @@ export interface $ZodCheckLengthEquals<T extends util.HasLength = util.HasLength
157
157
  }
158
158
  export declare const $ZodCheckLengthEquals: core.$constructor<$ZodCheckLengthEquals>;
159
159
  export type $ZodStringFormats = "email" | "url" | "emoji" | "uuid" | "guid" | "nanoid" | "cuid" | "cuid2" | "ulid" | "xid" | "ksuid" | "datetime" | "date" | "time" | "duration" | "ipv4" | "ipv6" | "cidrv4" | "cidrv6" | "base64" | "base64url" | "json_string" | "e164" | "lowercase" | "uppercase" | "regex" | "jwt" | "starts_with" | "ends_with" | "includes";
160
- export interface $ZodCheckStringFormatDef<Format extends $ZodStringFormats = $ZodStringFormats> extends $ZodCheckDef {
160
+ export interface $ZodCheckStringFormatDef<Format extends string = string> extends $ZodCheckDef {
161
161
  check: "string_format";
162
162
  format: Format;
163
163
  pattern?: RegExp | undefined;
@@ -274,4 +274,4 @@ export interface $ZodCheckOverwrite<T = unknown> extends $ZodCheck<T> {
274
274
  }
275
275
  export declare const $ZodCheckOverwrite: core.$constructor<$ZodCheckOverwrite>;
276
276
  export type $ZodChecks = $ZodCheckLessThan | $ZodCheckGreaterThan | $ZodCheckMultipleOf | $ZodCheckNumberFormat | $ZodCheckBigIntFormat | $ZodCheckMaxSize | $ZodCheckMinSize | $ZodCheckSizeEquals | $ZodCheckMaxLength | $ZodCheckMinLength | $ZodCheckLengthEquals | $ZodCheckStringFormat | $ZodCheckProperty | $ZodCheckMimeType | $ZodCheckOverwrite;
277
- export type $ZodStringFormatChecks = $ZodCheckRegex | $ZodCheckLowerCase | $ZodCheckUpperCase | $ZodCheckIncludes | $ZodCheckStartsWith | $ZodCheckEndsWith | schemas.$ZodGUID | schemas.$ZodUUID | schemas.$ZodEmail | schemas.$ZodURL | schemas.$ZodEmoji | schemas.$ZodNanoID | schemas.$ZodCUID | schemas.$ZodCUID2 | schemas.$ZodULID | schemas.$ZodXID | schemas.$ZodKSUID | schemas.$ZodISODateTime | schemas.$ZodISODate | schemas.$ZodISOTime | schemas.$ZodISODuration | schemas.$ZodIPv4 | schemas.$ZodIPv6 | schemas.$ZodCIDRv4 | schemas.$ZodCIDRv6 | schemas.$ZodBase64 | schemas.$ZodBase64URL | schemas.$ZodE164 | schemas.$ZodJWT;
277
+ export type $ZodStringFormatChecks = $ZodCheckRegex | $ZodCheckLowerCase | $ZodCheckUpperCase | $ZodCheckIncludes | $ZodCheckStartsWith | $ZodCheckEndsWith | schemas.$ZodStringFormatTypes;
@@ -111,12 +111,12 @@ export interface $ZodStringInternals<Input> extends $ZodTypeInternals<string, In
111
111
  export interface $ZodString<Input = unknown> extends _$ZodType<$ZodStringInternals<Input>> {
112
112
  }
113
113
  export declare const $ZodString: core.$constructor<$ZodString>;
114
- export interface $ZodStringFormatDef<Format extends checks.$ZodStringFormats = checks.$ZodStringFormats> extends $ZodStringDef, checks.$ZodCheckStringFormatDef<Format> {
114
+ export interface $ZodStringFormatDef<Format extends string = string> extends $ZodStringDef, checks.$ZodCheckStringFormatDef<Format> {
115
115
  }
116
- export interface $ZodStringFormatInternals<Format extends checks.$ZodStringFormats = checks.$ZodStringFormats> extends $ZodStringInternals<string>, checks.$ZodCheckStringFormatInternals {
116
+ export interface $ZodStringFormatInternals<Format extends string = string> extends $ZodStringInternals<string>, checks.$ZodCheckStringFormatInternals {
117
117
  def: $ZodStringFormatDef<Format>;
118
118
  }
119
- export interface $ZodStringFormat<Format extends checks.$ZodStringFormats = checks.$ZodStringFormats> extends $ZodType {
119
+ export interface $ZodStringFormat<Format extends string = string> extends $ZodType {
120
120
  _zod: $ZodStringFormatInternals<Format>;
121
121
  }
122
122
  export declare const $ZodStringFormat: core.$constructor<$ZodStringFormat>;
@@ -328,6 +328,16 @@ export interface $ZodJWT extends $ZodType {
328
328
  _zod: $ZodJWTInternals;
329
329
  }
330
330
  export declare const $ZodJWT: core.$constructor<$ZodJWT>;
331
+ export interface $ZodCustomStringFormatDef<Format extends string = string> extends $ZodStringFormatDef<Format> {
332
+ fn: (val: string) => unknown;
333
+ }
334
+ export interface $ZodCustomStringFormatInternals<Format extends string = string> extends $ZodStringFormatInternals<Format> {
335
+ def: $ZodCustomStringFormatDef<Format>;
336
+ }
337
+ export interface $ZodCustomStringFormat<Format extends string = string> extends $ZodStringFormat<Format> {
338
+ _zod: $ZodCustomStringFormatInternals<Format>;
339
+ }
340
+ export declare const $ZodCustomStringFormat: core.$constructor<$ZodCustomStringFormat>;
331
341
  export interface $ZodNumberDef extends $ZodTypeDef {
332
342
  type: "number";
333
343
  coerce?: boolean;
@@ -24,7 +24,7 @@ export interface ZodMiniString<Input = unknown> extends _ZodMiniString<core.$Zod
24
24
  }
25
25
  export declare const ZodMiniString: core.$constructor<ZodMiniString>;
26
26
  export declare function string(params?: string | core.$ZodStringParams): ZodMiniString<string>;
27
- export interface ZodMiniStringFormat<Format extends core.$ZodStringFormats = core.$ZodStringFormats> extends _ZodMiniString<core.$ZodStringFormatInternals<Format>>, core.$ZodStringFormat<Format> {
27
+ export interface ZodMiniStringFormat<Format extends string = string> extends _ZodMiniString<core.$ZodStringFormatInternals<Format>>, core.$ZodStringFormat<Format> {
28
28
  }
29
29
  export declare const ZodMiniStringFormat: core.$constructor<ZodMiniStringFormat>;
30
30
  export interface ZodMiniEmail extends _ZodMiniString<core.$ZodEmailInternals> {
@@ -106,6 +106,11 @@ export interface ZodMiniJWT extends _ZodMiniString<core.$ZodJWTInternals> {
106
106
  }
107
107
  export declare const ZodMiniJWT: core.$constructor<ZodMiniJWT>;
108
108
  export declare function jwt(params?: string | core.$ZodJWTParams): ZodMiniJWT;
109
+ export interface ZodMiniCustomStringFormat<Format extends string = string> extends ZodMiniStringFormat<Format>, core.$ZodCustomStringFormat<Format> {
110
+ _zod: core.$ZodCustomStringFormatInternals<Format>;
111
+ }
112
+ export declare const ZodMiniCustomStringFormat: core.$constructor<ZodMiniCustomStringFormat>;
113
+ export declare function stringFormat<Format extends string>(format: Format, fnOrRegex: ((arg: string) => util.MaybeAsync<unknown>) | RegExp, _params?: string | core.$ZodStringFormatParams): ZodMiniCustomStringFormat<Format>;
109
114
  interface _ZodMiniNumber<T extends core.$ZodNumberInternals<unknown> = core.$ZodNumberInternals<unknown>> extends _ZodMiniType<T>, core.$ZodNumber<T["input"]> {
110
115
  _zod: T;
111
116
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod",
3
- "version": "3.26.0-canary.20250616T222346",
3
+ "version": "3.26.0-canary.20250618T044324",
4
4
  "type": "module",
5
5
  "author": "Colin McDonnell <zod@colinhacks.com>",
6
6
  "description": "TypeScript-first schema declaration and validation library with static type inference",