zod 4.1.0-canary.20250723T215716 → 4.1.0-canary.20250723T222937

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.1.0-canary.20250723T215716",
3
+ "version": "4.1.0-canary.20250723T222937",
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",
@@ -61,8 +61,6 @@ export interface ZodType<
61
61
 
62
62
  // refinements
63
63
  refine(check: (arg: core.output<this>) => unknown | Promise<unknown>, params?: string | core.$ZodCustomParams): this;
64
- /** @deprecated Use [`.check()`](https://zod.dev/api?id=check) instead.
65
- */
66
64
  superRefine(
67
65
  refinement: (arg: core.output<this>, ctx: RefinementCtx<core.output<this>>) => void | Promise<void>
68
66
  ): this;
@@ -90,3 +90,28 @@ test("readonly", () => {
90
90
  const a = ["asdf"] as const;
91
91
  z.literal(a);
92
92
  });
93
+
94
+ test("literal pattern", () => {
95
+ expect(z.literal(1.1)._zod.pattern).toMatchInlineSnapshot(`/\\^\\(1\\\\\\.1\\)\\$/`);
96
+
97
+ expect(z.templateLiteral([z.literal(1.1)]).safeParse("1.1")).toMatchInlineSnapshot(`
98
+ {
99
+ "data": "1.1",
100
+ "success": true,
101
+ }
102
+ `);
103
+ expect(z.templateLiteral([z.literal(1.1)]).safeParse("1n1")).toMatchInlineSnapshot(`
104
+ {
105
+ "error": [ZodError: [
106
+ {
107
+ "code": "invalid_format",
108
+ "format": "template_literal",
109
+ "pattern": "^(1\\\\.1)$",
110
+ "path": [],
111
+ "message": "Invalid input"
112
+ }
113
+ ]],
114
+ "success": false,
115
+ }
116
+ `);
117
+ });
@@ -6,6 +6,7 @@ const hello = z.templateLiteral(["hello"]);
6
6
  const world = z.templateLiteral(["", z.literal("world")]);
7
7
  const one = z.templateLiteral([1]);
8
8
  const two = z.templateLiteral(["", z.literal(2)]);
9
+ const onePointOne = z.templateLiteral([z.literal(1.1)]);
9
10
  const truee = z.templateLiteral([true]);
10
11
  const anotherTrue = z.templateLiteral(["", z.literal(true)]);
11
12
  const falsee = z.templateLiteral([false]);
@@ -289,6 +290,7 @@ test("template literal parsing - success - basic cases", () => {
289
290
  world.parse("world");
290
291
  one.parse("1");
291
292
  two.parse("2");
293
+ onePointOne.parse("1.1");
292
294
  truee.parse("true");
293
295
  anotherTrue.parse("true");
294
296
  falsee.parse("false");
@@ -381,6 +383,7 @@ test("template literal parsing - failure - basic cases", () => {
381
383
  expect(() => one.parse("2")).toThrow();
382
384
  expect(() => one.parse("12")).toThrow();
383
385
  expect(() => one.parse("21")).toThrow();
386
+ expect(() => onePointOne.parse("1s1")).toThrow();
384
387
  expect(() => two.parse("1")).toThrow();
385
388
  expect(() => two.parse("21")).toThrow();
386
389
  expect(() => two.parse("12")).toThrow();
@@ -2795,7 +2795,7 @@ export const $ZodLiteral: core.$constructor<$ZodLiteral> = /*@__PURE__*/ core.$c
2795
2795
  inst._zod.pattern = new RegExp(
2796
2796
  `^(${def.values
2797
2797
 
2798
- .map((o) => (typeof o === "string" ? util.escapeRegex(o) : o ? o.toString() : String(o)))
2798
+ .map((o) => (typeof o === "string" ? util.escapeRegex(o) : o ? util.escapeRegex(o.toString()) : String(o)))
2799
2799
  .join("|")})$`
2800
2800
  );
2801
2801
 
@@ -25,8 +25,6 @@ export interface ZodType<out Output = unknown, out Input = unknown, out Internal
25
25
  safeParseAsync(data: unknown, params?: core.ParseContext<core.$ZodIssue>): Promise<parse.ZodSafeParseResult<core.output<this>>>;
26
26
  spa: (data: unknown, params?: core.ParseContext<core.$ZodIssue>) => Promise<parse.ZodSafeParseResult<core.output<this>>>;
27
27
  refine(check: (arg: core.output<this>) => unknown | Promise<unknown>, params?: string | core.$ZodCustomParams): this;
28
- /** @deprecated Use [`.check()`](https://zod.dev/api?id=check) instead.
29
- */
30
28
  superRefine(refinement: (arg: core.output<this>, ctx: RefinementCtx<core.output<this>>) => void | Promise<void>): this;
31
29
  overwrite(fn: (x: core.output<this>) => core.output<this>): this;
32
30
  optional(): ZodOptional<this>;
@@ -25,8 +25,6 @@ export interface ZodType<out Output = unknown, out Input = unknown, out Internal
25
25
  safeParseAsync(data: unknown, params?: core.ParseContext<core.$ZodIssue>): Promise<parse.ZodSafeParseResult<core.output<this>>>;
26
26
  spa: (data: unknown, params?: core.ParseContext<core.$ZodIssue>) => Promise<parse.ZodSafeParseResult<core.output<this>>>;
27
27
  refine(check: (arg: core.output<this>) => unknown | Promise<unknown>, params?: string | core.$ZodCustomParams): this;
28
- /** @deprecated Use [`.check()`](https://zod.dev/api?id=check) instead.
29
- */
30
28
  superRefine(refinement: (arg: core.output<this>, ctx: RefinementCtx<core.output<this>>) => void | Promise<void>): this;
31
29
  overwrite(fn: (x: core.output<this>) => core.output<this>): this;
32
30
  optional(): ZodOptional<this>;
@@ -1397,7 +1397,7 @@ exports.$ZodLiteral = core.$constructor("$ZodLiteral", (inst, def) => {
1397
1397
  exports.$ZodType.init(inst, def);
1398
1398
  inst._zod.values = new Set(def.values);
1399
1399
  inst._zod.pattern = new RegExp(`^(${def.values
1400
- .map((o) => (typeof o === "string" ? util.escapeRegex(o) : o ? o.toString() : String(o)))
1400
+ .map((o) => (typeof o === "string" ? util.escapeRegex(o) : o ? util.escapeRegex(o.toString()) : String(o)))
1401
1401
  .join("|")})$`);
1402
1402
  inst._zod.parse = (payload, _ctx) => {
1403
1403
  const input = payload.value;
@@ -1366,7 +1366,7 @@ export const $ZodLiteral = /*@__PURE__*/ core.$constructor("$ZodLiteral", (inst,
1366
1366
  $ZodType.init(inst, def);
1367
1367
  inst._zod.values = new Set(def.values);
1368
1368
  inst._zod.pattern = new RegExp(`^(${def.values
1369
- .map((o) => (typeof o === "string" ? util.escapeRegex(o) : o ? o.toString() : String(o)))
1369
+ .map((o) => (typeof o === "string" ? util.escapeRegex(o) : o ? util.escapeRegex(o.toString()) : String(o)))
1370
1370
  .join("|")})$`);
1371
1371
  inst._zod.parse = (payload, _ctx) => {
1372
1372
  const input = payload.value;