zod 4.1.0-canary.20250711T201420 → 4.1.0-canary.20250723T215716
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 +1 -1
- package/src/v4/locales/bg.ts +136 -0
- package/src/v4/locales/da.ts +141 -0
- package/src/v4/locales/index.ts +2 -0
- package/src/v4/locales/is.ts +127 -0
- package/v4/locales/bg.cjs +156 -0
- package/v4/locales/bg.d.cts +5 -0
- package/v4/locales/bg.d.ts +5 -0
- package/v4/locales/bg.js +128 -0
- package/v4/locales/da.cjs +157 -0
- package/v4/locales/da.d.cts +4 -0
- package/v4/locales/da.d.ts +4 -0
- package/v4/locales/da.js +131 -0
- package/v4/locales/index.cjs +5 -1
- package/v4/locales/index.d.cts +2 -0
- package/v4/locales/index.d.ts +2 -0
- package/v4/locales/index.js +2 -0
- package/v4/locales/is.cjs +145 -0
- package/v4/locales/is.d.cts +5 -0
- package/v4/locales/is.d.ts +5 -0
- package/v4/locales/is.js +117 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zod",
|
|
3
|
-
"version": "4.1.0-canary.
|
|
3
|
+
"version": "4.1.0-canary.20250723T215716",
|
|
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",
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { $ZodStringFormats } from "../core/checks.js";
|
|
2
|
+
import type * as errors from "../core/errors.js";
|
|
3
|
+
import * as util from "../core/util.js";
|
|
4
|
+
|
|
5
|
+
export const parsedType = (data: any): string => {
|
|
6
|
+
const t = typeof data;
|
|
7
|
+
|
|
8
|
+
switch (t) {
|
|
9
|
+
case "number": {
|
|
10
|
+
return Number.isNaN(data) ? "NaN" : "число";
|
|
11
|
+
}
|
|
12
|
+
case "object": {
|
|
13
|
+
if (Array.isArray(data)) {
|
|
14
|
+
return "масив";
|
|
15
|
+
}
|
|
16
|
+
if (data === null) {
|
|
17
|
+
return "null";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (Object.getPrototypeOf(data) !== Object.prototype && data.constructor) {
|
|
21
|
+
return data.constructor.name;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return t;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const error: () => errors.$ZodErrorMap = () => {
|
|
29
|
+
const Sizable: Record<string, { unit: string; verb: string }> = {
|
|
30
|
+
string: { unit: "символа", verb: "да съдържа" },
|
|
31
|
+
file: { unit: "байта", verb: "да съдържа" },
|
|
32
|
+
array: { unit: "елемента", verb: "да съдържа" },
|
|
33
|
+
set: { unit: "елемента", verb: "да съдържа" },
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
function getSizing(origin: string): { unit: string; verb: string } | null {
|
|
37
|
+
return Sizable[origin] ?? null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const Nouns: {
|
|
41
|
+
[k in $ZodStringFormats | (string & {})]?: string;
|
|
42
|
+
} = {
|
|
43
|
+
regex: "вход",
|
|
44
|
+
email: "имейл адрес",
|
|
45
|
+
url: "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: "base64-кодиран низ",
|
|
66
|
+
base64url: "base64url-кодиран низ",
|
|
67
|
+
json_string: "JSON низ",
|
|
68
|
+
e164: "E.164 номер",
|
|
69
|
+
jwt: "JWT",
|
|
70
|
+
template_literal: "вход",
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
return (issue) => {
|
|
74
|
+
switch (issue.code) {
|
|
75
|
+
case "invalid_type":
|
|
76
|
+
return `Невалиден вход: очакван ${issue.expected}, получен ${parsedType(issue.input)}`;
|
|
77
|
+
|
|
78
|
+
case "invalid_value":
|
|
79
|
+
if (issue.values.length === 1) return `Невалиден вход: очакван ${util.stringifyPrimitive(issue.values[0])}`;
|
|
80
|
+
return `Невалидна опция: очаквано едно от ${util.joinValues(issue.values, "|")}`;
|
|
81
|
+
case "too_big": {
|
|
82
|
+
const adj = issue.inclusive ? "<=" : "<";
|
|
83
|
+
const sizing = getSizing(issue.origin);
|
|
84
|
+
if (sizing)
|
|
85
|
+
return `Твърде голямо: очаква се ${issue.origin ?? "стойност"} да съдържа ${adj}${issue.maximum.toString()} ${sizing.unit ?? "елемента"}`;
|
|
86
|
+
return `Твърде голямо: очаква се ${issue.origin ?? "стойност"} да бъде ${adj}${issue.maximum.toString()}`;
|
|
87
|
+
}
|
|
88
|
+
case "too_small": {
|
|
89
|
+
const adj = issue.inclusive ? ">=" : ">";
|
|
90
|
+
const sizing = getSizing(issue.origin);
|
|
91
|
+
if (sizing) {
|
|
92
|
+
return `Твърде малко: очаква се ${issue.origin} да съдържа ${adj}${issue.minimum.toString()} ${sizing.unit}`;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return `Твърде малко: очаква се ${issue.origin} да бъде ${adj}${issue.minimum.toString()}`;
|
|
96
|
+
}
|
|
97
|
+
case "invalid_format": {
|
|
98
|
+
const _issue = issue as errors.$ZodStringFormatIssues;
|
|
99
|
+
if (_issue.format === "starts_with") {
|
|
100
|
+
return `Невалиден низ: трябва да започва с "${_issue.prefix}"`;
|
|
101
|
+
}
|
|
102
|
+
if (_issue.format === "ends_with") return `Невалиден низ: трябва да завършва с "${_issue.suffix}"`;
|
|
103
|
+
if (_issue.format === "includes") return `Невалиден низ: трябва да включва "${_issue.includes}"`;
|
|
104
|
+
if (_issue.format === "regex") return `Невалиден низ: трябва да съвпада с ${_issue.pattern}`;
|
|
105
|
+
|
|
106
|
+
let invalid_adj = "Невалиден";
|
|
107
|
+
|
|
108
|
+
if (_issue.format === "emoji") invalid_adj = "Невалидно";
|
|
109
|
+
if (_issue.format === "datetime") invalid_adj = "Невалидно";
|
|
110
|
+
if (_issue.format === "date") invalid_adj = "Невалидна";
|
|
111
|
+
if (_issue.format === "time") invalid_adj = "Невалидно";
|
|
112
|
+
if (_issue.format === "duration") invalid_adj = "Невалидна";
|
|
113
|
+
|
|
114
|
+
return `${invalid_adj} ${Nouns[_issue.format] ?? issue.format}`;
|
|
115
|
+
}
|
|
116
|
+
case "not_multiple_of":
|
|
117
|
+
return `Невалидно число: трябва да бъде кратно на ${issue.divisor}`;
|
|
118
|
+
case "unrecognized_keys":
|
|
119
|
+
return `Неразпознат${issue.keys.length > 1 ? "и" : ""} ключ${issue.keys.length > 1 ? "ове" : ""}: ${util.joinValues(issue.keys, ", ")}`;
|
|
120
|
+
case "invalid_key":
|
|
121
|
+
return `Невалиден ключ в ${issue.origin}`;
|
|
122
|
+
case "invalid_union":
|
|
123
|
+
return "Невалиден вход";
|
|
124
|
+
case "invalid_element":
|
|
125
|
+
return `Невалидна стойност в ${issue.origin}`;
|
|
126
|
+
default:
|
|
127
|
+
return `Невалиден вход`;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export default function (): { localeError: errors.$ZodErrorMap } {
|
|
133
|
+
return {
|
|
134
|
+
localeError: error(),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import type { $ZodStringFormats } from "../core/checks.js";
|
|
2
|
+
import type * as errors from "../core/errors.js";
|
|
3
|
+
import * as util from "../core/util.js";
|
|
4
|
+
|
|
5
|
+
const error: () => errors.$ZodErrorMap = () => {
|
|
6
|
+
const Sizable: Record<string, { unit: string; verb: string }> = {
|
|
7
|
+
string: { unit: "tegn", verb: "havde" },
|
|
8
|
+
file: { unit: "bytes", verb: "havde" },
|
|
9
|
+
array: { unit: "elementer", verb: "indeholdt" },
|
|
10
|
+
set: { unit: "elementer", verb: "indeholdt" },
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const TypeNames: Record<string, string> = {
|
|
14
|
+
string: "streng",
|
|
15
|
+
number: "tal",
|
|
16
|
+
boolean: "boolean",
|
|
17
|
+
array: "liste",
|
|
18
|
+
object: "objekt",
|
|
19
|
+
set: "sæt",
|
|
20
|
+
file: "fil",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function getSizing(origin: string): { unit: string; verb: string } | null {
|
|
24
|
+
return Sizable[origin] ?? null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function getTypeName(type: string): string {
|
|
28
|
+
return TypeNames[type] ?? type;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const parsedType = (data: any): string => {
|
|
32
|
+
const t = typeof data;
|
|
33
|
+
|
|
34
|
+
switch (t) {
|
|
35
|
+
case "number": {
|
|
36
|
+
return Number.isNaN(data) ? "NaN" : "tal";
|
|
37
|
+
}
|
|
38
|
+
case "object": {
|
|
39
|
+
if (Array.isArray(data)) {
|
|
40
|
+
return "liste";
|
|
41
|
+
}
|
|
42
|
+
if (data === null) {
|
|
43
|
+
return "null";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (Object.getPrototypeOf(data) !== Object.prototype && data.constructor) {
|
|
47
|
+
return data.constructor.name;
|
|
48
|
+
}
|
|
49
|
+
return "objekt";
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return t;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const Nouns: {
|
|
56
|
+
[k in $ZodStringFormats | (string & {})]?: string;
|
|
57
|
+
} = {
|
|
58
|
+
regex: "input",
|
|
59
|
+
email: "e-mailadresse",
|
|
60
|
+
url: "URL",
|
|
61
|
+
emoji: "emoji",
|
|
62
|
+
uuid: "UUID",
|
|
63
|
+
uuidv4: "UUIDv4",
|
|
64
|
+
uuidv6: "UUIDv6",
|
|
65
|
+
nanoid: "nanoid",
|
|
66
|
+
guid: "GUID",
|
|
67
|
+
cuid: "cuid",
|
|
68
|
+
cuid2: "cuid2",
|
|
69
|
+
ulid: "ULID",
|
|
70
|
+
xid: "XID",
|
|
71
|
+
ksuid: "KSUID",
|
|
72
|
+
datetime: "ISO dato- og klokkeslæt",
|
|
73
|
+
date: "ISO-dato",
|
|
74
|
+
time: "ISO-klokkeslæt",
|
|
75
|
+
duration: "ISO-varighed",
|
|
76
|
+
ipv4: "IPv4-område",
|
|
77
|
+
ipv6: "IPv6-område",
|
|
78
|
+
cidrv4: "IPv4-spektrum",
|
|
79
|
+
cidrv6: "IPv6-spektrum",
|
|
80
|
+
base64: "base64-kodet streng",
|
|
81
|
+
base64url: "base64url-kodet streng",
|
|
82
|
+
json_string: "JSON-streng",
|
|
83
|
+
e164: "E.164-nummer",
|
|
84
|
+
jwt: "JWT",
|
|
85
|
+
template_literal: "input",
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
return (issue) => {
|
|
89
|
+
switch (issue.code) {
|
|
90
|
+
case "invalid_type":
|
|
91
|
+
return `Ugyldigt input: forventede ${getTypeName(issue.expected)}, fik ${getTypeName(parsedType(issue.input))}`;
|
|
92
|
+
case "invalid_value":
|
|
93
|
+
if (issue.values.length === 1) return `Ugyldig værdi: forventede ${util.stringifyPrimitive(issue.values[0])}`;
|
|
94
|
+
return `Ugyldigt valg: forventede en af følgende ${util.joinValues(issue.values, "|")}`;
|
|
95
|
+
case "too_big": {
|
|
96
|
+
const adj = issue.inclusive ? "<=" : "<";
|
|
97
|
+
const sizing = getSizing(issue.origin);
|
|
98
|
+
const origin = getTypeName(issue.origin);
|
|
99
|
+
if (sizing)
|
|
100
|
+
return `For stor: forventede ${origin ?? "value"} ${sizing.verb} ${adj} ${issue.maximum.toString()} ${sizing.unit ?? "elementer"}`;
|
|
101
|
+
return `For stor: forventede ${origin ?? "value"} havde ${adj} ${issue.maximum.toString()}`;
|
|
102
|
+
}
|
|
103
|
+
case "too_small": {
|
|
104
|
+
const adj = issue.inclusive ? ">=" : ">";
|
|
105
|
+
const sizing = getSizing(issue.origin);
|
|
106
|
+
const origin = getTypeName(issue.origin);
|
|
107
|
+
if (sizing) {
|
|
108
|
+
return `For lille: forventede ${origin} ${sizing.verb} ${adj} ${issue.minimum.toString()} ${sizing.unit}`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return `For lille: forventede ${origin} havde ${adj} ${issue.minimum.toString()}`;
|
|
112
|
+
}
|
|
113
|
+
case "invalid_format": {
|
|
114
|
+
const _issue = issue as errors.$ZodStringFormatIssues;
|
|
115
|
+
if (_issue.format === "starts_with") return `Ugyldig streng: skal starte med "${_issue.prefix}"`;
|
|
116
|
+
if (_issue.format === "ends_with") return `Ugyldig streng: skal ende med "${_issue.suffix}"`;
|
|
117
|
+
if (_issue.format === "includes") return `Ugyldig streng: skal indeholde "${_issue.includes}"`;
|
|
118
|
+
if (_issue.format === "regex") return `Ugyldig streng: skal matche mønsteret ${_issue.pattern}`;
|
|
119
|
+
return `Ugyldig ${Nouns[_issue.format] ?? issue.format}`;
|
|
120
|
+
}
|
|
121
|
+
case "not_multiple_of":
|
|
122
|
+
return `Ugyldigt tal: skal være deleligt med ${issue.divisor}`;
|
|
123
|
+
case "unrecognized_keys":
|
|
124
|
+
return `${issue.keys.length > 1 ? "Ukendte nøgler" : "Ukendt nøgle"}: ${util.joinValues(issue.keys, ", ")}`;
|
|
125
|
+
case "invalid_key":
|
|
126
|
+
return `Ugyldig nøgle i ${issue.origin}`;
|
|
127
|
+
case "invalid_union":
|
|
128
|
+
return "Ugyldigt input: matcher ingen af de tilladte typer";
|
|
129
|
+
case "invalid_element":
|
|
130
|
+
return `Ugyldig værdi i ${issue.origin}`;
|
|
131
|
+
default:
|
|
132
|
+
return `Ugyldigt input`;
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export default function (): { localeError: errors.$ZodErrorMap } {
|
|
138
|
+
return {
|
|
139
|
+
localeError: error(),
|
|
140
|
+
};
|
|
141
|
+
}
|
package/src/v4/locales/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { default as az } from "./az.js";
|
|
|
3
3
|
export { default as be } from "./be.js";
|
|
4
4
|
export { default as ca } from "./ca.js";
|
|
5
5
|
export { default as cs } from "./cs.js";
|
|
6
|
+
export { default as da } from "./da.js";
|
|
6
7
|
export { default as de } from "./de.js";
|
|
7
8
|
export { default as en } from "./en.js";
|
|
8
9
|
export { default as eo } from "./eo.js";
|
|
@@ -14,6 +15,7 @@ export { default as frCA } from "./fr-CA.js";
|
|
|
14
15
|
export { default as he } from "./he.js";
|
|
15
16
|
export { default as hu } from "./hu.js";
|
|
16
17
|
export { default as id } from "./id.js";
|
|
18
|
+
export { default as is } from "./is.js";
|
|
17
19
|
export { default as it } from "./it.js";
|
|
18
20
|
export { default as ja } from "./ja.js";
|
|
19
21
|
export { default as kh } from "./kh.js";
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { $ZodStringFormats } from "../core/checks.js";
|
|
2
|
+
import type * as errors from "../core/errors.js";
|
|
3
|
+
import * as util from "../core/util.js";
|
|
4
|
+
|
|
5
|
+
export const parsedType = (data: any): string => {
|
|
6
|
+
const t = typeof data;
|
|
7
|
+
|
|
8
|
+
switch (t) {
|
|
9
|
+
case "number": {
|
|
10
|
+
return Number.isNaN(data) ? "NaN" : "númer";
|
|
11
|
+
}
|
|
12
|
+
case "object": {
|
|
13
|
+
if (Array.isArray(data)) {
|
|
14
|
+
return "fylki";
|
|
15
|
+
}
|
|
16
|
+
if (data === null) {
|
|
17
|
+
return "null";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (Object.getPrototypeOf(data) !== Object.prototype && data.constructor) {
|
|
21
|
+
return data.constructor.name;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return t;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const error: () => errors.$ZodErrorMap = () => {
|
|
29
|
+
const Sizable: Record<string, { unit: string; verb: string }> = {
|
|
30
|
+
string: { unit: "stafi", verb: "að hafa" },
|
|
31
|
+
file: { unit: "bæti", verb: "að hafa" },
|
|
32
|
+
array: { unit: "hluti", verb: "að hafa" },
|
|
33
|
+
set: { unit: "hluti", verb: "að hafa" },
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
function getSizing(origin: string): { unit: string; verb: string } | null {
|
|
37
|
+
return Sizable[origin] ?? null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const Nouns: {
|
|
41
|
+
[k in $ZodStringFormats | (string & {})]?: string;
|
|
42
|
+
} = {
|
|
43
|
+
regex: "gildi",
|
|
44
|
+
email: "netfang",
|
|
45
|
+
url: "vefslóð",
|
|
46
|
+
emoji: "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 dagsetning og tími",
|
|
58
|
+
date: "ISO dagsetning",
|
|
59
|
+
time: "ISO tími",
|
|
60
|
+
duration: "ISO tímalengd",
|
|
61
|
+
ipv4: "IPv4 address",
|
|
62
|
+
ipv6: "IPv6 address",
|
|
63
|
+
cidrv4: "IPv4 range",
|
|
64
|
+
cidrv6: "IPv6 range",
|
|
65
|
+
base64: "base64-encoded strengur",
|
|
66
|
+
base64url: "base64url-encoded strengur",
|
|
67
|
+
json_string: "JSON strengur",
|
|
68
|
+
e164: "E.164 tölugildi",
|
|
69
|
+
jwt: "JWT",
|
|
70
|
+
template_literal: "gildi",
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
return (issue) => {
|
|
74
|
+
switch (issue.code) {
|
|
75
|
+
case "invalid_type":
|
|
76
|
+
return `Rangt gildi: Þú slóst inn ${parsedType(issue.input)} þar sem á að vera ${issue.expected}`;
|
|
77
|
+
|
|
78
|
+
case "invalid_value":
|
|
79
|
+
if (issue.values.length === 1) return `Rangt gildi: gert ráð fyrir ${util.stringifyPrimitive(issue.values[0])}`;
|
|
80
|
+
return `Ógilt val: má vera eitt af eftirfarandi ${util.joinValues(issue.values, "|")}`;
|
|
81
|
+
case "too_big": {
|
|
82
|
+
const adj = issue.inclusive ? "<=" : "<";
|
|
83
|
+
const sizing = getSizing(issue.origin);
|
|
84
|
+
if (sizing)
|
|
85
|
+
return `Of stórt: gert er ráð fyrir að ${issue.origin ?? "gildi"} hafi ${adj}${issue.maximum.toString()} ${sizing.unit ?? "hluti"}`;
|
|
86
|
+
return `Of stórt: gert er ráð fyrir að ${issue.origin ?? "gildi"} sé ${adj}${issue.maximum.toString()}`;
|
|
87
|
+
}
|
|
88
|
+
case "too_small": {
|
|
89
|
+
const adj = issue.inclusive ? ">=" : ">";
|
|
90
|
+
const sizing = getSizing(issue.origin);
|
|
91
|
+
if (sizing) {
|
|
92
|
+
return `Of lítið: gert er ráð fyrir að ${issue.origin} hafi ${adj}${issue.minimum.toString()} ${sizing.unit}`;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return `Of lítið: gert er ráð fyrir að ${issue.origin} sé ${adj}${issue.minimum.toString()}`;
|
|
96
|
+
}
|
|
97
|
+
case "invalid_format": {
|
|
98
|
+
const _issue = issue as errors.$ZodStringFormatIssues;
|
|
99
|
+
if (_issue.format === "starts_with") {
|
|
100
|
+
return `Ógildur strengur: verður að byrja á "${_issue.prefix}"`;
|
|
101
|
+
}
|
|
102
|
+
if (_issue.format === "ends_with") return `Ógildur strengur: verður að enda á "${_issue.suffix}"`;
|
|
103
|
+
if (_issue.format === "includes") return `Ógildur strengur: verður að innihalda "${_issue.includes}"`;
|
|
104
|
+
if (_issue.format === "regex") return `Ógildur strengur: verður að fylgja mynstri ${_issue.pattern}`;
|
|
105
|
+
return `Rangt ${Nouns[_issue.format] ?? issue.format}`;
|
|
106
|
+
}
|
|
107
|
+
case "not_multiple_of":
|
|
108
|
+
return `Röng tala: verður að vera margfeldi af ${issue.divisor}`;
|
|
109
|
+
case "unrecognized_keys":
|
|
110
|
+
return `Óþekkt ${issue.keys.length > 1 ? "ir lyklar" : "ur lykill"}: ${util.joinValues(issue.keys, ", ")}`;
|
|
111
|
+
case "invalid_key":
|
|
112
|
+
return `Rangur lykill í ${issue.origin}`;
|
|
113
|
+
case "invalid_union":
|
|
114
|
+
return "Rangt gildi";
|
|
115
|
+
case "invalid_element":
|
|
116
|
+
return `Rangt gildi í ${issue.origin}`;
|
|
117
|
+
default:
|
|
118
|
+
return `Rangt gildi`;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export default function (): { localeError: errors.$ZodErrorMap } {
|
|
124
|
+
return {
|
|
125
|
+
localeError: error(),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.parsedType = void 0;
|
|
27
|
+
exports.default = default_1;
|
|
28
|
+
const util = __importStar(require("../core/util.cjs"));
|
|
29
|
+
const parsedType = (data) => {
|
|
30
|
+
const t = typeof data;
|
|
31
|
+
switch (t) {
|
|
32
|
+
case "number": {
|
|
33
|
+
return Number.isNaN(data) ? "NaN" : "число";
|
|
34
|
+
}
|
|
35
|
+
case "object": {
|
|
36
|
+
if (Array.isArray(data)) {
|
|
37
|
+
return "масив";
|
|
38
|
+
}
|
|
39
|
+
if (data === null) {
|
|
40
|
+
return "null";
|
|
41
|
+
}
|
|
42
|
+
if (Object.getPrototypeOf(data) !== Object.prototype && data.constructor) {
|
|
43
|
+
return data.constructor.name;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return t;
|
|
48
|
+
};
|
|
49
|
+
exports.parsedType = parsedType;
|
|
50
|
+
const error = () => {
|
|
51
|
+
const Sizable = {
|
|
52
|
+
string: { unit: "символа", verb: "да съдържа" },
|
|
53
|
+
file: { unit: "байта", verb: "да съдържа" },
|
|
54
|
+
array: { unit: "елемента", verb: "да съдържа" },
|
|
55
|
+
set: { unit: "елемента", verb: "да съдържа" },
|
|
56
|
+
};
|
|
57
|
+
function getSizing(origin) {
|
|
58
|
+
return Sizable[origin] ?? null;
|
|
59
|
+
}
|
|
60
|
+
const Nouns = {
|
|
61
|
+
regex: "вход",
|
|
62
|
+
email: "имейл адрес",
|
|
63
|
+
url: "URL",
|
|
64
|
+
emoji: "емоджи",
|
|
65
|
+
uuid: "UUID",
|
|
66
|
+
uuidv4: "UUIDv4",
|
|
67
|
+
uuidv6: "UUIDv6",
|
|
68
|
+
nanoid: "nanoid",
|
|
69
|
+
guid: "GUID",
|
|
70
|
+
cuid: "cuid",
|
|
71
|
+
cuid2: "cuid2",
|
|
72
|
+
ulid: "ULID",
|
|
73
|
+
xid: "XID",
|
|
74
|
+
ksuid: "KSUID",
|
|
75
|
+
datetime: "ISO време",
|
|
76
|
+
date: "ISO дата",
|
|
77
|
+
time: "ISO време",
|
|
78
|
+
duration: "ISO продължителност",
|
|
79
|
+
ipv4: "IPv4 адрес",
|
|
80
|
+
ipv6: "IPv6 адрес",
|
|
81
|
+
cidrv4: "IPv4 диапазон",
|
|
82
|
+
cidrv6: "IPv6 диапазон",
|
|
83
|
+
base64: "base64-кодиран низ",
|
|
84
|
+
base64url: "base64url-кодиран низ",
|
|
85
|
+
json_string: "JSON низ",
|
|
86
|
+
e164: "E.164 номер",
|
|
87
|
+
jwt: "JWT",
|
|
88
|
+
template_literal: "вход",
|
|
89
|
+
};
|
|
90
|
+
return (issue) => {
|
|
91
|
+
switch (issue.code) {
|
|
92
|
+
case "invalid_type":
|
|
93
|
+
return `Невалиден вход: очакван ${issue.expected}, получен ${(0, exports.parsedType)(issue.input)}`;
|
|
94
|
+
case "invalid_value":
|
|
95
|
+
if (issue.values.length === 1)
|
|
96
|
+
return `Невалиден вход: очакван ${util.stringifyPrimitive(issue.values[0])}`;
|
|
97
|
+
return `Невалидна опция: очаквано едно от ${util.joinValues(issue.values, "|")}`;
|
|
98
|
+
case "too_big": {
|
|
99
|
+
const adj = issue.inclusive ? "<=" : "<";
|
|
100
|
+
const sizing = getSizing(issue.origin);
|
|
101
|
+
if (sizing)
|
|
102
|
+
return `Твърде голямо: очаква се ${issue.origin ?? "стойност"} да съдържа ${adj}${issue.maximum.toString()} ${sizing.unit ?? "елемента"}`;
|
|
103
|
+
return `Твърде голямо: очаква се ${issue.origin ?? "стойност"} да бъде ${adj}${issue.maximum.toString()}`;
|
|
104
|
+
}
|
|
105
|
+
case "too_small": {
|
|
106
|
+
const adj = issue.inclusive ? ">=" : ">";
|
|
107
|
+
const sizing = getSizing(issue.origin);
|
|
108
|
+
if (sizing) {
|
|
109
|
+
return `Твърде малко: очаква се ${issue.origin} да съдържа ${adj}${issue.minimum.toString()} ${sizing.unit}`;
|
|
110
|
+
}
|
|
111
|
+
return `Твърде малко: очаква се ${issue.origin} да бъде ${adj}${issue.minimum.toString()}`;
|
|
112
|
+
}
|
|
113
|
+
case "invalid_format": {
|
|
114
|
+
const _issue = issue;
|
|
115
|
+
if (_issue.format === "starts_with") {
|
|
116
|
+
return `Невалиден низ: трябва да започва с "${_issue.prefix}"`;
|
|
117
|
+
}
|
|
118
|
+
if (_issue.format === "ends_with")
|
|
119
|
+
return `Невалиден низ: трябва да завършва с "${_issue.suffix}"`;
|
|
120
|
+
if (_issue.format === "includes")
|
|
121
|
+
return `Невалиден низ: трябва да включва "${_issue.includes}"`;
|
|
122
|
+
if (_issue.format === "regex")
|
|
123
|
+
return `Невалиден низ: трябва да съвпада с ${_issue.pattern}`;
|
|
124
|
+
let invalid_adj = "Невалиден";
|
|
125
|
+
if (_issue.format === "emoji")
|
|
126
|
+
invalid_adj = "Невалидно";
|
|
127
|
+
if (_issue.format === "datetime")
|
|
128
|
+
invalid_adj = "Невалидно";
|
|
129
|
+
if (_issue.format === "date")
|
|
130
|
+
invalid_adj = "Невалидна";
|
|
131
|
+
if (_issue.format === "time")
|
|
132
|
+
invalid_adj = "Невалидно";
|
|
133
|
+
if (_issue.format === "duration")
|
|
134
|
+
invalid_adj = "Невалидна";
|
|
135
|
+
return `${invalid_adj} ${Nouns[_issue.format] ?? issue.format}`;
|
|
136
|
+
}
|
|
137
|
+
case "not_multiple_of":
|
|
138
|
+
return `Невалидно число: трябва да бъде кратно на ${issue.divisor}`;
|
|
139
|
+
case "unrecognized_keys":
|
|
140
|
+
return `Неразпознат${issue.keys.length > 1 ? "и" : ""} ключ${issue.keys.length > 1 ? "ове" : ""}: ${util.joinValues(issue.keys, ", ")}`;
|
|
141
|
+
case "invalid_key":
|
|
142
|
+
return `Невалиден ключ в ${issue.origin}`;
|
|
143
|
+
case "invalid_union":
|
|
144
|
+
return "Невалиден вход";
|
|
145
|
+
case "invalid_element":
|
|
146
|
+
return `Невалидна стойност в ${issue.origin}`;
|
|
147
|
+
default:
|
|
148
|
+
return `Невалиден вход`;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
function default_1() {
|
|
153
|
+
return {
|
|
154
|
+
localeError: error(),
|
|
155
|
+
};
|
|
156
|
+
}
|