zod 4.2.0-canary.20251118T185426 → 4.2.0-canary.20251124T022609

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod",
3
- "version": "4.2.0-canary.20251118T185426",
3
+ "version": "4.2.0-canary.20251124T022609",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Colin McDonnell <zod@colinhacks.com>",
@@ -27,5 +27,6 @@ export {
27
27
  _trim as trim,
28
28
  _toLowerCase as toLowerCase,
29
29
  _toUpperCase as toUpperCase,
30
+ _slugify as slugify,
30
31
  type $RefinementCtx as RefinementCtx,
31
32
  } from "../core/index.js";
@@ -252,6 +252,7 @@ export interface _ZodString<T extends core.$ZodStringInternals<unknown> = core.$
252
252
  normalize(form?: "NFC" | "NFD" | "NFKC" | "NFKD" | (string & {})): this;
253
253
  toLowerCase(): this;
254
254
  toUpperCase(): this;
255
+ slugify(): this;
255
256
  }
256
257
 
257
258
  /** @internal */
@@ -281,6 +282,7 @@ export const _ZodString: core.$constructor<_ZodString> = /*@__PURE__*/ core.$con
281
282
  inst.normalize = (...args) => inst.check(checks.normalize(...args));
282
283
  inst.toLowerCase = () => inst.check(checks.toLowerCase());
283
284
  inst.toUpperCase = () => inst.check(checks.toUpperCase());
285
+ inst.slugify = () => inst.check(checks.slugify());
284
286
  });
285
287
 
