zod 4.2.0-canary.20251106T212241 → 4.2.0-canary.20251106T214242

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.20251106T212241",
3
+ "version": "4.2.0-canary.20251106T214242",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Colin McDonnell <zod@colinhacks.com>",
@@ -0,0 +1,379 @@
1
+ import { beforeEach, describe, expect, test } from "vitest";
2
+ import { z } from "../../../../index.js";
3
+ import he from "../../../locales/he.js";
4
+
5
+ describe("Hebrew localization", () => {
6
+ beforeEach(() => {
7
+ z.config(he());
8
+ });
9
+
10
+ describe("too_small errors with definite article and gendered verbs", () => {
11
+ test("string type (feminine - צריכה)", () => {
12
+ const schema = z.string().min(3);
13
+ const result = schema.safeParse("ab");
14
+ expect(result.success).toBe(false);
15
+ if (!result.success) {
16
+ expect(result.error.issues[0].message).toBe("קצר מדי: המחרוזת צריכה להכיל 3 תווים או יותר");
17
+ }
18
+ });
19
+
20
+ test("number type (masculine - צריך)", () => {
21
+ const schema = z.number().min(10);
22
+ const result = schema.safeParse(5);
23
+ expect(result.success).toBe(false);
24
+ if (!result.success) {
25
+ expect(result.error.issues[0].message).toBe("קטן מדי: המספר צריך להיות גדול או שווה ל-10");
26
+ }
27
+ });
28
+
29
+ test("array type (masculine - צריך)", () => {
30
+ const schema = z.array(z.string()).min(1);
31
+ const result = schema.safeParse([]);
32
+ expect(result.success).toBe(false);
33
+ if (!result.success) {
34
+ expect(result.error.issues[0].message).toBe("קטן מדי: המערך צריך להכיל לפחות פריט אחד");
35
+ }
36
+ });
37
+
38
+ test("set type (feminine - צריכה)", () => {
39
+ const schema = z.set(z.string()).min(2);
40
+ const result = schema.safeParse(new Set(["a"]));
41
+ expect(result.success).toBe(false);
42
+ if (!result.success) {
43
+ expect(result.error.issues[0].message).toBe("קטן מדי: הקבוצה (Set) צריכה להכיל 2 פריטים או יותר");
44
+ }
45
+ });
46
+ });
47
+
48
+ describe("too_big errors with definite article and gendered verbs", () => {
49
+ test("string type (feminine - צריכה)", () => {
50
+ const schema = z.string().max(3);
51
+ const result = schema.safeParse("abcde");
52
+ expect(result.success).toBe(false);
53
+ if (!result.success) {
54
+ expect(result.error.issues[0].message).toBe("ארוך מדי: המחרוזת צריכה להכיל 3 תווים או פחות");
55
+ }
56
+ });
57
+
58
+ test("number type (masculine - צריך)", () => {
59
+ const schema = z.number().max(365);
60
+ const result = schema.safeParse(400);
61
+ expect(result.success).toBe(false);
62
+ if (!result.success) {
63
+ expect(result.error.issues[0].message).toBe("גדול מדי: המספר צריך להיות קטן או שווה ל-365");
64
+ }
65
+ });
66
+
67
+ test("array max", () => {
68
+ const schema = z.array(z.string()).max(2);
69
+ const result = schema.safeParse(["a", "b", "c"]);
70
+ expect(result.success).toBe(false);
71
+ if (!result.success) {
72
+ expect(result.error.issues[0].message).toBe("גדול מדי: המערך צריך להכיל 2 פריטים או פחות");
73
+ }
74
+ });
75
+ });
76
+
77
+ describe("invalid_type errors with definite article and gendered verbs", () => {
78
+ test("string expected (feminine), number received", () => {
79
+ const schema = z.string();
80
+ const result = schema.safeParse(123);
81
+ expect(result.success).toBe(false);
82
+ if (!result.success) {
83
+ expect(result.error.issues[0].message).toBe("קלט לא תקין: צריך להיות מחרוזת, התקבל מספר");
84
+ }
85
+ });
86
+
87
+ test("number expected (masculine), string received", () => {
88
+ const schema = z.number();
89
+ const result = schema.safeParse("abc");
90
+ expect(result.success).toBe(false);
91
+ if (!result.success) {
92
+ expect(result.error.issues[0].message).toBe("קלט לא תקין: צריך להיות מספר, התקבל מחרוזת");
93
+ }
94
+ });
95
+
96
+ test("boolean expected (masculine), null received", () => {
97
+ const schema = z.boolean();
98
+ const result = schema.safeParse(null);
99
+ expect(result.success).toBe(false);
100
+ if (!result.success) {
101
+ expect(result.error.issues[0].message).toBe("קלט לא תקין: צריך להיות ערך בוליאני, התקבל ערך ריק (null)");
102
+ }
103
+ });
104
+
105
+ test("array expected (masculine), object received", () => {
106
+ const schema = z.array(z.string());
107
+ const result = schema.safeParse({});
108
+ expect(result.success).toBe(false);
109
+ if (!result.success) {
110
+ expect(result.error.issues[0].message).toBe("קלט לא תקין: צריך להיות מערך, התקבל אובייקט");
111
+ }
112
+ });
113
+
114
+ test("object expected (masculine), array received", () => {
115
+ const schema = z.object({ a: z.string() });
116
+ const result = schema.safeParse([]);
117
+ expect(result.success).toBe(false);
118
+ if (!result.success) {
119
+ expect(result.error.issues[0].message).toBe("קלט לא תקין: צריך להיות אובייקט, התקבל מערך");
120
+ }
121
+ });
122
+
123
+ test("function expected (feminine), string received", () => {
124
+ const schema = z.function();
125
+ const result = schema.safeParse("not a function");
126
+ expect(result.success).toBe(false);
127
+ if (!result.success) {
128
+ expect(result.error.issues[0].message).toBe("קלט לא תקין: צריך להיות פונקציה, התקבל מחרוזת");
129
+ }
130
+ });
131
+ });
132
+
133
+ describe("gendered verbs consistency", () => {
134
+ test("feminine types use צריכה", () => {
135
+ const feminineTypes = [
136
+ { schema: z.string().min(5), input: "abc" },
137
+ { schema: z.set(z.string()).min(2), input: new Set(["a"]) },
138
+ ];
139
+
140
+ for (const { schema, input } of feminineTypes) {
141
+ const result = schema.safeParse(input);
142
+ expect(result.success).toBe(false);
143
+ if (!result.success) {
144
+ expect(result.error.issues[0].message).toContain("צריכה");
145
+ }
146
+ }
147
+ });
148
+
149
+ test("masculine types use צריך", () => {
150
+ const masculineTypes = [
151
+ { schema: z.number().min(10), input: 5 },
152
+ { schema: z.array(z.string()).min(2), input: ["a"] },
153
+ ];
154
+
155
+ for (const { schema, input } of masculineTypes) {
156
+ const result = schema.safeParse(input);
157
+ expect(result.success).toBe(false);
158
+ if (!result.success) {
159
+ expect(result.error.issues[0].message).toContain("צריך");
160
+ }
161
+ }
162
+ });
163
+ });
164
+
165
+ describe("invalid_value with enum", () => {
166
+ test("single value", () => {
167
+ const schema = z.enum(["a"]);
168
+ const result = schema.safeParse("b");
169
+ expect(result.success).toBe(false);
170
+ if (!result.success) {
171
+ expect(result.error.issues[0].message).toBe('ערך לא תקין: הערך חייב להיות "a"');
172
+ }
173
+ });
174
+
175
+ test("two values", () => {
176
+ const schema = z.enum(["a", "b"]);
177
+ const result = schema.safeParse("c");
178
+ expect(result.success).toBe(false);
179
+ if (!result.success) {
180
+ expect(result.error.issues[0].message).toBe('ערך לא תקין: האפשרויות המתאימות הן "a" או "b"');
181
+ }
182
+ });
183
+
184
+ test("multiple values", () => {
185
+ const schema = z.enum(["a", "b", "c"]);
186
+ const result = schema.safeParse("d");
187
+ expect(result.success).toBe(false);
188
+ if (!result.success) {
189
+ expect(result.error.issues[0].message).toBe('ערך לא תקין: האפשרויות המתאימות הן "a", "b" או "c"');
190
+ }
191
+ });
192
+ });
193
+
194
+ describe("other error types", () => {
195
+ test("not_multiple_of", () => {
196
+ const schema = z.number().multipleOf(3);
197
+ const result = schema.safeParse(10);
198
+ expect(result.success).toBe(false);
199
+ if (!result.success) {
200
+ expect(result.error.issues[0].message).toBe("מספר לא תקין: חייב להיות מכפלה של 3");
201
+ }
202
+ });
203
+
204
+ test("unrecognized_keys - single key", () => {
205
+ const schema = z.object({ a: z.string() }).strict();
206
+ const result = schema.safeParse({ a: "test", b: "extra" });
207
+ expect(result.success).toBe(false);
208
+ if (!result.success) {
209
+ expect(result.error.issues[0].message).toBe('מפתח לא מזוהה: "b"');
210
+ }
211
+ });
212
+
213
+ test("unrecognized_keys - multiple keys", () => {
214
+ const schema = z.object({ a: z.string() }).strict();
215
+ const result = schema.safeParse({ a: "test", b: "extra", c: "more" });
216
+ expect(result.success).toBe(false);
217
+ if (!result.success) {
218
+ expect(result.error.issues[0].message).toBe('מפתחות לא מזוהים: "b", "c"');
219
+ }
220
+ });
221
+
222
+ test("invalid_union", () => {
223
+ const schema = z.union([z.string(), z.number()]);
224
+ const result = schema.safeParse(true);
225
+ expect(result.success).toBe(false);
226
+ if (!result.success) {
227
+ expect(result.error.issues[0].message).toBe("קלט לא תקין");
228
+ }
229
+ });
230
+
231
+ test("invalid_key in object", () => {
232
+ const schema = z.record(z.number(), z.string());
233
+ const result = schema.safeParse({ notANumber: "value" });
234
+ expect(result.success).toBe(false);
235
+ if (!result.success) {
236
+ expect(result.error.issues[0].message).toBe("שדה לא תקין באובייקט");
237
+ }
238
+ });
239
+ });
240
+
241
+ describe("invalid_format with string checks", () => {
242
+ test("startsWith", () => {
243
+ const schema = z.string().startsWith("hello");
244
+ const result = schema.safeParse("world");
245
+ expect(result.success).toBe(false);
246
+ if (!result.success) {
247
+ expect(result.error.issues[0].message).toBe('המחרוזת חייבת להתחיל ב "hello"');
248
+ }
249
+ });
250
+
251
+ test("endsWith", () => {
252
+ const schema = z.string().endsWith("world");
253
+ const result = schema.safeParse("hello");
254
+ expect(result.success).toBe(false);
255
+ if (!result.success) {
256
+ expect(result.error.issues[0].message).toBe('המחרוזת חייבת להסתיים ב "world"');
257
+ }
258
+ });
259
+
260
+ test("includes", () => {
261
+ const schema = z.string().includes("test");
262
+ const result = schema.safeParse("hello world");
263
+ expect(result.success).toBe(false);
264
+ if (!result.success) {
265
+ expect(result.error.issues[0].message).toBe('המחרוזת חייבת לכלול "test"');
266
+ }
267
+ });
268
+
269
+ test("regex", () => {
270
+ const schema = z.string().regex(/^[a-z]+$/);
271
+ const result = schema.safeParse("ABC123");
272
+ expect(result.success).toBe(false);
273
+ if (!result.success) {
274
+ expect(result.error.issues[0].message).toBe("המחרוזת חייבת להתאים לתבנית /^[a-z]+$/");
275
+ }
276
+ });
277
+ });
278
+
279
+ describe("invalid_format with common formats", () => {
280
+ test("email", () => {
281
+ const schema = z.string().email();
282
+ const result = schema.safeParse("not-an-email");
283
+ expect(result.success).toBe(false);
284
+ if (!result.success) {
285
+ expect(result.error.issues[0].message).toBe("כתובת אימייל לא תקינה");
286
+ }
287
+ });
288
+
289
+ test("url", () => {
290
+ const schema = z.string().url();
291
+ const result = schema.safeParse("not-a-url");
292
+ expect(result.success).toBe(false);
293
+ if (!result.success) {
294
+ expect(result.error.issues[0].message).toBe("כתובת רשת לא תקינה");
295
+ }
296
+ });
297
+
298
+ test("uuid", () => {
299
+ const schema = z.string().uuid();
300
+ const result = schema.safeParse("not-a-uuid");
301
+ expect(result.success).toBe(false);
302
+ if (!result.success) {
303
+ expect(result.error.issues[0].message).toBe("UUID לא תקין");
304
+ }
305
+ });
306
+ });
307
+
308
+ describe("tuple validation", () => {
309
+ test("invalid element type in tuple shows full error message", () => {
310
+ const schema = z.tuple([z.string(), z.number()]);
311
+ const result = schema.safeParse(["abc", "not a number"]);
312
+ expect(result.success).toBe(false);
313
+ if (!result.success) {
314
+ expect(result.error.issues[0].message).toBe("קלט לא תקין: צריך להיות מספר, התקבל מחרוזת");
315
+ }
316
+ });
317
+ });
318
+
319
+ describe("inclusive vs exclusive bounds", () => {
320
+ test("inclusive minimum (>=)", () => {
321
+ const schema = z.number().min(10);
322
+ const result = schema.safeParse(5);
323
+ expect(result.success).toBe(false);
324
+ if (!result.success) {
325
+ expect(result.error.issues[0].message).toBe("קטן מדי: המספר צריך להיות גדול או שווה ל-10");
326
+ }
327
+ });
328
+
329
+ test("exclusive minimum (>)", () => {
330
+ const schema = z.number().gt(10);
331
+ const result = schema.safeParse(10);
332
+ expect(result.success).toBe(false);
333
+ if (!result.success) {
334
+ expect(result.error.issues[0].message).toBe("קטן מדי: המספר צריך להיות גדול מ-10");
335
+ }
336
+ });
337
+
338
+ test("inclusive maximum (<=)", () => {
339
+ const schema = z.number().max(10);
340
+ const result = schema.safeParse(15);
341
+ expect(result.success).toBe(false);
342
+ if (!result.success) {
343
+ expect(result.error.issues[0].message).toBe("גדול מדי: המספר צריך להיות קטן או שווה ל-10");
344
+ }
345
+ });
346
+
347
+ test("exclusive maximum (<)", () => {
348
+ const schema = z.number().lt(10);
349
+ const result = schema.safeParse(10);
350
+ expect(result.success).toBe(false);
351
+ if (!result.success) {
352
+ expect(result.error.issues[0].message).toBe("גדול מדי: המספר צריך להיות קטן מ-10");
353
+ }
354
+ });
355
+ });
356
+
357
+ describe("all type names with definite article", () => {
358
+ test("verifies all type translations are correct", () => {
359
+ const types = [
360
+ { schema: z.string(), expected: "מחרוזת", input: 123 },
361
+ { schema: z.number(), expected: "מספר", input: "abc" },
362
+ { schema: z.boolean(), expected: "ערך בוליאני", input: "abc" },
363
+ { schema: z.bigint(), expected: "BigInt", input: "abc" },
364
+ { schema: z.date(), expected: "תאריך", input: "abc" },
365
+ { schema: z.array(z.any()), expected: "מערך", input: "abc" },
366
+ { schema: z.object({}), expected: "אובייקט", input: "abc" },
367
+ { schema: z.function(), expected: "פונקציה", input: "abc" },
368
+ ];
369
+
370
+ for (const { schema, expected, input } of types) {
371
+ const result = schema.safeParse(input);
372
+ expect(result.success).toBe(false);
373
+ if (!result.success) {
374
+ expect(result.error.issues[0].message).toContain(expected);
375
+ }
376
+ }
377
+ });
378
+ });
379
+ });
@@ -3,115 +3,246 @@ import type * as errors from "../core/errors.js";
3
3
  import * as util from "../core/util.js";
