zod 4.2.0-canary.20250911T045022 → 4.2.0-canary.20250911T045735
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/README.md +1 -1
- package/package.json +1 -1
- package/src/v4/core/tests/locales/es.test.ts +181 -0
- package/src/v4/locales/es.ts +44 -10
- package/v4/locales/es.cjs +42 -10
- package/v4/locales/es.js +42 -10
package/README.md
CHANGED
|
@@ -121,7 +121,7 @@ Player.parse({ username: "billie", xp: 100 });
|
|
|
121
121
|
// => returns { username: "billie", xp: 100 }
|
|
122
122
|
```
|
|
123
123
|
|
|
124
|
-
**Note** — If your schema uses certain asynchronous APIs like `async` [refinements](#
|
|
124
|
+
**Note** — If your schema uses certain asynchronous APIs like `async` [refinements](https://zod.dev/api#refinements) or [transforms](https://zod.dev/api#transforms), you'll need to use the `.parseAsync()` method instead.
|
|
125
125
|
|
|
126
126
|
```ts
|
|
127
127
|
const schema = z.string().refine(async (val) => val.length <= 8);
|
package/package.json
CHANGED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { z } from "../../../../index.js";
|
|
3
|
+
import es from "../../../locales/es.js";
|
|
4
|
+
|
|
5
|
+
test("Spanish locale - type name translations in too_small errors", () => {
|
|
6
|
+
z.config(es());
|
|
7
|
+
|
|
8
|
+
// Test string type translation
|
|
9
|
+
const stringSchema = z.string().min(5);
|
|
10
|
+
const stringResult = stringSchema.safeParse("abc");
|
|
11
|
+
expect(stringResult.success).toBe(false);
|
|
12
|
+
if (!stringResult.success) {
|
|
13
|
+
expect(stringResult.error.issues[0].message).toBe(
|
|
14
|
+
"Demasiado pequeño: se esperaba que texto tuviera >=5 caracteres"
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Test number type translation
|
|
19
|
+
const numberSchema = z.number().min(10);
|
|
20
|
+
const numberResult = numberSchema.safeParse(5);
|
|
21
|
+
expect(numberResult.success).toBe(false);
|
|
22
|
+
if (!numberResult.success) {
|
|
23
|
+
expect(numberResult.error.issues[0].message).toBe("Demasiado pequeño: se esperaba que número fuera >=10");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Test array type translation
|
|
27
|
+
const arraySchema = z.array(z.string()).min(3);
|
|
28
|
+
const arrayResult = arraySchema.safeParse(["a", "b"]);
|
|
29
|
+
expect(arrayResult.success).toBe(false);
|
|
30
|
+
if (!arrayResult.success) {
|
|
31
|
+
expect(arrayResult.error.issues[0].message).toBe(
|
|
32
|
+
"Demasiado pequeño: se esperaba que arreglo tuviera >=3 elementos"
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Test set type translation
|
|
37
|
+
const setSchema = z.set(z.string()).min(2);
|
|
38
|
+
const setResult = setSchema.safeParse(new Set(["a"]));
|
|
39
|
+
expect(setResult.success).toBe(false);
|
|
40
|
+
if (!setResult.success) {
|
|
41
|
+
expect(setResult.error.issues[0].message).toBe("Demasiado pequeño: se esperaba que conjunto tuviera >=2 elementos");
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("Spanish locale - type name translations in too_big errors", () => {
|
|
46
|
+
z.config(es());
|
|
47
|
+
|
|
48
|
+
// Test string type translation
|
|
49
|
+
const stringSchema = z.string().max(3);
|
|
50
|
+
const stringResult = stringSchema.safeParse("abcde");
|
|
51
|
+
expect(stringResult.success).toBe(false);
|
|
52
|
+
if (!stringResult.success) {
|
|
53
|
+
expect(stringResult.error.issues[0].message).toBe("Demasiado grande: se esperaba que texto tuviera <=3 caracteres");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Test number type translation
|
|
57
|
+
const numberSchema = z.number().max(10);
|
|
58
|
+
const numberResult = numberSchema.safeParse(15);
|
|
59
|
+
expect(numberResult.success).toBe(false);
|
|
60
|
+
if (!numberResult.success) {
|
|
61
|
+
expect(numberResult.error.issues[0].message).toBe("Demasiado grande: se esperaba que número fuera <=10");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Test array type translation
|
|
65
|
+
const arraySchema = z.array(z.string()).max(2);
|
|
66
|
+
const arrayResult = arraySchema.safeParse(["a", "b", "c"]);
|
|
67
|
+
expect(arrayResult.success).toBe(false);
|
|
68
|
+
if (!arrayResult.success) {
|
|
69
|
+
expect(arrayResult.error.issues[0].message).toBe("Demasiado grande: se esperaba que arreglo tuviera <=2 elementos");
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("Spanish locale - type name translations in invalid_type errors", () => {
|
|
74
|
+
z.config(es());
|
|
75
|
+
|
|
76
|
+
// Test string expected, number received
|
|
77
|
+
const stringSchema = z.string();
|
|
78
|
+
const stringResult = stringSchema.safeParse(123);
|
|
79
|
+
expect(stringResult.success).toBe(false);
|
|
80
|
+
if (!stringResult.success) {
|
|
81
|
+
expect(stringResult.error.issues[0].message).toBe("Entrada inválida: se esperaba texto, recibido número");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Test number expected, string received
|
|
85
|
+
const numberSchema = z.number();
|
|
86
|
+
const numberResult = numberSchema.safeParse("abc");
|
|
87
|
+
expect(numberResult.success).toBe(false);
|
|
88
|
+
if (!numberResult.success) {
|
|
89
|
+
expect(numberResult.error.issues[0].message).toBe("Entrada inválida: se esperaba número, recibido texto");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Test boolean expected, null received
|
|
93
|
+
const booleanSchema = z.boolean();
|
|
94
|
+
const booleanResult = booleanSchema.safeParse(null);
|
|
95
|
+
expect(booleanResult.success).toBe(false);
|
|
96
|
+
if (!booleanResult.success) {
|
|
97
|
+
expect(booleanResult.error.issues[0].message).toBe("Entrada inválida: se esperaba booleano, recibido nulo");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Test array expected, object received
|
|
101
|
+
const arraySchema = z.array(z.string());
|
|
102
|
+
const arrayResult = arraySchema.safeParse({});
|
|
103
|
+
expect(arrayResult.success).toBe(false);
|
|
104
|
+
if (!arrayResult.success) {
|
|
105
|
+
expect(arrayResult.error.issues[0].message).toBe("Entrada inválida: se esperaba arreglo, recibido objeto");
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("Spanish locale - fallback for unknown type names", () => {
|
|
110
|
+
z.config(es());
|
|
111
|
+
|
|
112
|
+
// Test with a type that's not in the TypeNames dictionary
|
|
113
|
+
// This will test the fallback behavior
|
|
114
|
+
const dateSchema = z.date().min(new Date("2025-01-01"));
|
|
115
|
+
const dateResult = dateSchema.safeParse(new Date("2024-01-01"));
|
|
116
|
+
expect(dateResult.success).toBe(false);
|
|
117
|
+
if (!dateResult.success) {
|
|
118
|
+
// Should use "fecha" since we included it in TypeNames
|
|
119
|
+
expect(dateResult.error.issues[0].message).toContain("fecha");
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("Spanish locale - other error cases", () => {
|
|
124
|
+
z.config(es());
|
|
125
|
+
|
|
126
|
+
// Test invalid_element with tuple
|
|
127
|
+
const tupleSchema = z.tuple([z.string(), z.number()]);
|
|
128
|
+
const tupleResult = tupleSchema.safeParse(["abc", "not a number"]);
|
|
129
|
+
expect(tupleResult.success).toBe(false);
|
|
130
|
+
if (!tupleResult.success) {
|
|
131
|
+
expect(tupleResult.error.issues[0].message).toContain("Entrada inválida");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Test invalid_value with enum
|
|
135
|
+
const enumSchema = z.enum(["a", "b"]);
|
|
136
|
+
const enumResult = enumSchema.safeParse("c");
|
|
137
|
+
expect(enumResult.success).toBe(false);
|
|
138
|
+
if (!enumResult.success) {
|
|
139
|
+
expect(enumResult.error.issues[0].message).toBe('Opción inválida: se esperaba una de "a"|"b"');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Test not_multiple_of
|
|
143
|
+
const multipleSchema = z.number().multipleOf(3);
|
|
144
|
+
const multipleResult = multipleSchema.safeParse(10);
|
|
145
|
+
expect(multipleResult.success).toBe(false);
|
|
146
|
+
if (!multipleResult.success) {
|
|
147
|
+
expect(multipleResult.error.issues[0].message).toBe("Número inválido: debe ser múltiplo de 3");
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Test unrecognized_keys
|
|
151
|
+
const strictSchema = z.object({ a: z.string() }).strict();
|
|
152
|
+
const strictResult = strictSchema.safeParse({ a: "test", b: "extra" });
|
|
153
|
+
expect(strictResult.success).toBe(false);
|
|
154
|
+
if (!strictResult.success) {
|
|
155
|
+
expect(strictResult.error.issues[0].message).toBe('Llave desconocida: "b"');
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Test invalid_union
|
|
159
|
+
const unionSchema = z.union([z.string(), z.number()]);
|
|
160
|
+
const unionResult = unionSchema.safeParse(true);
|
|
161
|
+
expect(unionResult.success).toBe(false);
|
|
162
|
+
if (!unionResult.success) {
|
|
163
|
+
expect(unionResult.error.issues[0].message).toBe("Entrada inválida");
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Test invalid_format with regex
|
|
167
|
+
const regexSchema = z.string().regex(/^[a-z]+$/);
|
|
168
|
+
const regexResult = regexSchema.safeParse("ABC123");
|
|
169
|
+
expect(regexResult.success).toBe(false);
|
|
170
|
+
if (!regexResult.success) {
|
|
171
|
+
expect(regexResult.error.issues[0].message).toBe("Cadena inválida: debe coincidir con el patrón /^[a-z]+$/");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Test invalid_format with startsWith
|
|
175
|
+
const startsWithSchema = z.string().startsWith("hello");
|
|
176
|
+
const startsWithResult = startsWithSchema.safeParse("world");
|
|
177
|
+
expect(startsWithResult.success).toBe(false);
|
|
178
|
+
if (!startsWithResult.success) {
|
|
179
|
+
expect(startsWithResult.error.issues[0].message).toBe('Cadena inválida: debe comenzar con "hello"');
|
|
180
|
+
}
|
|
181
|
+
});
|
package/src/v4/locales/es.ts
CHANGED
|
@@ -10,27 +10,59 @@ const error: () => errors.$ZodErrorMap = () => {
|
|
|
10
10
|
set: { unit: "elementos", verb: "tener" },
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
const TypeNames: Record<string, string> = {
|
|
14
|
+
string: "texto",
|
|
15
|
+
number: "número",
|
|
16
|
+
boolean: "booleano",
|
|
17
|
+
array: "arreglo",
|
|
18
|
+
object: "objeto",
|
|
19
|
+
set: "conjunto",
|
|
20
|
+
file: "archivo",
|
|
21
|
+
date: "fecha",
|
|
22
|
+
bigint: "número grande",
|
|
23
|
+
symbol: "símbolo",
|
|
24
|
+
undefined: "indefinido",
|
|
25
|
+
null: "nulo",
|
|
26
|
+
function: "función",
|
|
27
|
+
map: "mapa",
|
|
28
|
+
record: "registro",
|
|
29
|
+
tuple: "tupla",
|
|
30
|
+
enum: "enumeración",
|
|
31
|
+
union: "unión",
|
|
32
|
+
literal: "literal",
|
|
33
|
+
promise: "promesa",
|
|
34
|
+
void: "vacío",
|
|
35
|
+
never: "nunca",
|
|
36
|
+
unknown: "desconocido",
|
|
37
|
+
any: "cualquiera",
|
|
38
|
+
};
|
|
39
|
+
|
|
13
40
|
function getSizing(origin: string): { unit: string; verb: string } | null {
|
|
14
41
|
return Sizable[origin] ?? null;
|
|
15
42
|
}
|
|
16
43
|
|
|
44
|
+
function getTypeName(type: string): string {
|
|
45
|
+
return TypeNames[type] ?? type;
|
|
46
|
+
}
|
|
47
|
+
|
|
17
48
|
const parsedType = (data: any): string => {
|
|
18
49
|
const t = typeof data;
|
|
19
50
|
|
|
20
51
|
switch (t) {
|
|
21
52
|
case "number": {
|
|
22
|
-
return Number.isNaN(data) ? "NaN" : "
|
|
53
|
+
return Number.isNaN(data) ? "NaN" : "number";
|
|
23
54
|
}
|
|
24
55
|
case "object": {
|
|
25
56
|
if (Array.isArray(data)) {
|
|
26
|
-
return "
|
|
57
|
+
return "array";
|
|
27
58
|
}
|
|
28
59
|
if (data === null) {
|
|
29
|
-
return "
|
|
60
|
+
return "null";
|
|
30
61
|
}
|
|
31
62
|
if (Object.getPrototypeOf(data) !== Object.prototype) {
|
|
32
63
|
return data.constructor.name;
|
|
33
64
|
}
|
|
65
|
+
return "object";
|
|
34
66
|
}
|
|
35
67
|
}
|
|
36
68
|
return t;
|
|
@@ -72,7 +104,7 @@ const error: () => errors.$ZodErrorMap = () => {
|
|
|
72
104
|
return (issue) => {
|
|
73
105
|
switch (issue.code) {
|
|
74
106
|
case "invalid_type":
|
|
75
|
-
return `Entrada inválida: se esperaba ${issue.expected}, recibido ${parsedType(issue.input)}`;
|
|
107
|
+
return `Entrada inválida: se esperaba ${getTypeName(issue.expected)}, recibido ${getTypeName(parsedType(issue.input))}`;
|
|
76
108
|
// return `Entrada inválida: se esperaba ${issue.expected}, recibido ${util.getParsedType(issue.input)}`;
|
|
77
109
|
case "invalid_value":
|
|
78
110
|
if (issue.values.length === 1)
|
|
@@ -81,18 +113,20 @@ const error: () => errors.$ZodErrorMap = () => {
|
|
|
81
113
|
case "too_big": {
|
|
82
114
|
const adj = issue.inclusive ? "<=" : "<";
|
|
83
115
|
const sizing = getSizing(issue.origin);
|
|
116
|
+
const origin = getTypeName(issue.origin);
|
|
84
117
|
if (sizing)
|
|
85
|
-
return `Demasiado grande: se esperaba que ${
|
|
86
|
-
return `Demasiado grande: se esperaba que ${
|
|
118
|
+
return `Demasiado grande: se esperaba que ${origin ?? "valor"} tuviera ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elementos"}`;
|
|
119
|
+
return `Demasiado grande: se esperaba que ${origin ?? "valor"} fuera ${adj}${issue.maximum.toString()}`;
|
|
87
120
|
}
|
|
88
121
|
case "too_small": {
|
|
89
122
|
const adj = issue.inclusive ? ">=" : ">";
|
|
90
123
|
const sizing = getSizing(issue.origin);
|
|
124
|
+
const origin = getTypeName(issue.origin);
|
|
91
125
|
if (sizing) {
|
|
92
|
-
return `Demasiado pequeño: se esperaba que ${
|
|
126
|
+
return `Demasiado pequeño: se esperaba que ${origin} tuviera ${adj}${issue.minimum.toString()} ${sizing.unit}`;
|
|
93
127
|
}
|
|
94
128
|
|
|
95
|
-
return `Demasiado pequeño: se esperaba que ${
|
|
129
|
+
return `Demasiado pequeño: se esperaba que ${origin} fuera ${adj}${issue.minimum.toString()}`;
|
|
96
130
|
}
|
|
97
131
|
case "invalid_format": {
|
|
98
132
|
const _issue = issue as errors.$ZodStringFormatIssues;
|
|
@@ -107,11 +141,11 @@ const error: () => errors.$ZodErrorMap = () => {
|
|
|
107
141
|
case "unrecognized_keys":
|
|
108
142
|
return `Llave${issue.keys.length > 1 ? "s" : ""} desconocida${issue.keys.length > 1 ? "s" : ""}: ${util.joinValues(issue.keys, ", ")}`;
|
|
109
143
|
case "invalid_key":
|
|
110
|
-
return `Llave inválida en ${issue.origin}`;
|
|
144
|
+
return `Llave inválida en ${getTypeName(issue.origin)}`;
|
|
111
145
|
case "invalid_union":
|
|
112
146
|
return "Entrada inválida";
|
|
113
147
|
case "invalid_element":
|
|
114
|
-
return `Valor inválido en ${issue.origin}`;
|
|
148
|
+
return `Valor inválido en ${getTypeName(issue.origin)}`;
|
|
115
149
|
default:
|
|
116
150
|
return `Entrada inválida`;
|
|
117
151
|
}
|
package/v4/locales/es.cjs
CHANGED
|
@@ -32,25 +32,55 @@ const error = () => {
|
|
|
32
32
|
array: { unit: "elementos", verb: "tener" },
|
|
33
33
|
set: { unit: "elementos", verb: "tener" },
|
|
34
34
|
};
|
|
35
|
+
const TypeNames = {
|
|
36
|
+
string: "texto",
|
|
37
|
+
number: "número",
|
|
38
|
+
boolean: "booleano",
|
|
39
|
+
array: "arreglo",
|
|
40
|
+
object: "objeto",
|
|
41
|
+
set: "conjunto",
|
|
42
|
+
file: "archivo",
|
|
43
|
+
date: "fecha",
|
|
44
|
+
bigint: "número grande",
|
|
45
|
+
symbol: "símbolo",
|
|
46
|
+
undefined: "indefinido",
|
|
47
|
+
null: "nulo",
|
|
48
|
+
function: "función",
|
|
49
|
+
map: "mapa",
|
|
50
|
+
record: "registro",
|
|
51
|
+
tuple: "tupla",
|
|
52
|
+
enum: "enumeración",
|
|
53
|
+
union: "unión",
|
|
54
|
+
literal: "literal",
|
|
55
|
+
promise: "promesa",
|
|
56
|
+
void: "vacío",
|
|
57
|
+
never: "nunca",
|
|
58
|
+
unknown: "desconocido",
|
|
59
|
+
any: "cualquiera",
|
|
60
|
+
};
|
|
35
61
|
function getSizing(origin) {
|
|
36
62
|
return Sizable[origin] ?? null;
|
|
37
63
|
}
|
|
64
|
+
function getTypeName(type) {
|
|
65
|
+
return TypeNames[type] ?? type;
|
|
66
|
+
}
|
|
38
67
|
const parsedType = (data) => {
|
|
39
68
|
const t = typeof data;
|
|
40
69
|
switch (t) {
|
|
41
70
|
case "number": {
|
|
42
|
-
return Number.isNaN(data) ? "NaN" : "
|
|
71
|
+
return Number.isNaN(data) ? "NaN" : "number";
|
|
43
72
|
}
|
|
44
73
|
case "object": {
|
|
45
74
|
if (Array.isArray(data)) {
|
|
46
|
-
return "
|
|
75
|
+
return "array";
|
|
47
76
|
}
|
|
48
77
|
if (data === null) {
|
|
49
|
-
return "
|
|
78
|
+
return "null";
|
|
50
79
|
}
|
|
51
80
|
if (Object.getPrototypeOf(data) !== Object.prototype) {
|
|
52
81
|
return data.constructor.name;
|
|
53
82
|
}
|
|
83
|
+
return "object";
|
|
54
84
|
}
|
|
55
85
|
}
|
|
56
86
|
return t;
|
|
@@ -88,7 +118,7 @@ const error = () => {
|
|
|
88
118
|
return (issue) => {
|
|
89
119
|
switch (issue.code) {
|
|
90
120
|
case "invalid_type":
|
|
91
|
-
return `Entrada inválida: se esperaba ${issue.expected}, recibido ${parsedType(issue.input)}`;
|
|
121
|
+
return `Entrada inválida: se esperaba ${getTypeName(issue.expected)}, recibido ${getTypeName(parsedType(issue.input))}`;
|
|
92
122
|
// return `Entrada inválida: se esperaba ${issue.expected}, recibido ${util.getParsedType(issue.input)}`;
|
|
93
123
|
case "invalid_value":
|
|
94
124
|
if (issue.values.length === 1)
|
|
@@ -97,17 +127,19 @@ const error = () => {
|
|
|
97
127
|
case "too_big": {
|
|
98
128
|
const adj = issue.inclusive ? "<=" : "<";
|
|
99
129
|
const sizing = getSizing(issue.origin);
|
|
130
|
+
const origin = getTypeName(issue.origin);
|
|
100
131
|
if (sizing)
|
|
101
|
-
return `Demasiado grande: se esperaba que ${
|
|
102
|
-
return `Demasiado grande: se esperaba que ${
|
|
132
|
+
return `Demasiado grande: se esperaba que ${origin ?? "valor"} tuviera ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elementos"}`;
|
|
133
|
+
return `Demasiado grande: se esperaba que ${origin ?? "valor"} fuera ${adj}${issue.maximum.toString()}`;
|
|
103
134
|
}
|
|
104
135
|
case "too_small": {
|
|
105
136
|
const adj = issue.inclusive ? ">=" : ">";
|
|
106
137
|
const sizing = getSizing(issue.origin);
|
|
138
|
+
const origin = getTypeName(issue.origin);
|
|
107
139
|
if (sizing) {
|
|
108
|
-
return `Demasiado pequeño: se esperaba que ${
|
|
140
|
+
return `Demasiado pequeño: se esperaba que ${origin} tuviera ${adj}${issue.minimum.toString()} ${sizing.unit}`;
|
|
109
141
|
}
|
|
110
|
-
return `Demasiado pequeño: se esperaba que ${
|
|
142
|
+
return `Demasiado pequeño: se esperaba que ${origin} fuera ${adj}${issue.minimum.toString()}`;
|
|
111
143
|
}
|
|
112
144
|
case "invalid_format": {
|
|
113
145
|
const _issue = issue;
|
|
@@ -126,11 +158,11 @@ const error = () => {
|
|
|
126
158
|
case "unrecognized_keys":
|
|
127
159
|
return `Llave${issue.keys.length > 1 ? "s" : ""} desconocida${issue.keys.length > 1 ? "s" : ""}: ${util.joinValues(issue.keys, ", ")}`;
|
|
128
160
|
case "invalid_key":
|
|
129
|
-
return `Llave inválida en ${issue.origin}`;
|
|
161
|
+
return `Llave inválida en ${getTypeName(issue.origin)}`;
|
|
130
162
|
case "invalid_union":
|
|
131
163
|
return "Entrada inválida";
|
|
132
164
|
case "invalid_element":
|
|
133
|
-
return `Valor inválido en ${issue.origin}`;
|
|
165
|
+
return `Valor inválido en ${getTypeName(issue.origin)}`;
|
|
134
166
|
default:
|
|
135
167
|
return `Entrada inválida`;
|
|
136
168
|
}
|
package/v4/locales/es.js
CHANGED
|
@@ -6,25 +6,55 @@ const error = () => {
|
|
|
6
6
|
array: { unit: "elementos", verb: "tener" },
|
|
7
7
|
set: { unit: "elementos", verb: "tener" },
|
|
8
8
|
};
|
|
9
|
+
const TypeNames = {
|
|
10
|
+
string: "texto",
|
|
11
|
+
number: "número",
|
|
12
|
+
boolean: "booleano",
|
|
13
|
+
array: "arreglo",
|
|
14
|
+
object: "objeto",
|
|
15
|
+
set: "conjunto",
|
|
16
|
+
file: "archivo",
|
|
17
|
+
date: "fecha",
|
|
18
|
+
bigint: "número grande",
|
|
19
|
+
symbol: "símbolo",
|
|
20
|
+
undefined: "indefinido",
|
|
21
|
+
null: "nulo",
|
|
22
|
+
function: "función",
|
|
23
|
+
map: "mapa",
|
|
24
|
+
record: "registro",
|
|
25
|
+
tuple: "tupla",
|
|
26
|
+
enum: "enumeración",
|
|
27
|
+
union: "unión",
|
|
28
|
+
literal: "literal",
|
|
29
|
+
promise: "promesa",
|
|
30
|
+
void: "vacío",
|
|
31
|
+
never: "nunca",
|
|
32
|
+
unknown: "desconocido",
|
|
33
|
+
any: "cualquiera",
|
|
34
|
+
};
|
|
9
35
|
function getSizing(origin) {
|
|
10
36
|
return Sizable[origin] ?? null;
|
|
11
37
|
}
|
|
38
|
+
function getTypeName(type) {
|
|
39
|
+
return TypeNames[type] ?? type;
|
|
40
|
+
}
|
|
12
41
|
const parsedType = (data) => {
|
|
13
42
|
const t = typeof data;
|
|
14
43
|
switch (t) {
|
|
15
44
|
case "number": {
|
|
16
|
-
return Number.isNaN(data) ? "NaN" : "
|
|
45
|
+
return Number.isNaN(data) ? "NaN" : "number";
|
|
17
46
|
}
|
|
18
47
|
case "object": {
|
|
19
48
|
if (Array.isArray(data)) {
|
|
20
|
-
return "
|
|
49
|
+
return "array";
|
|
21
50
|
}
|
|
22
51
|
if (data === null) {
|
|
23
|
-
return "
|
|
52
|
+
return "null";
|
|
24
53
|
}
|
|
25
54
|
if (Object.getPrototypeOf(data) !== Object.prototype) {
|
|
26
55
|
return data.constructor.name;
|
|
27
56
|
}
|
|
57
|
+
return "object";
|
|
28
58
|
}
|
|
29
59
|
}
|
|
30
60
|
return t;
|
|
@@ -62,7 +92,7 @@ const error = () => {
|
|
|
62
92
|
return (issue) => {
|
|
63
93
|
switch (issue.code) {
|
|
64
94
|
case "invalid_type":
|
|
65
|
-
return `Entrada inválida: se esperaba ${issue.expected}, recibido ${parsedType(issue.input)}`;
|
|
95
|
+
return `Entrada inválida: se esperaba ${getTypeName(issue.expected)}, recibido ${getTypeName(parsedType(issue.input))}`;
|
|
66
96
|
// return `Entrada inválida: se esperaba ${issue.expected}, recibido ${util.getParsedType(issue.input)}`;
|
|
67
97
|
case "invalid_value":
|
|
68
98
|
if (issue.values.length === 1)
|
|
@@ -71,17 +101,19 @@ const error = () => {
|
|
|
71
101
|
case "too_big": {
|
|
72
102
|
const adj = issue.inclusive ? "<=" : "<";
|
|
73
103
|
const sizing = getSizing(issue.origin);
|
|
104
|
+
const origin = getTypeName(issue.origin);
|
|
74
105
|
if (sizing)
|
|
75
|
-
return `Demasiado grande: se esperaba que ${
|
|
76
|
-
return `Demasiado grande: se esperaba que ${
|
|
106
|
+
return `Demasiado grande: se esperaba que ${origin ?? "valor"} tuviera ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elementos"}`;
|
|
107
|
+
return `Demasiado grande: se esperaba que ${origin ?? "valor"} fuera ${adj}${issue.maximum.toString()}`;
|
|
77
108
|
}
|
|
78
109
|
case "too_small": {
|
|
79
110
|
const adj = issue.inclusive ? ">=" : ">";
|
|
80
111
|
const sizing = getSizing(issue.origin);
|
|
112
|
+
const origin = getTypeName(issue.origin);
|
|
81
113
|
if (sizing) {
|
|
82
|
-
return `Demasiado pequeño: se esperaba que ${
|
|
114
|
+
return `Demasiado pequeño: se esperaba que ${origin} tuviera ${adj}${issue.minimum.toString()} ${sizing.unit}`;
|
|
83
115
|
}
|
|
84
|
-
return `Demasiado pequeño: se esperaba que ${
|
|
116
|
+
return `Demasiado pequeño: se esperaba que ${origin} fuera ${adj}${issue.minimum.toString()}`;
|
|
85
117
|
}
|
|
86
118
|
case "invalid_format": {
|
|
87
119
|
const _issue = issue;
|
|
@@ -100,11 +132,11 @@ const error = () => {
|
|
|
100
132
|
case "unrecognized_keys":
|
|
101
133
|
return `Llave${issue.keys.length > 1 ? "s" : ""} desconocida${issue.keys.length > 1 ? "s" : ""}: ${util.joinValues(issue.keys, ", ")}`;
|
|
102
134
|
case "invalid_key":
|
|
103
|
-
return `Llave inválida en ${issue.origin}`;
|
|
135
|
+
return `Llave inválida en ${getTypeName(issue.origin)}`;
|
|
104
136
|
case "invalid_union":
|
|
105
137
|
return "Entrada inválida";
|
|
106
138
|
case "invalid_element":
|
|
107
|
-
return `Valor inválido en ${issue.origin}`;
|
|
139
|
+
return `Valor inválido en ${getTypeName(issue.origin)}`;
|
|
108
140
|
default:
|
|
109
141
|
return `Entrada inválida`;
|
|
110
142
|
}
|