286
288
  export interface ZodString extends _ZodString<core.$ZodStringInternals<string>> {
@@ -2142,6 +2144,10 @@ export function superRefine<T>(
2142
2144
  return core._superRefine(fn);
2143
2145
  }
2144
2146
 
2147
+ // Re-export describe and meta from core
2148
+ export const describe = core.describe;
2149
+ export const meta = core.meta;
2150
+
2145
2151
  type ZodInstanceOfParams = core.Params<
2146
2152
  ZodCustom,
2147
2153
  core.$ZodIssueCustom,
@@ -0,0 +1,27 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import * as z from "../index.js";
3
+
4
+ describe("z.describe() check", () => {
5
+ it("registers description in globalRegistry", () => {
6
+ const schema = z.string().check(z.describe("A string"));
7
+ expect(z.globalRegistry.get(schema)?.description).toBe("A string");
8
+ });
9
+ });
10
+
11
+ describe("z.meta() check", () => {
12
+ it("registers metadata in globalRegistry", () => {
13
+ const schema = z.number().check(z.meta({ title: "Age", description: "User's age" }));
14
+ const meta = z.globalRegistry.get(schema);
15
+ expect(meta?.title).toBe("Age");
16
+ expect(meta?.description).toBe("User's age");
17
+ });
18
+ });
19
+
20
+ describe("combined usage", () => {
21
+ it("works with multiple checks", () => {
22
+ const schema = z.string().check(z.describe("Email address"), z.meta({ title: "Email" }));
23
+ const meta = z.globalRegistry.get(schema);
24
+ expect(meta?.description).toBe("Email address");
25
+ expect(meta?.title).toBe("Email");
26
+ });
27
+ });
@@ -803,6 +803,24 @@ test("lowerCase", () => {
803
803
  expect(z.string().toUpperCase().parse("asdf")).toEqual("ASDF");
804
804
  });
805
805
 
806
+ test("slugify", () => {
807
+ expect(z.string().slugify().parse("Hello World")).toEqual("hello-world");
808
+ expect(z.string().slugify().parse(" Hello World ")).toEqual("hello-world");
809
+ expect(z.string().slugify().parse("Hello@World#123")).toEqual("helloworld123");
810
+ expect(z.string().slugify().parse("Hello-World")).toEqual("hello-world");
811
+ expect(z.string().slugify().parse("Hello_World")).toEqual("hello-world");
812
+ expect(z.string().slugify().parse("---Hello---World---")).toEqual("hello-world");
813
+ expect(z.string().slugify().parse("Hello World")).toEqual("hello-world");
814
+ expect(z.string().slugify().parse("Hello!@#$%^&*()World")).toEqual("helloworld");
815
+
816
+ // can be used with check
817
+ expect(z.string().check(z.slugify()).parse("Hello World")).toEqual("hello-world");
818
+
819
+ // can be chained with other methods
820
+ expect(z.string().slugify().min(5).parse("Hello World")).toEqual("hello-world");
821
+ expect(() => z.string().slugify().min(20).parse("Hello World")).toThrow();
822
+ });
823
+
806
824
  // test("IP validation", () => {
807
825
  // const ipSchema = z.string().ip();
808
826
 
@@ -1,6 +1,7 @@
1
1
  import * as checks from "./checks.js";
2
2
  import type * as core from "./core.js";
3
3
  import type * as errors from "./errors.js";
4
+ import * as registries from "./registries.js";
4
5
  import * as schemas from "./schemas.js";
5
6
  import * as util from "./util.js";
6
7
 
@@ -1052,6 +1053,10 @@ export function _toLowerCase(): checks.$ZodCheckOverwrite<string> {
1052
1053
  export function _toUpperCase(): checks.$ZodCheckOverwrite<string> {
1053
1054
  return _overwrite((input) => input.toUpperCase());
1054
1055
  }
1056
+ // slugify
1057
+ export function _slugify(): checks.$ZodCheckOverwrite<string> {
1058
+ return _overwrite((input) => util.slugify(input));
1059
+ }
1055
1060
 
1056
1061
  /////// collections ///////
1057
1062
 
@@ -1534,6 +1539,30 @@ export function _check<O = unknown>(fn: schemas.CheckFn<O>, params?: string | $Z
1534
1539
  return ch;
1535
1540
  }
1536
1541
 
1542
+ export function describe<T>(description: string): checks.$ZodCheck<T> {
1543
+ const ch = new checks.$ZodCheck({ check: "describe" });
1544
+ ch._zod.onattach = [
1545
+ (inst) => {
1546
+ const existing = registries.globalRegistry.get(inst) ?? {};
1547
+ registries.globalRegistry.add(inst, { ...existing, description });
1548
+ },
1549
+ ];
1550
+ ch._zod.check = () => {}; // no-op check
1551
+ return ch;
1552
+ }
1553
+
1554
+ export function meta<T>(metadata: registries.GlobalMeta): checks.$ZodCheck<T> {
1555
+ const ch = new checks.$ZodCheck({ check: "meta" });
1556
+ ch._zod.onattach = [
1557
+ (inst) => {
1558
+ const existing = registries.globalRegistry.get(inst) ?? {};
1559
+ registries.globalRegistry.add(inst, { ...existing, ...metadata });
1560
+ },
1561
+ ];
1562
+ ch._zod.check = () => {}; // no-op check
1563
+ return ch;
1564
+ }
1565
+
1537
1566
  // export type $ZodCustomParams = CheckTypeParams<schemas.$ZodCustom, "fn">
1538
1567
 
1539
1568
  ///////// STRINGBOOL /////////
@@ -351,6 +351,15 @@ export function esc(str: string): string {
351
351
  return JSON.stringify(str);
352
352
  }
353
353
 
354
+ export function slugify(input: string): string {
355
+ return input
356
+ .toLowerCase()
357
+ .trim()
358
+ .replace(/[^\w\s-]/g, "")
359
+ .replace(/[\s_-]+/g, "-")
360
+ .replace(/^-+|-+$/g, "");
361
+ }
362
+
354
363
  export const captureStackTrace: (targetObject: object, constructorOpt?: Function) => void = (
355
364
  "captureStackTrace" in Error ? Error.captureStackTrace : (..._args: any[]) => {}
356
365
  ) as any;
@@ -1614,6 +1614,10 @@ export function superRefine<T>(
1614
1614
  return core._superRefine(fn);
1615
1615
  }
1616
1616
 
1617
+ // Re-export describe and meta from core
1618
+ export const describe = core.describe;
1619
+ export const meta = core.meta;
1620
+
1617
1621
  // instanceof
1618
1622
  abstract class Class {
1619
1623
  constructor(..._args: any[]) {}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toUpperCase = exports.toLowerCase = exports.trim = exports.normalize = exports.overwrite = exports.mime = exports.property = exports.endsWith = exports.startsWith = exports.includes = exports.uppercase = exports.lowercase = exports.regex = exports.length = exports.minLength = exports.maxLength = exports.size = exports.minSize = exports.maxSize = exports.multipleOf = exports.nonnegative = exports.nonpositive = exports.negative = exports.positive = exports.gte = exports.gt = exports.lte = exports.lt = void 0;
3
+ exports.slugify = exports.toUpperCase = exports.toLowerCase = exports.trim = exports.normalize = exports.overwrite = exports.mime = exports.property = exports.endsWith = exports.startsWith = exports.includes = exports.uppercase = exports.lowercase = exports.regex = exports.length = exports.minLength = exports.maxLength = exports.size = exports.minSize = exports.maxSize = exports.multipleOf = exports.nonnegative = exports.nonpositive = exports.negative = exports.positive = exports.gte = exports.gt = exports.lte = exports.lt = void 0;
4
4
  var index_js_1 = require("../core/index.cjs");
5
5
  Object.defineProperty(exports, "lt", { enumerable: true, get: function () { return index_js_1._lt; } });
6
6
  Object.defineProperty(exports, "lte", { enumerable: true, get: function () { return index_js_1._lte; } });
@@ -30,3 +30,4 @@ Object.defineProperty(exports, "normalize", { enumerable: true, get: function ()
30
30
  Object.defineProperty(exports, "trim", { enumerable: true, get: function () { return index_js_1._trim; } });
31
31
  Object.defineProperty(exports, "toLowerCase", { enumerable: true, get: function () { return index_js_1._toLowerCase; } });
32
32
  Object.defineProperty(exports, "toUpperCase", { enumerable: true, get: function () { return index_js_1._toUpperCase; } });
33
+ Object.defineProperty(exports, "slugify", { enumerable: true, get: function () { return index_js_1._slugify; } });
@@ -1 +1 @@
1
- export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, type $RefinementCtx as RefinementCtx, } from "../core/index.cjs";
1
+ export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, _slugify as slugify, type $RefinementCtx as RefinementCtx, } from "../core/index.cjs";
@@ -1 +1 @@
1
- export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, type $RefinementCtx as RefinementCtx, } from "../core/index.js";
1
+ export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, _slugify as slugify, type $RefinementCtx as RefinementCtx, } from "../core/index.js";
@@ -1 +1 @@
1
- export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, } from "../core/index.js";
1
+ export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, _slugify as slugify, } from "../core/index.js";
@@ -24,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  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.ZodMAC = 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.ZodFunction = exports.ZodPromise = exports.ZodLazy = exports.ZodTemplateLiteral = exports.ZodReadonly = exports.ZodCodec = exports.ZodPipe = exports.ZodNaN = exports.ZodCatch = exports.ZodSuccess = exports.ZodNonOptional = exports.ZodPrefault = exports.ZodDefault = exports.ZodNullable = exports.ZodOptional = exports.ZodTransform = void 0;
27
+ exports.stringbool = exports.meta = exports.describe = exports.ZodCustom = exports.ZodFunction = exports.ZodPromise = exports.ZodLazy = exports.ZodTemplateLiteral = exports.ZodReadonly = exports.ZodCodec = exports.ZodPipe = exports.ZodNaN = exports.ZodCatch = exports.ZodSuccess = exports.ZodNonOptional = exports.ZodPrefault = exports.ZodDefault = exports.ZodNullable = exports.ZodOptional = exports.ZodTransform = void 0;
28
28
  exports.string = string;