4
4
 
5
5
  const error: () => errors.$ZodErrorMap = () => {
6
- const Sizable: Record<string, { unit: string; verb: string }> = {
7
- string: { unit: "אותיות", verb: "לכלול" },
8
- file: { unit: "בייטים", verb: "לכלול" },
9
- array: { unit: "פריטים", verb: "לכלול" },
10
- set: { unit: "פריטים", verb: "לכלול" },
6
+ // Hebrew labels + grammatical gender
7
+ const TypeNames: Record<string, { label: string; gender: "m" | "f" }> = {
8
+ string: { label: "מחרוזת", gender: "f" },
9
+ number: { label: "מספר", gender: "m" },
10
+ boolean: { label: "ערך בוליאני", gender: "m" },
11
+ bigint: { label: "BigInt", gender: "m" },
12
+ date: { label: "תאריך", gender: "m" },
13
+ array: { label: "מערך", gender: "m" },
14
+ object: { label: "אובייקט", gender: "m" },
15
+ null: { label: "ערך ריק (null)", gender: "m" },
16
+ undefined: { label: "ערך לא מוגדר (undefined)", gender: "m" },
17
+ symbol: { label: "סימבול (Symbol)", gender: "m" },
18
+ function: { label: "פונקציה", gender: "f" },
19
+ map: { label: "מפה (Map)", gender: "f" },
20
+ set: { label: "קבוצה (Set)", gender: "f" },
21
+ file: { label: "קובץ", gender: "m" },
22
+ promise: { label: "Promise", gender: "m" },
23
+ NaN: { label: "NaN", gender: "m" },
24
+ unknown: { label: "ערך לא ידוע", gender: "m" },
25
+ value: { label: "ערך", gender: "m" },
11
26
  };
12
27
 
13
- function getSizing(origin: string): { unit: string; verb: string } | null {
28
+ // Sizing units for size-related messages + localized origin labels
29
+ const Sizable: Record<string, { unit: string; shortLabel?: string; longLabel?: string }> = {
30
+ string: { unit: "תווים", shortLabel: "קצר", longLabel: "ארוך" },
31
+ file: { unit: "בייטים", shortLabel: "קטן", longLabel: "גדול" },
32
+ array: { unit: "פריטים", shortLabel: "קטן", longLabel: "גדול" },
33
+ set: { unit: "פריטים", shortLabel: "קטן", longLabel: "גדול" },
34
+ number: { unit: "", shortLabel: "קטן", longLabel: "גדול" }, // no unit
35
+ };
36
+
37
+ // Helpers — labels, articles, and verbs
38
+ const typeEntry = (t?: string | null) => (t ? TypeNames[t] : undefined);
39
+
40
+ const typeLabel = (t?: string | null): string => {
41
+ const e = typeEntry(t);
42
+ if (e) return e.label;
43
+ // fallback: show raw string if unknown
44
+ return t ?? TypeNames.unknown.label;
45
+ };
46
+
47
+ const withDefinite = (t?: string | null): string => `ה${typeLabel(t)}`;
48
+
49
+ const verbFor = (t?: string | null): string => {
50
+ const e = typeEntry(t);
51
+ const gender = e?.gender ?? "m";
52
+ return gender === "f" ? "צריכה להיות" : "צריך להיות";
53
+ };
54
+
55
+ const getSizing = (origin?: string | null) => {
56
+ if (!origin) return null;
14
57
  return Sizable[origin] ?? null;
15
- }
58
+ };
16
59
 
60
+ // Robust type parser for "received" — returns a key we understand or a constructor name
17
61
  const parsedType = (data: any): string => {
18
62
  const t = typeof data;
19
-
20
63
  switch (t) {
21
- case "number": {
64
+ case "number":
22
65
  return Number.isNaN(data) ? "NaN" : "number";
23
- }
24
66
  case "object": {
25
- if (Array.isArray(data)) {
26
- return "array";
27
- }
28
- if (data === null) {
29
- return "null";
30
- }
31
-
67
+ if (Array.isArray(data)) return "array";
68
+ if (data === null) return "null";
32
69
  if (Object.getPrototypeOf(data) !== Object.prototype && data.constructor) {
33
- return data.constructor.name;
70
+ return data.constructor.name; // keep as-is (e.g., "Date")
34
71
  }
72
+ return "object";
35
73
  }
74
+ default:
75
+ return t;
36
76
  }
37
- return t;
38
77
  };
39
78
 
40
79
  const Nouns: {
41
- [k in $ZodStringFormats | (string & {})]?: string;
80
+ [k in $ZodStringFormats]: { label: string; gender: "m" | "f" };
42
81
  } = {
43
- regex: "קלט",
44
- email: "כתובת אימייל",
45
- url: "כתובת רשת",
46
- emoji: "אימוג'י",
47
- uuid: "UUID",
48
- uuidv4: "UUIDv4",
49
- uuidv6: "UUIDv6",
50
- nanoid: "nanoid",
51
- guid: "GUID",
52
- cuid: "cuid",
53
- cuid2: "cuid2",
54
- ulid: "ULID",
55
- xid: "XID",
56
- ksuid: "KSUID",
57
- datetime: "תאריך וזמן ISO",
58
- date: "תאריך ISO",
59
- time: "זמן ISO",
60
- duration: "משך זמן ISO",
61
- ipv4: "כתובת IPv4",
62
- ipv6: "כתובת IPv6",
63
- cidrv4: "טווח IPv4",
64
- cidrv6: "טווח IPv6",
65
- base64: "מחרוזת בבסיס 64",
66
- base64url: "מחרוזת בבסיס 64 לכתובות רשת",
67
- json_string: "מחרוזת JSON",
68
- e164: "מספר E.164",
69
- jwt: "JWT",
70
- template_literal: "קלט",
82
+ regex: { label: "קלט", gender: "m" },
83
+ email: { label: "כתובת אימייל", gender: "f" },
84
+ url: { label: "כתובת רשת", gender: "f" },
85
+ emoji: { label: "אימוג'י", gender: "m" },
86
+ uuid: { label: "UUID", gender: "m" },
87
+ nanoid: { label: "nanoid", gender: "m" },
88
+ guid: { label: "GUID", gender: "m" },
89
+ cuid: { label: "cuid", gender: "m" },
90
+ cuid2: { label: "cuid2", gender: "m" },
91
+ ulid: { label: "ULID", gender: "m" },
92
+ xid: { label: "XID", gender: "m" },
93
+ ksuid: { label: "KSUID", gender: "m" },
94
+ datetime: { label: "תאריך וזמן ISO", gender: "m" },
95
+ date: { label: "תאריך ISO", gender: "m" },
96
+ time: { label: "זמן ISO", gender: "m" },
97
+ duration: { label: "משך זמן ISO", gender: "m" },
98
+ ipv4: { label: "כתובת IPv4", gender: "f" },
99
+ ipv6: { label: "כתובת IPv6", gender: "f" },
100
+ cidrv4: { label: "טווח IPv4", gender: "m" },
101
+ cidrv6: { label: "טווח IPv6", gender: "m" },
102
+ base64: { label: "מחרוזת בבסיס 64", gender: "f" },
103
+ base64url: { label: "מחרוזת בבסיס 64 לכתובות רשת", gender: "f" },
104
+ json_string: { label: "מחרוזת JSON", gender: "f" },
105
+ e164: { label: "מספר E.164", gender: "m" },
106
+ jwt: { label: "JWT", gender: "m" },
107
+ ends_with: { label: "קלט", gender: "m" },
108
+ includes: { label: "קלט", gender: "m" },
109
+ lowercase: { label: "קלט", gender: "m" },
110
+ starts_with: { label: "קלט", gender: "m" },
111
+ uppercase: { label: "קלט", gender: "m" },
71
112
  };
72
113
 
73
114
  return (issue) => {
74
115
  switch (issue.code) {
75
- case "invalid_type":
76
- return `קלט לא תקין: צריך ${issue.expected}, התקבל ${parsedType(issue.input)}`;
77
- // return `Invalid input: expected ${issue.expected}, received ${util.getParsedType(issue.input)}`;
78
- case "invalid_value":
79
- if (issue.values.length === 1) return `קלט לא תקין: צריך ${util.stringifyPrimitive(issue.values[0])}`;
80
- return `קלט לא תקין: צריך אחת מהאפשרויות ${util.joinValues(issue.values, "|")}`;
116
+ case "invalid_type": {
117
+ // Expected type: show without definite article for clearer Hebrew
118
+ const expectedKey = issue.expected as string | undefined;
119
+ const expected = typeLabel(expectedKey);
120
+ // Received: show localized label if known, otherwise constructor/raw
121
+ const receivedKey = parsedType(issue.input);
122
+ const received = TypeNames[receivedKey]?.label ?? receivedKey;
123
+ return `קלט לא תקין: צריך להיות ${expected}, התקבל ${received}`;
124
+ }
125
+
126
+ case "invalid_value": {
127
+ if (issue.values.length === 1) {
128
+ return `ערך לא תקין: הערך חייב להיות ${util.stringifyPrimitive(issue.values[0])}`;
129
+ }
130
+ // Join values with proper Hebrew formatting
131
+ const stringified = issue.values.map((v) => util.stringifyPrimitive(v));
132
+ if (issue.values.length === 2) {
133
+ return `ערך לא תקין: האפשרויות המתאימות הן ${stringified[0]} או ${stringified[1]}`;
134
+ }
135
+ // For 3+ values: "a", "b" או "c"
136
+ const lastValue = stringified[stringified.length - 1];
137
+ const restValues = stringified.slice(0, -1).join(", ");
138
+ return `ערך לא תקין: האפשרויות המתאימות הן ${restValues} או ${lastValue}`;
139
+ }
140
+
81
141
  case "too_big": {
82
- const adj = issue.inclusive ? "<=" : "<";
83
142
  const sizing = getSizing(issue.origin);
84
- if (sizing)
85
- return `גדול מדי: ${issue.origin ?? "value"} צריך להיות ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elements"}`;
86
- return `גדול מדי: ${issue.origin ?? "value"} צריך להיות ${adj}${issue.maximum.toString()}`;
143
+ const subject = withDefinite(issue.origin ?? "value");
144
+
145
+ if (issue.origin === "string") {
146
+ // Special handling for strings - more natural Hebrew
147
+ return `${sizing?.longLabel ?? "ארוך"} מדי: ${subject} צריכה להכיל ${issue.maximum.toString()} ${sizing?.unit ?? ""} ${issue.inclusive ? "או פחות" : "לכל היותר"}`.trim();
148
+ }
149
+
150
+ if (issue.origin === "number") {
151
+ // Natural Hebrew for numbers
152
+ const comparison = issue.inclusive ? `קטן או שווה ל-${issue.maximum}` : `קטן מ-${issue.maximum}`;
153
+ return `גדול מדי: ${subject} צריך להיות ${comparison}`;
154
+ }
155
+
156
+ if (issue.origin === "array" || issue.origin === "set") {
157
+ // Natural Hebrew for arrays and sets
158
+ const verb = issue.origin === "set" ? "צריכה" : "צריך";
159
+ const comparison = issue.inclusive
160
+ ? `${issue.maximum} ${sizing?.unit ?? ""} או פחות`
161
+ : `פחות מ-${issue.maximum} ${sizing?.unit ?? ""}`;
162
+ return `גדול מדי: ${subject} ${verb} להכיל ${comparison}`.trim();
163
+ }
164
+
165
+ const adj = issue.inclusive ? "<=" : "<";
166
+ const be = verbFor(issue.origin ?? "value");
167
+ if (sizing?.unit) {
168
+ return `${sizing.longLabel} מדי: ${subject} ${be} ${adj}${issue.maximum.toString()} ${sizing.unit}`;
169
+ }
170
+ return `${sizing?.longLabel ?? "גדול"} מדי: ${subject} ${be} ${adj}${issue.maximum.toString()}`;
87
171
  }
172
+
88
173
  case "too_small": {
89
- const adj = issue.inclusive ? ">=" : ">";
90
174
  const sizing = getSizing(issue.origin);
91
- if (sizing) {
92
- return `קטן מדי: ${issue.origin} צריך להיות ${adj}${issue.minimum.toString()} ${sizing.unit}`;
175
+ const subject = withDefinite(issue.origin ?? "value");
176
+
177
+ if (issue.origin === "string") {
178
+ // Special handling for strings - more natural Hebrew
179
+ return `${sizing?.shortLabel ?? "קצר"} מדי: ${subject} צריכה להכיל ${issue.minimum.toString()} ${sizing?.unit ?? ""} ${issue.inclusive ? "או יותר" : "לפחות"}`.trim();
180
+ }
181
+
182
+ if (issue.origin === "number") {
183
+ // Natural Hebrew for numbers
184
+ const comparison = issue.inclusive ? `גדול או שווה ל-${issue.minimum}` : `גדול מ-${issue.minimum}`;
185
+ return `קטן מדי: ${subject} צריך להיות ${comparison}`;
186
+ }
187
+
188
+ if (issue.origin === "array" || issue.origin === "set") {
189
+ // Natural Hebrew for arrays and sets
190
+ const verb = issue.origin === "set" ? "צריכה" : "צריך";
191
+
192
+ // Special case for singular (minimum === 1)
193
+ if (issue.minimum === 1 && issue.inclusive) {
194
+ const singularPhrase = issue.origin === "set" ? "לפחות פריט אחד" : "לפחות פריט אחד";
195
+ return `קטן מדי: ${subject} ${verb} להכיל ${singularPhrase}`;
196
+ }
197
+
198
+ const comparison = issue.inclusive
199
+ ? `${issue.minimum} ${sizing?.unit ?? ""} או יותר`
200
+ : `יותר מ-${issue.minimum} ${sizing?.unit ?? ""}`;
201
+ return `קטן מדי: ${subject} ${verb} להכיל ${comparison}`.trim();
93
202
  }
94
203
 
95
- return `קטן מדי: ${issue.origin} צריך להיות ${adj}${issue.minimum.toString()}`;
204
+ const adj = issue.inclusive ? ">=" : ">";
205
+ const be = verbFor(issue.origin ?? "value");
206
+ if (sizing?.unit) {
207
+ return `${sizing.shortLabel} מדי: ${subject} ${be} ${adj}${issue.minimum.toString()} ${sizing.unit}`;
208
+ }
209
+ return `${sizing?.shortLabel ?? "קטן"} מדי: ${subject} ${be} ${adj}${issue.minimum.toString()}`;
96
210
  }
211
+
97
212
  case "invalid_format": {
98
213
  const _issue = issue as errors.$ZodStringFormatIssues;
99
- if (_issue.format === "starts_with") return `מחרוזת לא תקינה: חייבת להתחיל ב"${_issue.prefix}"`;
100
- if (_issue.format === "ends_with") return `מחרוזת לא תקינה: חייבת להסתיים ב "${_issue.suffix}"`;
101
- if (_issue.format === "includes") return `מחרוזת לא תקינה: חייבת לכלול "${_issue.includes}"`;
102
- if (_issue.format === "regex") return `מחרוזת לא תקינה: חייבת להתאים לתבנית ${_issue.pattern}`;
103
- return `${Nouns[_issue.format] ?? issue.format} לא תקין`;
214
+ // These apply to strings use feminine grammar + ה׳ הידיעה
215
+ if (_issue.format === "starts_with") return `המחרוזת חייבת להתחיל ב "${_issue.prefix}"`;
216
+ if (_issue.format === "ends_with") return `המחרוזת חייבת להסתיים ב "${_issue.suffix}"`;
217
+ if (_issue.format === "includes") return `המחרוזת חייבת לכלול "${_issue.includes}"`;
218
+ if (_issue.format === "regex") return `המחרוזת חייבת להתאים לתבנית ${_issue.pattern}`;
219
+
220
+ // Handle gender agreement for formats
221
+ const nounEntry = Nouns[_issue.format];
222
+ const noun = nounEntry?.label ?? _issue.format;
223
+ const gender = nounEntry?.gender ?? "m";
224
+ const adjective = gender === "f" ? "תקינה" : "תקין";
225
+ return `${noun} לא ${adjective}`;
104
226
  }
227
+
105
228
  case "not_multiple_of":
106
229
  return `מספר לא תקין: חייב להיות מכפלה של ${issue.divisor}`;
230
+
107
231
  case "unrecognized_keys":
108
232
  return `מפתח${issue.keys.length > 1 ? "ות" : ""} לא מזוה${issue.keys.length > 1 ? "ים" : "ה"}: ${util.joinValues(issue.keys, ", ")}`;
109
- case "invalid_key":
110
- return `מפתח לא תקין ב${issue.origin}`;
233
+
234
+ case "invalid_key": {
235
+ return `שדה לא תקין באובייקט`;
236
+ }
237
+
111
238
  case "invalid_union":
112
239
  return "קלט לא תקין";
113
- case "invalid_element":
114
- return `ערך לא תקין ב${issue.origin}`;
240
+
241
+ case "invalid_element": {
242
+ const place = withDefinite(issue.origin ?? "array");
243
+ return `ערך לא תקין ב${place}`;
244
+ }
245
+
115
246
  default:
116
247
  return `קלט לא תקין`;
117
248
  }
package/v4/locales/he.cjs CHANGED
@@ -26,111 +26,222 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.default = default_1;
27
27
  const util = __importStar(require("../core/util.cjs"));
28
28
  const error = () => {
29
+ // Hebrew labels + grammatical gender
30
+ const TypeNames = {
31
+ string: { label: "מחרוזת", gender: "f" },
32
+ number: { label: "מספר", gender: "m" },
33
+ boolean: { label: "ערך בוליאני", gender: "m" },
34
+ bigint: { label: "BigInt", gender: "m" },
35
+ date: { label: "תאריך", gender: "m" },
36
+ array: { label: "מערך", gender: "m" },
37
+ object: { label: "אובייקט", gender: "m" },
38
+ null: { label: "ערך ריק (null)", gender: "m" },
39
+ undefined: { label: "ערך לא מוגדר (undefined)", gender: "m" },
40
+ symbol: { label: "סימבול (Symbol)", gender: "m" },
41
+ function: { label: "פונקציה", gender: "f" },
42
+ map: { label: "מפה (Map)", gender: "f" },
43
+ set: { label: "קבוצה (Set)", gender: "f" },
44
+ file: { label: "קובץ", gender: "m" },
45
+ promise: { label: "Promise", gender: "m" },
46
+ NaN: { label: "NaN", gender: "m" },
47
+ unknown: { label: "ערך לא ידוע", gender: "m" },
48
+ value: { label: "ערך", gender: "m" },
49
+ };
50
+ // Sizing units for size-related messages + localized origin labels
29
51
  const Sizable = {
30
- string: { unit: "אותיות", verb: "לכלול" },
31
- file: { unit: "בייטים", verb: "לכלול" },
32
- array: { unit: "פריטים", verb: "לכלול" },
33
- set: { unit: "פריטים", verb: "לכלול" },
52
+ string: { unit: "תווים", shortLabel: "קצר", longLabel: "ארוך" },
53
+ file: { unit: "בייטים", shortLabel: "קטן", longLabel: "גדול" },
54
+ array: { unit: "פריטים", shortLabel: "קטן", longLabel: "גדול" },
55
+ set: { unit: "פריטים", shortLabel: "קטן", longLabel: "גדול" },
56
+ number: { unit: "", shortLabel: "קטן", longLabel: "גדול" }, // no unit
57
+ };
58
+ // Helpers — labels, articles, and verbs
59
+ const typeEntry = (t) => (t ? TypeNames[t] : undefined);
60
+ const typeLabel = (t) => {
61
+ const e = typeEntry(t);
62
+ if (e)
63
+ return e.label;
64
+ // fallback: show raw string if unknown
65
+ return t ?? TypeNames.unknown.label;
34
66
  };
35
- function getSizing(origin) {
67
+ const withDefinite = (t) => `ה${typeLabel(t)}`;
68
+ const verbFor = (t) => {
69
+ const e = typeEntry(t);
70
+ const gender = e?.gender ?? "m";
71
+ return gender === "f" ? "צריכה להיות" : "צריך להיות";
72
+ };
73
+ const getSizing = (origin) => {
74
+ if (!origin)
75
+ return null;
36
76
  return Sizable[origin] ?? null;
37
- }
77
+ };
78
+ // Robust type parser for "received" — returns a key we understand or a constructor name
38
79
  const parsedType = (data) => {
39
80
  const t = typeof data;
40
81
  switch (t) {
41
- case "number": {
82
+ case "number":
42
83
  return Number.isNaN(data) ? "NaN" : "number";
43
- }
44
84
  case "object": {
45
- if (Array.isArray(data)) {
85
+ if (Array.isArray(data))
46
86
  return "array";
47
- }
48
- if (data === null) {
87
+ if (data === null)
49
88
  return "null";
50
- }
51
89
  if (Object.getPrototypeOf(data) !== Object.prototype && data.constructor) {
52
- return data.constructor.name;
90
+ return data.constructor.name; // keep as-is (e.g., "Date")
53
91
  }
92
+ return "object";
54
93
  }
94
+ default:
95
+ return t;
55
96
  }
56
- return t;
57
97
  };
58
98
  const Nouns = {
59
- regex: "קלט",
60
- email: "כתובת אימייל",
61
- url: "כתובת רשת",
62
- emoji: "אימוג'י",
63
- uuid: "UUID",
64
- uuidv4: "UUIDv4",
65
- uuidv6: "UUIDv6",
66
- nanoid: "nanoid",
67
- guid: "GUID",
68
- cuid: "cuid",
69
- cuid2: "cuid2",
70
- ulid: "ULID",
71
- xid: "XID",
72
- ksuid: "KSUID",
73
- datetime: "תאריך וזמן ISO",
74
- date: "תאריך ISO",
75
- time: "זמן ISO",
76
- duration: "משך זמן ISO",
77
- ipv4: "כתובת IPv4",
78
- ipv6: "כתובת IPv6",
79
- cidrv4: "טווח IPv4",
80
- cidrv6: "טווח IPv6",
81
- base64: "מחרוזת בבסיס 64",
82
- base64url: "מחרוזת בבסיס 64 לכתובות רשת",
83
- json_string: "מחרוזת JSON",
84
- e164: "מספר E.164",
85
- jwt: "JWT",
86
- template_literal: "קלט",
99
+ regex: { label: "קלט", gender: "m" },
100
+ email: { label: "כתובת אימייל", gender: "f" },
101
+ url: { label: "כתובת רשת", gender: "f" },
102
+ emoji: { label: "אימוג'י", gender: "m" },
103
+ uuid: { label: "UUID", gender: "m" },
104
+ nanoid: { label: "nanoid", gender: "m" },
105
+ guid: { label: "GUID", gender: "m" },
106
+ cuid: { label: "cuid", gender: "m" },
107
+ cuid2: { label: "cuid2", gender: "m" },
108
+ ulid: { label: "ULID", gender: "m" },
109
+ xid: { label: "XID", gender: "m" },
110
+ ksuid: { label: "KSUID", gender: "m" },
111
+ datetime: { label: "תאריך וזמן ISO", gender: "m" },
112
+ date: { label: "תאריך ISO", gender: "m" },
113
+ time: { label: "זמן ISO", gender: "m" },
114
+ duration: { label: "משך זמן ISO", gender: "m" },
115
+ ipv4: { label: "כתובת IPv4", gender: "f" },
116
+ ipv6: { label: "כתובת IPv6", gender: "f" },
117
+ cidrv4: { label: "טווח IPv4", gender: "m" },
118
+ cidrv6: { label: "טווח IPv6", gender: "m" },
119
+ base64: { label: "מחרוזת בבסיס 64", gender: "f" },
120
+ base64url: { label: "מחרוזת בבסיס 64 לכתובות רשת", gender: "f" },
121
+ json_string: { label: "מחרוזת JSON", gender: "f" },
122
+ e164: { label: "מספר E.164", gender: "m" },
123
+ jwt: { label: "JWT", gender: "m" },
124
+ ends_with: { label: "קלט", gender: "m" },
125
+ includes: { label: "קלט", gender: "m" },
126
+ lowercase: { label: "קלט", gender: "m" },
127
+ starts_with: { label: "קלט", gender: "m" },
128
+ uppercase: { label: "קלט", gender: "m" },
87
129
  };
88
130
  return (issue) => {
89
131
  switch (issue.code) {
90
- case "invalid_type":
91
- return `קלט לא תקין: צריך ${issue.expected}, התקבל ${parsedType(issue.input)}`;
92
- // return `Invalid input: expected ${issue.expected}, received ${util.getParsedType(issue.input)}`;
93
- case "invalid_value":
94
- if (issue.values.length === 1)
95
- return `קלט לא תקין: צריך ${util.stringifyPrimitive(issue.values[0])}`;
96
- return `קלט לא תקין: צריך אחת מהאפשרויות ${util.joinValues(issue.values, "|")}`;
132
+ case "invalid_type": {
133
+ // Expected type: show without definite article for clearer Hebrew
134
+ const expectedKey = issue.expected;
135
+ const expected = typeLabel(expectedKey);
136
+ // Received: show localized label if known, otherwise constructor/raw
137
+ const receivedKey = parsedType(issue.input);
138
+ const received = TypeNames[receivedKey]?.label ?? receivedKey;
139
+ return `קלט לא תקין: צריך להיות ${expected}, התקבל ${received}`;
140
+ }
141
+ case "invalid_value": {
142
+ if (issue.values.length === 1) {
143
+ return `ערך לא תקין: הערך חייב להיות ${util.stringifyPrimitive(issue.values[0])}`;
144
+ }
145
+ // Join values with proper Hebrew formatting
146
+ const stringified = issue.values.map((v) => util.stringifyPrimitive(v));
147
+ if (issue.values.length === 2) {
148
+ return `ערך לא תקין: האפשרויות המתאימות הן ${stringified[0]} או ${stringified[1]}`;
149
+ }
150
+ // For 3+ values: "a", "b" או "c"
151
+ const lastValue = stringified[stringified.length - 1];
152
+ const restValues = stringified.slice(0, -1).join(", ");
153
+ return `ערך לא תקין: האפשרויות המתאימות הן ${restValues} או ${lastValue}`;
154
+ }
97
155
  case "too_big": {
98
- const adj = issue.inclusive ? "<=" : "<";
99
156
  const sizing = getSizing(issue.origin);
100
- if (sizing)
101
- return `גדול מדי: ${issue.origin ?? "value"} צריך להיות ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elements"}`;
102
- return `גדול מדי: ${issue.origin ?? "value"} צריך להיות ${adj}${issue.maximum.toString()}`;
157
+ const subject = withDefinite(issue.origin ?? "value");
158
+ if (issue.origin === "string") {
159
+ // Special handling for strings - more natural Hebrew
160
+ return `${sizing?.longLabel ?? "ארוך"} מדי: ${subject} צריכה להכיל ${issue.maximum.toString()} ${sizing?.unit ?? ""} ${issue.inclusive ? "או פחות" : "לכל היותר"}`.trim();
161
+ }
162
+ if (issue.origin === "number") {
163
+ // Natural Hebrew for numbers
164
+ const comparison = issue.inclusive ? `קטן או שווה ל-${issue.maximum}` : `קטן מ-${issue.maximum}`;
165
+ return `גדול מדי: ${subject} צריך להיות ${comparison}`;
166
+ }
167
+ if (issue.origin === "array" || issue.origin === "set") {
168
+ // Natural Hebrew for arrays and sets
169
+ const verb = issue.origin === "set" ? "צריכה" : "צריך";
170
+ const comparison = issue.inclusive
171
+ ? `${issue.maximum} ${sizing?.unit ?? ""} או פחות`
172
+ : `פחות מ-${issue.maximum} ${sizing?.unit ?? ""}`;
173
+ return `גדול מדי: ${subject} ${verb} להכיל ${comparison}`.trim();
174
+ }
175
+ const adj = issue.inclusive ? "<=" : "<";
176
+ const be = verbFor(issue.origin ?? "value");
177
+ if (sizing?.unit) {
178
+ return `${sizing.longLabel} מדי: ${subject} ${be} ${adj}${issue.maximum.toString()} ${sizing.unit}`;
179
+ }
180
+ return `${sizing?.longLabel ?? "גדול"} מדי: ${subject} ${be} ${adj}${issue.maximum.toString()}`;
103
181
  }
104
182
  case "too_small": {
105
- const adj = issue.inclusive ? ">=" : ">";
106
183
  const sizing = getSizing(issue.origin);
107
- if (sizing) {
108
- return `קטן מדי: ${issue.origin} צריך להיות ${adj}${issue.minimum.toString()} ${sizing.unit}`;
184
+ const subject = withDefinite(issue.origin ?? "value");
185
+ if (issue.origin === "string") {
186
+ // Special handling for strings - more natural Hebrew
187
+ return `${sizing?.shortLabel ?? "קצר"} מדי: ${subject} צריכה להכיל ${issue.minimum.toString()} ${sizing?.unit ?? ""} ${issue.inclusive ? "או יותר" : "לפחות"}`.trim();
109
188
  }
110
- return `קטן מדי: ${issue.origin} צריך להיות ${adj}${issue.minimum.toString()}`;
189
+ if (issue.origin === "number") {
190
+ // Natural Hebrew for numbers
191
+ const comparison = issue.inclusive ? `גדול או שווה ל-${issue.minimum}` : `גדול מ-${issue.minimum}`;
192
+ return `קטן מדי: ${subject} צריך להיות ${comparison}`;
193
+ }
194
+ if (issue.origin === "array" || issue.origin === "set") {
195
+ // Natural Hebrew for arrays and sets
196
+ const verb = issue.origin === "set" ? "צריכה" : "צריך";
197
+ // Special case for singular (minimum === 1)
198
+ if (issue.minimum === 1 && issue.inclusive) {
199
+ const singularPhrase = issue.origin === "set" ? "לפחות פריט אחד" : "לפחות פריט אחד";
200
+ return `קטן מדי: ${subject} ${verb} להכיל ${singularPhrase}`;
201
+ }
202
+ const comparison = issue.inclusive
203
+ ? `${issue.minimum} ${sizing?.unit ?? ""} או יותר`
204
+ : `יותר מ-${issue.minimum} ${sizing?.unit ?? ""}`;
205
+ return `קטן מדי: ${subject} ${verb} להכיל ${comparison}`.trim();
206
+ }
207
+ const adj = issue.inclusive ? ">=" : ">";
208
+ const be = verbFor(issue.origin ?? "value");
209
+ if (sizing?.unit) {
210
+ return `${sizing.shortLabel} מדי: ${subject} ${be} ${adj}${issue.minimum.toString()} ${sizing.unit}`;
211
+ }
212
+ return `${sizing?.shortLabel ?? "קטן"} מדי: ${subject} ${be} ${adj}${issue.minimum.toString()}`;
111
213
  }
112
214
  case "invalid_format": {
113
215
  const _issue = issue;
216
+ // These apply to strings — use feminine grammar + ה׳ הידיעה
114
217
  if (_issue.format === "starts_with")
115
- return `מחרוזת לא תקינה: חייבת להתחיל ב"${_issue.prefix}"`;
218
+ return `המחרוזת חייבת להתחיל ב "${_issue.prefix}"`;
116
219
  if (_issue.format === "ends_with")
117
- return `מחרוזת לא תקינה: חייבת להסתיים ב "${_issue.suffix}"`;
220
+ return `המחרוזת חייבת להסתיים ב "${_issue.suffix}"`;
118
221
  if (_issue.format === "includes")
119
- return `מחרוזת לא תקינה: חייבת לכלול "${_issue.includes}"`;
222
+ return `המחרוזת חייבת לכלול "${_issue.includes}"`;
120
223
  if (_issue.format === "regex")
121
- return `מחרוזת לא תקינה: חייבת להתאים לתבנית ${_issue.pattern}`;
122
- return `${Nouns[_issue.format] ?? issue.format} לא תקין`;
224
+ return `המחרוזת חייבת להתאים לתבנית ${_issue.pattern}`;
225
+ // Handle gender agreement for formats
226
+ const nounEntry = Nouns[_issue.format];
227
+ const noun = nounEntry?.label ?? _issue.format;
228
+ const gender = nounEntry?.gender ?? "m";
229
+ const adjective = gender === "f" ? "תקינה" : "תקין";
230
+ return `${noun} לא ${adjective}`;
123
231
  }
124
232
  case "not_multiple_of":
125
233
  return `מספר לא תקין: חייב להיות מכפלה של ${issue.divisor}`;
126
234
  case "unrecognized_keys":
127
235
  return `מפתח${issue.keys.length > 1 ? "ות" : ""} לא מזוה${issue.keys.length > 1 ? "ים" : "ה"}: ${util.joinValues(issue.keys, ", ")}`;
128
- case "invalid_key":
129
- return `מפתח לא תקין ב${issue.origin}`;
236
+ case "invalid_key": {
237
+ return `שדה לא תקין באובייקט`;
238
+ }
130
239
  case "invalid_union":
131
240
  return "קלט לא תקין";
132
- case "invalid_element":
133
- return `ערך לא תקין ב${issue.origin}`;
241
+ case "invalid_element": {
242
+ const place = withDefinite(issue.origin ?? "array");
243
+ return `ערך לא תקין ב${place}`;
244
+ }
134
245
  default:
135
246
  return `קלט לא תקין`;
136
247
  }
package/v4/locales/he.js CHANGED
@@ -1,110 +1,221 @@
1
1
  import * as util from "../core/util.js";
2
2
  const error = () => {
3
+ // Hebrew labels + grammatical gender
4
+ const TypeNames = {
5
+ string: { label: "מחרוזת", gender: "f" },
6
+ number: { label: "מספר", gender: "m" },
7
+ boolean: { label: "ערך בוליאני", gender: "m" },
8
+ bigint: { label: "BigInt", gender: "m" },
9
+ date: { label: "תאריך", gender: "m" },
10
+ array: { label: "מערך", gender: "m" },
11
+ object: { label: "אובייקט", gender: "m" },
12
+ null: { label: "ערך ריק (null)", gender: "m" },
13
+ undefined: { label: "ערך לא מוגדר (undefined)", gender: "m" },
14
+ symbol: { label: "סימבול (Symbol)", gender: "m" },
15
+ function: { label: "פונקציה", gender: "f" },
16
+ map: { label: "מפה (Map)", gender: "f" },
17
+ set: { label: "קבוצה (Set)", gender: "f" },
18
+ file: { label: "קובץ", gender: "m" },
19
+ promise: { label: "Promise", gender: "m" },
20
+ NaN: { label: "NaN", gender: "m" },
21
+ unknown: { label: "ערך לא ידוע", gender: "m" },
22
+ value: { label: "ערך", gender: "m" },
23
+ };
24
+ // Sizing units for size-related messages + localized origin labels
3
25
  const Sizable = {
4
- string: { unit: "אותיות", verb: "לכלול" },
5
- file: { unit: "בייטים", verb: "לכלול" },
6
- array: { unit: "פריטים", verb: "לכלול" },
7
- set: { unit: "פריטים", verb: "לכלול" },
26
+ string: { unit: "תווים", shortLabel: "קצר", longLabel: "ארוך" },
27
+ file: { unit: "בייטים", shortLabel: "קטן", longLabel: "גדול" },
28
+ array: { unit: "פריטים", shortLabel: "קטן", longLabel: "גדול" },
29
+ set: { unit: "פריטים", shortLabel: "קטן", longLabel: "גדול" },
30
+ number: { unit: "", shortLabel: "קטן", longLabel: "גדול" }, // no unit
31
+ };
32
+ // Helpers — labels, articles, and verbs
33
+ const typeEntry = (t) => (t ? TypeNames[t] : undefined);
34
+ const typeLabel = (t) => {
35
+ const e = typeEntry(t);
36
+ if (e)
37
+ return e.label;
38
+ // fallback: show raw string if unknown
39
+ return t ?? TypeNames.unknown.label;
8
40
  };
9
- function getSizing(origin) {
41
+ const withDefinite = (t) => `ה${typeLabel(t)}`;
42
+ const verbFor = (t) => {
43
+ const e = typeEntry(t);
44
+ const gender = e?.gender ?? "m";
45
+ return gender === "f" ? "צריכה להיות" : "צריך להיות";
46
+ };
47
+ const getSizing = (origin) => {
48
+ if (!origin)
49
+ return null;
10
50
  return Sizable[origin] ?? null;
11
- }
51
+ };
52
+ // Robust type parser for "received" — returns a key we understand or a constructor name
12
53
  const parsedType = (data) => {
13
54
  const t = typeof data;
14
55
  switch (t) {
15
- case "number": {
56
+ case "number":
16
57
  return Number.isNaN(data) ? "NaN" : "number";
17
- }
18
58
  case "object": {
19
- if (Array.isArray(data)) {
59
+ if (Array.isArray(data))
20
60
  return "array";
21
- }
22
- if (data === null) {
61
+ if (data === null)
23
62
  return "null";
24
- }
25
63
  if (Object.getPrototypeOf(data) !== Object.prototype && data.constructor) {
26
- return data.constructor.name;
64
+ return data.constructor.name; // keep as-is (e.g., "Date")
27
65
  }
66
+ return "object";
28
67
  }
68
+ default:
69
+ return t;
29
70
  }
30
- return t;
31
71
  };
32
72
  const Nouns = {
33
- regex: "קלט",
34
- email: "כתובת אימייל",
35
- url: "כתובת רשת",
36
- emoji: "אימוג'י",
37
- uuid: "UUID",
38
- uuidv4: "UUIDv4",
39
- uuidv6: "UUIDv6",
40
- nanoid: "nanoid",
41
- guid: "GUID",
42
- cuid: "cuid",
43
- cuid2: "cuid2",
44
- ulid: "ULID",
45
- xid: "XID",
46
- ksuid: "KSUID",
47
- datetime: "תאריך וזמן ISO",
48
- date: "תאריך ISO",
49
- time: "זמן ISO",
50
- duration: "משך זמן ISO",
51
- ipv4: "כתובת IPv4",
52
- ipv6: "כתובת IPv6",
53
- cidrv4: "טווח IPv4",
54
- cidrv6: "טווח IPv6",
55
- base64: "מחרוזת בבסיס 64",
56
- base64url: "מחרוזת בבסיס 64 לכתובות רשת",
57
- json_string: "מחרוזת JSON",
58
- e164: "מספר E.164",
59
- jwt: "JWT",
60
- template_literal: "קלט",
73
+ regex: { label: "קלט", gender: "m" },
74
+ email: { label: "כתובת אימייל", gender: "f" },
75
+ url: { label: "כתובת רשת", gender: "f" },
76
+ emoji: { label: "אימוג'י", gender: "m" },
77
+ uuid: { label: "UUID", gender: "m" },
78
+ nanoid: { label: "nanoid", gender: "m" },
79
+ guid: { label: "GUID", gender: "m" },
80
+ cuid: { label: "cuid", gender: "m" },
81
+ cuid2: { label: "cuid2", gender: "m" },
82
+ ulid: { label: "ULID", gender: "m" },
83
+ xid: { label: "XID", gender: "m" },
84
+ ksuid: { label: "KSUID", gender: "m" },
85
+ datetime: { label: "תאריך וזמן ISO", gender: "m" },
86
+ date: { label: "תאריך ISO", gender: "m" },
87
+ time: { label: "זמן ISO", gender: "m" },
88
+ duration: { label: "משך זמן ISO", gender: "m" },
89
+ ipv4: { label: "כתובת IPv4", gender: "f" },
90
+ ipv6: { label: "כתובת IPv6", gender: "f" },
91
+ cidrv4: { label: "טווח IPv4", gender: "m" },
92
+ cidrv6: { label: "טווח IPv6", gender: "m" },
93
+ base64: { label: "מחרוזת בבסיס 64", gender: "f" },
94
+ base64url: { label: "מחרוזת בבסיס 64 לכתובות רשת", gender: "f" },
95
+ json_string: { label: "מחרוזת JSON", gender: "f" },
96
+ e164: { label: "מספר E.164", gender: "m" },
97
+ jwt: { label: "JWT", gender: "m" },
98
+ ends_with: { label: "קלט", gender: "m" },
99
+ includes: { label: "קלט", gender: "m" },
100
+ lowercase: { label: "קלט", gender: "m" },
101
+ starts_with: { label: "קלט", gender: "m" },
102
+ uppercase: { label: "קלט", gender: "m" },
61
103
  };
62
104
  return (issue) => {
63
105
  switch (issue.code) {
64
- case "invalid_type":
65
- return `קלט לא תקין: צריך ${issue.expected}, התקבל ${parsedType(issue.input)}`;
66
- // return `Invalid input: expected ${issue.expected}, received ${util.getParsedType(issue.input)}`;
67
- case "invalid_value":
68
- if (issue.values.length === 1)
69
- return `קלט לא תקין: צריך ${util.stringifyPrimitive(issue.values[0])}`;
70
- return `קלט לא תקין: צריך אחת מהאפשרויות ${util.joinValues(issue.values, "|")}`;
106
+ case "invalid_type": {
107
+ // Expected type: show without definite article for clearer Hebrew
108
+ const expectedKey = issue.expected;
109
+ const expected = typeLabel(expectedKey);
110
+ // Received: show localized label if known, otherwise constructor/raw
111
+ const receivedKey = parsedType(issue.input);
112
+ const received = TypeNames[receivedKey]?.label ?? receivedKey;
113
+ return `קלט לא תקין: צריך להיות ${expected}, התקבל ${received}`;
114
+ }
115
+ case "invalid_value": {
116
+ if (issue.values.length === 1) {
117
+ return `ערך לא תקין: הערך חייב להיות ${util.stringifyPrimitive(issue.values[0])}`;
118
+ }
119
+ // Join values with proper Hebrew formatting
120
+ const stringified = issue.values.map((v) => util.stringifyPrimitive(v));
121
+ if (issue.values.length === 2) {
122
+ return `ערך לא תקין: האפשרויות המתאימות הן ${stringified[0]} או ${stringified[1]}`;
123
+ }
124
+ // For 3+ values: "a", "b" או "c"
125
+ const lastValue = stringified[stringified.length - 1];
126
+ const restValues = stringified.slice(0, -1).join(", ");
127
+ return `ערך לא תקין: האפשרויות המתאימות הן ${restValues} או ${lastValue}`;
128
+ }
71
129
  case "too_big": {
72
- const adj = issue.inclusive ? "<=" : "<";
73
130
  const sizing = getSizing(issue.origin);
74
- if (sizing)
75
- return `גדול מדי: ${issue.origin ?? "value"} צריך להיות ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elements"}`;
76
- return `גדול מדי: ${issue.origin ?? "value"} צריך להיות ${adj}${issue.maximum.toString()}`;
131
+ const subject = withDefinite(issue.origin ?? "value");
132
+ if (issue.origin === "string") {
133
+ // Special handling for strings - more natural Hebrew
134
+ return `${sizing?.longLabel ?? "ארוך"} מדי: ${subject} צריכה להכיל ${issue.maximum.toString()} ${sizing?.unit ?? ""} ${issue.inclusive ? "או פחות" : "לכל היותר"}`.trim();
135
+ }
136
+ if (issue.origin === "number") {
137
+ // Natural Hebrew for numbers
138
+ const comparison = issue.inclusive ? `קטן או שווה ל-${issue.maximum}` : `קטן מ-${issue.maximum}`;
139
+ return `גדול מדי: ${subject} צריך להיות ${comparison}`;
140
+ }
141
+ if (issue.origin === "array" || issue.origin === "set") {
142
+ // Natural Hebrew for arrays and sets
143
+ const verb = issue.origin === "set" ? "צריכה" : "צריך";
144
+ const comparison = issue.inclusive
145
+ ? `${issue.maximum} ${sizing?.unit ?? ""} או פחות`
146
+ : `פחות מ-${issue.maximum} ${sizing?.unit ?? ""}`;
147
+ return `גדול מדי: ${subject} ${verb} להכיל ${comparison}`.trim();
148
+ }
149
+ const adj = issue.inclusive ? "<=" : "<";
150
+ const be = verbFor(issue.origin ?? "value");
151
+ if (sizing?.unit) {
152
+ return `${sizing.longLabel} מדי: ${subject} ${be} ${adj}${issue.maximum.toString()} ${sizing.unit}`;
153
+ }
154
+ return `${sizing?.longLabel ?? "גדול"} מדי: ${subject} ${be} ${adj}${issue.maximum.toString()}`;
77
155
  }
78
156
  case "too_small": {
79
- const adj = issue.inclusive ? ">=" : ">";
80
157
  const sizing = getSizing(issue.origin);
81
- if (sizing) {
82
- return `קטן מדי: ${issue.origin} צריך להיות ${adj}${issue.minimum.toString()} ${sizing.unit}`;
158
+ const subject = withDefinite(issue.origin ?? "value");
159
+ if (issue.origin === "string") {
160
+ // Special handling for strings - more natural Hebrew
161
+ return `${sizing?.shortLabel ?? "קצר"} מדי: ${subject} צריכה להכיל ${issue.minimum.toString()} ${sizing?.unit ?? ""} ${issue.inclusive ? "או יותר" : "לפחות"}`.trim();
83
162
  }
84
- return `קטן מדי: ${issue.origin} צריך להיות ${adj}${issue.minimum.toString()}`;
163
+ if (issue.origin === "number") {
164
+ // Natural Hebrew for numbers
165
+ const comparison = issue.inclusive ? `גדול או שווה ל-${issue.minimum}` : `גדול מ-${issue.minimum}`;
166
+ return `קטן מדי: ${subject} צריך להיות ${comparison}`;
167
+ }
168
+ if (issue.origin === "array" || issue.origin === "set") {
169
+ // Natural Hebrew for arrays and sets
170
+ const verb = issue.origin === "set" ? "צריכה" : "צריך";
171
+ // Special case for singular (minimum === 1)
172
+ if (issue.minimum === 1 && issue.inclusive) {
173
+ const singularPhrase = issue.origin === "set" ? "לפחות פריט אחד" : "לפחות פריט אחד";
174
+ return `קטן מדי: ${subject} ${verb} להכיל ${singularPhrase}`;
175
+ }
176
+ const comparison = issue.inclusive
177
+ ? `${issue.minimum} ${sizing?.unit ?? ""} או יותר`
178
+ : `יותר מ-${issue.minimum} ${sizing?.unit ?? ""}`;
179
+ return `קטן מדי: ${subject} ${verb} להכיל ${comparison}`.trim();
180
+ }
181
+ const adj = issue.inclusive ? ">=" : ">";
182
+ const be = verbFor(issue.origin ?? "value");
183
+ if (sizing?.unit) {
184
+ return `${sizing.shortLabel} מדי: ${subject} ${be} ${adj}${issue.minimum.toString()} ${sizing.unit}`;
185
+ }
186
+ return `${sizing?.shortLabel ?? "קטן"} מדי: ${subject} ${be} ${adj}${issue.minimum.toString()}`;
85
187
  }
86
188
  case "invalid_format": {
87
189
  const _issue = issue;
190
+ // These apply to strings — use feminine grammar + ה׳ הידיעה
88
191
  if (_issue.format === "starts_with")
89
- return `מחרוזת לא תקינה: חייבת להתחיל ב"${_issue.prefix}"`;
192
+ return `המחרוזת חייבת להתחיל ב "${_issue.prefix}"`;
90
193
  if (_issue.format === "ends_with")
91
- return `מחרוזת לא תקינה: חייבת להסתיים ב "${_issue.suffix}"`;
194
+ return `המחרוזת חייבת להסתיים ב "${_issue.suffix}"`;
92
195
  if (_issue.format === "includes")
93
- return `מחרוזת לא תקינה: חייבת לכלול "${_issue.includes}"`;
196
+ return `המחרוזת חייבת לכלול "${_issue.includes}"`;
94
197
  if (_issue.format === "regex")
95
- return `מחרוזת לא תקינה: חייבת להתאים לתבנית ${_issue.pattern}`;
96
- return `${Nouns[_issue.format] ?? issue.format} לא תקין`;
198
+ return `המחרוזת חייבת להתאים לתבנית ${_issue.pattern}`;
199
+ // Handle gender agreement for formats
200
+ const nounEntry = Nouns[_issue.format];
201
+ const noun = nounEntry?.label ?? _issue.format;
202
+ const gender = nounEntry?.gender ?? "m";
203
+ const adjective = gender === "f" ? "תקינה" : "תקין";
204
+ return `${noun} לא ${adjective}`;
97
205
  }
98
206
  case "not_multiple_of":
99
207
  return `מספר לא תקין: חייב להיות מכפלה של ${issue.divisor}`;
100
208
  case "unrecognized_keys":
101
209
  return `מפתח${issue.keys.length > 1 ? "ות" : ""} לא מזוה${issue.keys.length > 1 ? "ים" : "ה"}: ${util.joinValues(issue.keys, ", ")}`;
102
- case "invalid_key":
103
- return `מפתח לא תקין ב${issue.origin}`;
210
+ case "invalid_key": {
211
+ return `שדה לא תקין באובייקט`;
212
+ }
104
213
  case "invalid_union":
105
214
  return "קלט לא תקין";
106
- case "invalid_element":
107
- return `ערך לא תקין ב${issue.origin}`;
215
+ case "invalid_element": {
216
+ const place = withDefinite(issue.origin ?? "array");
217
+ return `ערך לא תקין ב${place}`;
218
+ }
108
219
  default:
109
220
  return `קלט לא תקין`;
110
221
  }