29
29
  exports.email = email;
30
30
  exports.guid = guid;
@@ -224,6 +224,7 @@ exports._ZodString = core.$constructor("_ZodString", (inst, def) => {
224
224
  inst.normalize = (...args) => inst.check(checks.normalize(...args));
225
225
  inst.toLowerCase = () => inst.check(checks.toLowerCase());
226
226
  inst.toUpperCase = () => inst.check(checks.toUpperCase());
227
+ inst.slugify = () => inst.check(checks.slugify());
227
228
  });
228
229
  exports.ZodString = core.$constructor("ZodString", (inst, def) => {
229
230
  core.$ZodString.init(inst, def);
@@ -1127,6 +1128,9 @@ function refine(fn, _params = {}) {
1127
1128
  function superRefine(fn) {
1128
1129
  return core._superRefine(fn);
1129
1130
  }
1131
+ // Re-export describe and meta from core
1132
+ exports.describe = core.describe;
1133
+ exports.meta = core.meta;
1130
1134
  function _instanceof(cls, params = {
1131
1135
  error: `Input not instance of ${cls.name}`,
1132
1136
  }) {
@@ -94,6 +94,7 @@ export interface _ZodString<T extends core.$ZodStringInternals<unknown> = core.$
94
94
  normalize(form?: "NFC" | "NFD" | "NFKC" | "NFKD" | (string & {})): this;
95
95
  toLowerCase(): this;
96
96
  toUpperCase(): this;
97
+ slugify(): this;
97
98
  }
98
99
  /** @internal */
99
100
  export declare const _ZodString: core.$constructor<_ZodString>;
@@ -654,6 +655,8 @@ export declare function check<O = unknown>(fn: core.CheckFn<O>): core.$ZodCheck<
654
655
  export declare function custom<O>(fn?: (data: unknown) => unknown, _params?: string | core.$ZodCustomParams | undefined): ZodCustom<O, O>;
655
656
  export declare function refine<T>(fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>, _params?: string | core.$ZodCustomParams): core.$ZodCheck<T>;
656
657
  export declare function superRefine<T>(fn: (arg: T, payload: core.$RefinementCtx<T>) => void | Promise<void>): core.$ZodCheck<T>;
658
+ export declare const describe: typeof core.describe;
659
+ export declare const meta: typeof core.meta;
657
660
  type ZodInstanceOfParams = core.Params<ZodCustom, core.$ZodIssueCustom, "type" | "check" | "checks" | "fn" | "abort" | "error" | "params" | "path">;
658
661
  declare function _instanceof<T extends typeof util.Class>(cls: T, params?: ZodInstanceOfParams): ZodCustom<InstanceType<T>, InstanceType<T>>;
659
662
  export { _instanceof as instanceof };
@@ -94,6 +94,7 @@ export interface _ZodString<T extends core.$ZodStringInternals<unknown> = core.$
94
94
  normalize(form?: "NFC" | "NFD" | "NFKC" | "NFKD" | (string & {})): this;
95
95
  toLowerCase(): this;
96
96
  toUpperCase(): this;
97
+ slugify(): this;
97
98
  }
98
99
  /** @internal */
99
100
  export declare const _ZodString: core.$constructor<_ZodString>;
@@ -654,6 +655,8 @@ export declare function check<O = unknown>(fn: core.CheckFn<O>): core.$ZodCheck<
654
655
  export declare function custom<O>(fn?: (data: unknown) => unknown, _params?: string | core.$ZodCustomParams | undefined): ZodCustom<O, O>;
655
656
  export declare function refine<T>(fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>, _params?: string | core.$ZodCustomParams): core.$ZodCheck<T>;
656
657
  export declare function superRefine<T>(fn: (arg: T, payload: core.$RefinementCtx<T>) => void | Promise<void>): core.$ZodCheck<T>;
658
+ export declare const describe: typeof core.describe;
659
+ export declare const meta: typeof core.meta;
657
660
  type ZodInstanceOfParams = core.Params<ZodCustom, core.$ZodIssueCustom, "type" | "check" | "checks" | "fn" | "abort" | "error" | "params" | "path">;
658
661
  declare function _instanceof<T extends typeof util.Class>(cls: T, params?: ZodInstanceOfParams): ZodCustom<InstanceType<T>, InstanceType<T>>;
659
662
  export { _instanceof as instanceof };
@@ -106,6 +106,7 @@ export const _ZodString = /*@__PURE__*/ core.$constructor("_ZodString", (inst, d
106
106
  inst.normalize = (...args) => inst.check(checks.normalize(...args));
107
107
  inst.toLowerCase = () => inst.check(checks.toLowerCase());
108
108
  inst.toUpperCase = () => inst.check(checks.toUpperCase());
109
+ inst.slugify = () => inst.check(checks.slugify());
109
110
  });
110
111
  export const ZodString = /*@__PURE__*/ core.$constructor("ZodString", (inst, def) => {
111
112
  core.$ZodString.init(inst, def);
@@ -1015,6 +1016,9 @@ export function refine(fn, _params = {}) {
1015
1016
  export function superRefine(fn) {
1016
1017
  return core._superRefine(fn);
1017
1018
  }
1019
+ // Re-export describe and meta from core
1020
+ export const describe = core.describe;
1021
+ export const meta = core.meta;
1018
1022
  function _instanceof(cls, params = {
1019
1023
  error: `Input not instance of ${cls.name}`,
1020
1024
  }) {
package/v4/core/api.cjs CHANGED
@@ -110,6 +110,7 @@ exports._normalize = _normalize;
110
110
  exports._trim = _trim;
111
111
  exports._toLowerCase = _toLowerCase;
112
112
  exports._toUpperCase = _toUpperCase;
113
+ exports._slugify = _slugify;
113
114
  exports._array = _array;
114
115
  exports._union = _union;
115
116
  exports._discriminatedUnion = _discriminatedUnion;
@@ -138,9 +139,12 @@ exports._custom = _custom;
138
139
  exports._refine = _refine;
139
140
  exports._superRefine = _superRefine;
140
141
  exports._check = _check;
142
+ exports.describe = describe;
143
+ exports.meta = meta;
141
144
  exports._stringbool = _stringbool;
142
145
  exports._stringFormat = _stringFormat;
143
146
  const checks = __importStar(require("./checks.cjs"));
147
+ const registries = __importStar(require("./registries.cjs"));
144
148
  const schemas = __importStar(require("./schemas.cjs"));
145
149
  const util = __importStar(require("./util.cjs"));
146
150
  function _string(Class, params) {
@@ -752,6 +756,10 @@ function _toLowerCase() {
752
756
  function _toUpperCase() {
753
757
  return _overwrite((input) => input.toUpperCase());
754
758
  }
759
+ // slugify
760
+ function _slugify() {
761
+ return _overwrite((input) => util.slugify(input));
762
+ }
755
763
  function _array(Class, element, params) {
756
764
  return new Class({
757
765
  type: "array",
@@ -999,6 +1007,28 @@ function _check(fn, params) {
999
1007
  ch._zod.check = fn;
1000
1008
  return ch;
1001
1009
  }
1010
+ function describe(description) {
1011
+ const ch = new checks.$ZodCheck({ check: "describe" });
1012
+ ch._zod.onattach = [
1013
+ (inst) => {
1014
+ const existing = registries.globalRegistry.get(inst) ?? {};
1015
+ registries.globalRegistry.add(inst, { ...existing, description });
1016
+ },
1017
+ ];
1018
+ ch._zod.check = () => { }; // no-op check
1019
+ return ch;
1020
+ }
1021
+ function meta(metadata) {
1022
+ const ch = new checks.$ZodCheck({ check: "meta" });
1023
+ ch._zod.onattach = [
1024
+ (inst) => {
1025
+ const existing = registries.globalRegistry.get(inst) ?? {};
1026
+ registries.globalRegistry.add(inst, { ...existing, ...metadata });
1027
+ },
1028
+ ];
1029
+ ch._zod.check = () => { }; // no-op check
1030
+ return ch;
1031
+ }
1002
1032
  function _stringbool(Classes, _params) {
1003
1033
  const params = util.normalizeParams(_params);
1004
1034
  let truthyArray = params.truthy ?? ["true", "1", "yes", "on", "y", "enabled"];
package/v4/core/api.d.cts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as checks from "./checks.cjs";
2
2
  import type * as core from "./core.cjs";
3
3
  import type * as errors from "./errors.cjs";
4
+ import * as registries from "./registries.cjs";
4
5
  import * as schemas from "./schemas.cjs";
5
6
  import * as util from "./util.cjs";
6
7
  export type Params<T extends schemas.$ZodType | checks.$ZodCheck, IssueTypes extends errors.$ZodIssueBase, OmitKeys extends keyof T["_zod"]["def"] = never> = util.Flatten<Partial<util.EmptyToNever<Omit<T["_zod"]["def"], OmitKeys> & ([IssueTypes] extends [never] ? {} : {
@@ -201,6 +202,7 @@ export declare function _normalize(form?: "NFC" | "NFD" | "NFKC" | "NFKD" | (str
201
202
  export declare function _trim(): checks.$ZodCheckOverwrite<string>;
202
203
  export declare function _toLowerCase(): checks.$ZodCheckOverwrite<string>;
203
204
  export declare function _toUpperCase(): checks.$ZodCheckOverwrite<string>;
205
+ export declare function _slugify(): checks.$ZodCheckOverwrite<string>;
204
206
  export type $ZodArrayParams = TypeParams<schemas.$ZodArray, "element">;
205
207
  export declare function _array<T extends schemas.$ZodType>(Class: util.SchemaClass<schemas.$ZodArray>, element: T, params?: string | $ZodArrayParams): schemas.$ZodArray<T>;
206
208
  export type $ZodObjectParams = TypeParams<schemas.$ZodObject, "shape" | "catchall">;
@@ -280,6 +282,8 @@ export interface $RefinementCtx<T = unknown> extends schemas.ParsePayload<T> {
280
282
  }
281
283
  export declare function _superRefine<T>(fn: (arg: T, payload: $RefinementCtx<T>) => void | Promise<void>): checks.$ZodCheck<T>;
282
284
  export declare function _check<O = unknown>(fn: schemas.CheckFn<O>, params?: string | $ZodCustomParams): checks.$ZodCheck<O>;
285
+ export declare function describe<T>(description: string): checks.$ZodCheck<T>;
286
+ export declare function meta<T>(metadata: registries.GlobalMeta): checks.$ZodCheck<T>;
283
287
  export interface $ZodStringBoolParams extends TypeParams {
284
288
  truthy?: string[];
285
289
  falsy?: string[];
package/v4/core/api.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as checks from "./checks.js";
2
2
  import type * as core from "./core.js";
3
3
  import type * as errors from "./errors.js";
4
+ import * as registries from "./registries.js";
4
5
  import * as schemas from "./schemas.js";
5
6
  import * as util from "./util.js";
6
7
  export type Params<T extends schemas.$ZodType | checks.$ZodCheck, IssueTypes extends errors.$ZodIssueBase, OmitKeys extends keyof T["_zod"]["def"] = never> = util.Flatten<Partial<util.EmptyToNever<Omit<T["_zod"]["def"], OmitKeys> & ([IssueTypes] extends [never] ? {} : {
@@ -201,6 +202,7 @@ export declare function _normalize(form?: "NFC" | "NFD" | "NFKC" | "NFKD" | (str
201
202
  export declare function _trim(): checks.$ZodCheckOverwrite<string>;
202
203
  export declare function _toLowerCase(): checks.$ZodCheckOverwrite<string>;
203
204
  export declare function _toUpperCase(): checks.$ZodCheckOverwrite<string>;
205
+ export declare function _slugify(): checks.$ZodCheckOverwrite<string>;
204
206
  export type $ZodArrayParams = TypeParams<schemas.$ZodArray, "element">;
205
207
  export declare function _array<T extends schemas.$ZodType>(Class: util.SchemaClass<schemas.$ZodArray>, element: T, params?: string | $ZodArrayParams): schemas.$ZodArray<T>;
206
208
  export type $ZodObjectParams = TypeParams<schemas.$ZodObject, "shape" | "catchall">;
@@ -280,6 +282,8 @@ export interface $RefinementCtx<T = unknown> extends schemas.ParsePayload<T> {
280
282
  }
281
283
  export declare function _superRefine<T>(fn: (arg: T, payload: $RefinementCtx<T>) => void | Promise<void>): checks.$ZodCheck<T>;
282
284
  export declare function _check<O = unknown>(fn: schemas.CheckFn<O>, params?: string | $ZodCustomParams): checks.$ZodCheck<O>;
285
+ export declare function describe<T>(description: string): checks.$ZodCheck<T>;
286
+ export declare function meta<T>(metadata: registries.GlobalMeta): checks.$ZodCheck<T>;
283
287
  export interface $ZodStringBoolParams extends TypeParams {
284
288
  truthy?: string[];
285
289
  falsy?: string[];
package/v4/core/api.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as checks from "./checks.js";
2
+ import * as registries from "./registries.js";
2
3
  import * as schemas from "./schemas.js";
3
4
  import * as util from "./util.js";
4
5
  export function _string(Class, params) {
@@ -616,6 +617,10 @@ export function _toLowerCase() {
616
617
  export function _toUpperCase() {
617
618
  return _overwrite((input) => input.toUpperCase());
618
619
  }
620
+ // slugify
621
+ export function _slugify() {
622
+ return _overwrite((input) => util.slugify(input));
623
+ }
619
624
  export function _array(Class, element, params) {
620
625
  return new Class({
621
626
  type: "array",
@@ -863,6 +868,28 @@ export function _check(fn, params) {
863
868
  ch._zod.check = fn;
864
869
  return ch;
865
870
  }
871
+ export function describe(description) {
872
+ const ch = new checks.$ZodCheck({ check: "describe" });
873
+ ch._zod.onattach = [
874
+ (inst) => {
875
+ const existing = registries.globalRegistry.get(inst) ?? {};
876
+ registries.globalRegistry.add(inst, { ...existing, description });
877
+ },
878
+ ];
879
+ ch._zod.check = () => { }; // no-op check
880
+ return ch;
881
+ }
882
+ export function meta(metadata) {
883
+ const ch = new checks.$ZodCheck({ check: "meta" });
884
+ ch._zod.onattach = [
885
+ (inst) => {
886
+ const existing = registries.globalRegistry.get(inst) ?? {};
887
+ registries.globalRegistry.add(inst, { ...existing, ...metadata });
888
+ },
889
+ ];
890
+ ch._zod.check = () => { }; // no-op check
891
+ return ch;
892
+ }
866
893
  export function _stringbool(Classes, _params) {
867
894
  const params = util.normalizeParams(_params);
868
895
  let truthyArray = params.truthy ?? ["true", "1", "yes", "on", "y", "enabled"];
package/v4/core/util.cjs CHANGED
@@ -22,6 +22,7 @@ exports.getElementAtPath = getElementAtPath;
22
22
  exports.promiseAllObject = promiseAllObject;
23
23
  exports.randomString = randomString;
24
24
  exports.esc = esc;
25
+ exports.slugify = slugify;
25
26
  exports.isObject = isObject;
26
27
  exports.isPlainObject = isPlainObject;
27
28
  exports.shallowClone = shallowClone;
@@ -190,6 +191,14 @@ function randomString(length = 10) {
190
191
  function esc(str) {
191
192
  return JSON.stringify(str);
192
193
  }
194
+ function slugify(input) {
195
+ return input
196
+ .toLowerCase()
197
+ .trim()
198
+ .replace(/[^\w\s-]/g, "")
199
+ .replace(/[\s_-]+/g, "-")
200
+ .replace(/^-+|-+$/g, "");
201
+ }
193
202
  exports.captureStackTrace = ("captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => { });
194
203
  function isObject(data) {
195
204
  return typeof data === "object" && data !== null && !Array.isArray(data);
@@ -133,6 +133,7 @@ export declare function promiseAllObject<T extends object>(promisesObj: T): Prom
133
133
  }>;
134
134
  export declare function randomString(length?: number): string;
135
135
  export declare function esc(str: string): string;
136
+ export declare function slugify(input: string): string;
136
137
  export declare const captureStackTrace: (targetObject: object, constructorOpt?: Function) => void;
137
138
  export declare function isObject(data: any): data is Record<PropertyKey, unknown>;
138
139
  export declare const allowsEval: {
package/v4/core/util.d.ts CHANGED
@@ -133,6 +133,7 @@ export declare function promiseAllObject<T extends object>(promisesObj: T): Prom
133
133
  }>;
134
134
  export declare function randomString(length?: number): string;
135
135
  export declare function esc(str: string): string;
136
+ export declare function slugify(input: string): string;
136
137
  export declare const captureStackTrace: (targetObject: object, constructorOpt?: Function) => void;
137
138
  export declare function isObject(data: any): data is Record<PropertyKey, unknown>;
138
139
  export declare const allowsEval: {
package/v4/core/util.js CHANGED
@@ -135,6 +135,14 @@ export function randomString(length = 10) {
135
135
  export function esc(str) {
136
136
  return JSON.stringify(str);
137
137
  }
138
+ export function slugify(input) {
139
+ return input
140
+ .toLowerCase()
141
+ .trim()
142
+ .replace(/[^\w\s-]/g, "")
143
+ .replace(/[\s_-]+/g, "-")
144
+ .replace(/^-+|-+$/g, "");
145
+ }
138
146
  export const captureStackTrace = ("captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => { });
139
147
  export function isObject(data) {
140
148
  return typeof data === "object" && data !== null && !Array.isArray(data);
@@ -24,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  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.ZodMiniMAC = 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.ZodMiniFunction = exports.stringbool = exports.ZodMiniCustom = exports.ZodMiniPromise = exports.ZodMiniLazy = exports.ZodMiniTemplateLiteral = exports.ZodMiniReadonly = exports.ZodMiniCodec = exports.ZodMiniPipe = exports.ZodMiniNaN = exports.ZodMiniCatch = exports.ZodMiniSuccess = exports.ZodMiniNonOptional = exports.ZodMiniPrefault = exports.ZodMiniDefault = exports.ZodMiniNullable = exports.ZodMiniOptional = void 0;
27
+ exports.ZodMiniFunction = exports.stringbool = exports.meta = exports.describe = exports.ZodMiniCustom = exports.ZodMiniPromise = exports.ZodMiniLazy = exports.ZodMiniTemplateLiteral = exports.ZodMiniReadonly = exports.ZodMiniCodec = exports.ZodMiniPipe = exports.ZodMiniNaN = exports.ZodMiniCatch = exports.ZodMiniSuccess = exports.ZodMiniNonOptional = exports.ZodMiniPrefault = exports.ZodMiniDefault = exports.ZodMiniNullable = exports.ZodMiniOptional = void 0;
28
28
  exports.string = string;
29
29
  exports.email = email;
30
30
  exports.guid = guid;
@@ -863,6 +863,9 @@ function refine(fn, _params = {}) {
863
863
  function superRefine(fn) {
864
864
  return core._superRefine(fn);
865
865
  }
866
+ // Re-export describe and meta from core
867
+ exports.describe = core.describe;
868
+ exports.meta = core.meta;
866
869
  // instanceof
867
870
  class Class {
868
871
  constructor(..._args) { }
@@ -357,6 +357,8 @@ export declare function check<O = unknown>(fn: core.CheckFn<O>, params?: string
357
357
  export declare function custom<O = unknown, I = O>(fn?: (data: O) => unknown, _params?: string | core.$ZodCustomParams | undefined): ZodMiniCustom<O, I>;
358
358
  export declare function refine<T>(fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>, _params?: string | core.$ZodCustomParams): core.$ZodCheck<T>;
359
359
  export declare function superRefine<T>(fn: (arg: T, payload: core.$RefinementCtx<T>) => void | Promise<void>): core.$ZodCheck<T>;
360
+ export declare const describe: typeof core.describe;
361
+ export declare const meta: typeof core.meta;
360
362
  declare abstract class Class {
361
363
  constructor(..._args: any[]);
362
364
  }
@@ -357,6 +357,8 @@ export declare function check<O = unknown>(fn: core.CheckFn<O>, params?: string
357
357
  export declare function custom<O = unknown, I = O>(fn?: (data: O) => unknown, _params?: string | core.$ZodCustomParams | undefined): ZodMiniCustom<O, I>;
358
358
  export declare function refine<T>(fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>, _params?: string | core.$ZodCustomParams): core.$ZodCheck<T>;
359
359
  export declare function superRefine<T>(fn: (arg: T, payload: core.$RefinementCtx<T>) => void | Promise<void>): core.$ZodCheck<T>;
360
+ export declare const describe: typeof core.describe;
361
+ export declare const meta: typeof core.meta;
360
362
  declare abstract class Class {
361
363
  constructor(..._args: any[]);
362
364
  }
@@ -744,6 +744,9 @@ export function refine(fn, _params = {}) {
744
744
  export function superRefine(fn) {
745
745
  return core._superRefine(fn);
746
746
  }
747
+ // Re-export describe and meta from core
748
+ export const describe = core.describe;
749
+ export const meta = core.meta;
747
750
  // instanceof
748
751
  class Class {
749
752
  constructor(..._args) { }