zod 4.1.6 → 4.1.7
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/classic/tests/default.test.ts +8 -0
- package/src/v4/classic/tests/string.test.ts +3 -0
- package/src/v4/classic/tests/template-literal.test.ts +10 -8
- package/src/v4/classic/tests/to-json-schema.test.ts +2 -2
- package/src/v4/core/regexes.ts +9 -9
- package/src/v4/core/schemas.ts +4 -2
- package/src/v4/core/tests/locales/es.test.ts +181 -0
- package/src/v4/core/util.ts +1 -0
- package/src/v4/core/versions.ts +1 -1
- package/src/v4/locales/es.ts +44 -10
- package/src/v4/locales/index.ts +4 -0
- package/src/v4/locales/ka.ts +138 -0
- package/src/v4/locales/kh.ts +3 -122
- package/src/v4/locales/km.ts +126 -0
- package/src/v4/locales/lt.ts +265 -0
- package/src/v4/locales/ua.ts +3 -122
- package/src/v4/locales/uk.ts +126 -0
- package/v4/core/regexes.cjs +9 -9
- package/v4/core/regexes.js +9 -9
- package/v4/core/schemas.cjs +5 -2
- package/v4/core/schemas.js +5 -2
- package/v4/core/util.cjs +2 -0
- package/v4/core/util.js +2 -0
- package/v4/core/versions.cjs +1 -1
- package/v4/core/versions.js +1 -1
- package/v4/locales/es.cjs +42 -10
- package/v4/locales/es.js +42 -10
- package/v4/locales/index.cjs +9 -1
- package/v4/locales/index.d.cts +4 -0
- package/v4/locales/index.d.ts +4 -0
- package/v4/locales/index.js +4 -0
- package/v4/locales/ka.cjs +153 -0
- package/v4/locales/ka.d.cts +5 -0
- package/v4/locales/ka.d.ts +5 -0
- package/v4/locales/ka.js +125 -0
- package/v4/locales/kh.cjs +5 -137
- package/v4/locales/kh.d.ts +1 -0
- package/v4/locales/kh.js +3 -115
- package/v4/locales/km.cjs +144 -0
- package/v4/locales/km.d.cts +5 -0
- package/v4/locales/km.d.ts +4 -0
- package/v4/locales/km.js +117 -0
- package/v4/locales/lt.cjs +258 -0
- package/v4/locales/lt.d.cts +5 -0
- package/v4/locales/lt.d.ts +5 -0
- package/v4/locales/lt.js +230 -0
- package/v4/locales/ua.cjs +5 -137
- package/v4/locales/ua.d.ts +1 -0
- package/v4/locales/ua.js +3 -115
- package/v4/locales/uk.cjs +144 -0
- package/v4/locales/uk.d.cts +5 -0
- package/v4/locales/uk.d.ts +4 -0
- package/v4/locales/uk.js +117 -0
package/src/v4/locales/kh.ts
CHANGED
|
@@ -1,126 +1,7 @@
|
|
|
1
|
-
import type { $ZodStringFormats } from "../core/checks.js";
|
|
2
1
|
import type * as errors from "../core/errors.js";
|
|
3
|
-
import
|
|
4
|
-
|
|
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: "គួរមាន" },
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
function getSizing(origin: string): { unit: string; verb: string } | null {
|
|
14
|
-
return Sizable[origin] ?? null;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const parsedType = (data: any): string => {
|
|
18
|
-
const t = typeof data;
|
|
19
|
-
|
|
20
|
-
switch (t) {
|
|
21
|
-
case "number": {
|
|
22
|
-
return Number.isNaN(data) ? "មិនមែនជាលេខ (NaN)" : "លេខ";
|
|
23
|
-
}
|
|
24
|
-
case "object": {
|
|
25
|
-
if (Array.isArray(data)) {
|
|
26
|
-
return "អារេ (Array)";
|
|
27
|
-
}
|
|
28
|
-
if (data === null) {
|
|
29
|
-
return "គ្មានតម្លៃ (null)";
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (Object.getPrototypeOf(data) !== Object.prototype && data.constructor) {
|
|
33
|
-
return data.constructor.name;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return t;
|
|
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
|
-
case "invalid_value":
|
|
78
|
-
if (issue.values.length === 1) return `ទិន្នន័យបញ្ចូលមិនត្រឹមត្រូវ៖ ត្រូវការ ${util.stringifyPrimitive(issue.values[0])}`;
|
|
79
|
-
return `ជម្រើសមិនត្រឹមត្រូវ៖ ត្រូវជាមួយក្នុងចំណោម ${util.joinValues(issue.values, "|")}`;
|
|
80
|
-
case "too_big": {
|
|
81
|
-
const adj = issue.inclusive ? "<=" : "<";
|
|
82
|
-
const sizing = getSizing(issue.origin);
|
|
83
|
-
if (sizing)
|
|
84
|
-
return `ធំពេក៖ ត្រូវការ ${issue.origin ?? "តម្លៃ"} ${adj} ${issue.maximum.toString()} ${sizing.unit ?? "ធាតុ"}`;
|
|
85
|
-
return `ធំពេក៖ ត្រូវការ ${issue.origin ?? "តម្លៃ"} ${adj} ${issue.maximum.toString()}`;
|
|
86
|
-
}
|
|
87
|
-
case "too_small": {
|
|
88
|
-
const adj = issue.inclusive ? ">=" : ">";
|
|
89
|
-
const sizing = getSizing(issue.origin);
|
|
90
|
-
if (sizing) {
|
|
91
|
-
return `តូចពេក៖ ត្រូវការ ${issue.origin} ${adj} ${issue.minimum.toString()} ${sizing.unit}`;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return `តូចពេក៖ ត្រូវការ ${issue.origin} ${adj} ${issue.minimum.toString()}`;
|
|
95
|
-
}
|
|
96
|
-
case "invalid_format": {
|
|
97
|
-
const _issue = issue as errors.$ZodStringFormatIssues;
|
|
98
|
-
if (_issue.format === "starts_with") {
|
|
99
|
-
return `ខ្សែអក្សរមិនត្រឹមត្រូវ៖ ត្រូវចាប់ផ្តើមដោយ "${_issue.prefix}"`;
|
|
100
|
-
}
|
|
101
|
-
if (_issue.format === "ends_with") return `ខ្សែអក្សរមិនត្រឹមត្រូវ៖ ត្រូវបញ្ចប់ដោយ "${_issue.suffix}"`;
|
|
102
|
-
if (_issue.format === "includes") return `ខ្សែអក្សរមិនត្រឹមត្រូវ៖ ត្រូវមាន "${_issue.includes}"`;
|
|
103
|
-
if (_issue.format === "regex") return `ខ្សែអក្សរមិនត្រឹមត្រូវ៖ ត្រូវតែផ្គូផ្គងនឹងទម្រង់ដែលបានកំណត់ ${_issue.pattern}`;
|
|
104
|
-
return `មិនត្រឹមត្រូវ៖ ${Nouns[_issue.format] ?? issue.format}`;
|
|
105
|
-
}
|
|
106
|
-
case "not_multiple_of":
|
|
107
|
-
return `លេខមិនត្រឹមត្រូវ៖ ត្រូវតែជាពហុគុណនៃ ${issue.divisor}`;
|
|
108
|
-
case "unrecognized_keys":
|
|
109
|
-
return `រកឃើញសោមិនស្គាល់៖ ${util.joinValues(issue.keys, ", ")}`;
|
|
110
|
-
case "invalid_key":
|
|
111
|
-
return `សោមិនត្រឹមត្រូវនៅក្នុង ${issue.origin}`;
|
|
112
|
-
case "invalid_union":
|
|
113
|
-
return `ទិន្នន័យមិនត្រឹមត្រូវ`;
|
|
114
|
-
case "invalid_element":
|
|
115
|
-
return `ទិន្នន័យមិនត្រឹមត្រូវនៅក្នុង ${issue.origin}`;
|
|
116
|
-
default:
|
|
117
|
-
return `ទិន្នន័យមិនត្រឹមត្រូវ`;
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
};
|
|
2
|
+
import km from "./km.js";
|
|
121
3
|
|
|
4
|
+
/** @deprecated Use `km` instead. */
|
|
122
5
|
export default function (): { localeError: errors.$ZodErrorMap } {
|
|
123
|
-
return
|
|
124
|
-
localeError: error(),
|
|
125
|
-
};
|
|
6
|
+
return km();
|
|
126
7
|
}
|
|
@@ -0,0 +1,126 @@
|
|
|
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: "តួអក្សរ", verb: "គួរមាន" },
|
|
8
|
+
file: { unit: "បៃ", verb: "គួរមាន" },
|
|
9
|
+
array: { unit: "ធាតុ", verb: "គួរមាន" },
|
|
10
|
+
set: { unit: "ធាតុ", verb: "គួរមាន" },
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
function getSizing(origin: string): { unit: string; verb: string } | null {
|
|
14
|
+
return Sizable[origin] ?? null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const parsedType = (data: any): string => {
|
|
18
|
+
const t = typeof data;
|
|
19
|
+
|
|
20
|
+
switch (t) {
|
|
21
|
+
case "number": {
|
|
22
|
+
return Number.isNaN(data) ? "មិនមែនជាលេខ (NaN)" : "លេខ";
|
|
23
|
+
}
|
|
24
|
+
case "object": {
|
|
25
|
+
if (Array.isArray(data)) {
|
|
26
|
+
return "អារេ (Array)";
|
|
27
|
+
}
|
|
28
|
+
if (data === null) {
|
|
29
|
+
return "គ្មានតម្លៃ (null)";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (Object.getPrototypeOf(data) !== Object.prototype && data.constructor) {
|
|
33
|
+
return data.constructor.name;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return t;
|
|
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
|
+
case "invalid_value":
|
|
78
|
+
if (issue.values.length === 1) return `ទិន្នន័យបញ្ចូលមិនត្រឹមត្រូវ៖ ត្រូវការ ${util.stringifyPrimitive(issue.values[0])}`;
|
|
79
|
+
return `ជម្រើសមិនត្រឹមត្រូវ៖ ត្រូវជាមួយក្នុងចំណោម ${util.joinValues(issue.values, "|")}`;
|
|
80
|
+
case "too_big": {
|
|
81
|
+
const adj = issue.inclusive ? "<=" : "<";
|
|
82
|
+
const sizing = getSizing(issue.origin);
|
|
83
|
+
if (sizing)
|
|
84
|
+
return `ធំពេក៖ ត្រូវការ ${issue.origin ?? "តម្លៃ"} ${adj} ${issue.maximum.toString()} ${sizing.unit ?? "ធាតុ"}`;
|
|
85
|
+
return `ធំពេក៖ ត្រូវការ ${issue.origin ?? "តម្លៃ"} ${adj} ${issue.maximum.toString()}`;
|
|
86
|
+
}
|
|
87
|
+
case "too_small": {
|
|
88
|
+
const adj = issue.inclusive ? ">=" : ">";
|
|
89
|
+
const sizing = getSizing(issue.origin);
|
|
90
|
+
if (sizing) {
|
|
91
|
+
return `តូចពេក៖ ត្រូវការ ${issue.origin} ${adj} ${issue.minimum.toString()} ${sizing.unit}`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return `តូចពេក៖ ត្រូវការ ${issue.origin} ${adj} ${issue.minimum.toString()}`;
|
|
95
|
+
}
|
|
96
|
+
case "invalid_format": {
|
|
97
|
+
const _issue = issue as errors.$ZodStringFormatIssues;
|
|
98
|
+
if (_issue.format === "starts_with") {
|
|
99
|
+
return `ខ្សែអក្សរមិនត្រឹមត្រូវ៖ ត្រូវចាប់ផ្តើមដោយ "${_issue.prefix}"`;
|
|
100
|
+
}
|
|
101
|
+
if (_issue.format === "ends_with") return `ខ្សែអក្សរមិនត្រឹមត្រូវ៖ ត្រូវបញ្ចប់ដោយ "${_issue.suffix}"`;
|
|
102
|
+
if (_issue.format === "includes") return `ខ្សែអក្សរមិនត្រឹមត្រូវ៖ ត្រូវមាន "${_issue.includes}"`;
|
|
103
|
+
if (_issue.format === "regex") return `ខ្សែអក្សរមិនត្រឹមត្រូវ៖ ត្រូវតែផ្គូផ្គងនឹងទម្រង់ដែលបានកំណត់ ${_issue.pattern}`;
|
|
104
|
+
return `មិនត្រឹមត្រូវ៖ ${Nouns[_issue.format] ?? issue.format}`;
|
|
105
|
+
}
|
|
106
|
+
case "not_multiple_of":
|
|
107
|
+
return `លេខមិនត្រឹមត្រូវ៖ ត្រូវតែជាពហុគុណនៃ ${issue.divisor}`;
|
|
108
|
+
case "unrecognized_keys":
|
|
109
|
+
return `រកឃើញសោមិនស្គាល់៖ ${util.joinValues(issue.keys, ", ")}`;
|
|
110
|
+
case "invalid_key":
|
|
111
|
+
return `សោមិនត្រឹមត្រូវនៅក្នុង ${issue.origin}`;
|
|
112
|
+
case "invalid_union":
|
|
113
|
+
return `ទិន្នន័យមិនត្រឹមត្រូវ`;
|
|
114
|
+
case "invalid_element":
|
|
115
|
+
return `ទិន្នន័យមិនត្រឹមត្រូវនៅក្នុង ${issue.origin}`;
|
|
116
|
+
default:
|
|
117
|
+
return `ទិន្នន័យមិនត្រឹមត្រូវ`;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export default function (): { localeError: errors.$ZodErrorMap } {
|
|
123
|
+
return {
|
|
124
|
+
localeError: error(),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
@@ -0,0 +1,265 @@
|
|
|
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
|
+
return parsedTypeFromType(t, data);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const parsedTypeFromType = (t: string, data: any = undefined): string => {
|
|
11
|
+
switch (t) {
|
|
12
|
+
case "number": {
|
|
13
|
+
return Number.isNaN(data) ? "NaN" : "skaičius";
|
|
14
|
+
}
|
|
15
|
+
case "bigint": {
|
|
16
|
+
return "sveikasis skaičius";
|
|
17
|
+
}
|
|
18
|
+
case "string": {
|
|
19
|
+
return "eilutė";
|
|
20
|
+
}
|
|
21
|
+
case "boolean": {
|
|
22
|
+
return "loginė reikšmė";
|
|
23
|
+
}
|
|
24
|
+
case "undefined":
|
|
25
|
+
case "void": {
|
|
26
|
+
return "neapibrėžta reikšmė";
|
|
27
|
+
}
|
|
28
|
+
case "function": {
|
|
29
|
+
return "funkcija";
|
|
30
|
+
}
|
|
31
|
+
case "symbol": {
|
|
32
|
+
return "simbolis";
|
|
33
|
+
}
|
|
34
|
+
case "object": {
|
|
35
|
+
if (data === undefined) return "nežinomas objektas";
|
|
36
|
+
if (data === null) return "nulinė reikšmė";
|
|
37
|
+
|
|
38
|
+
if (Array.isArray(data)) return "masyvas";
|
|
39
|
+
if (Object.getPrototypeOf(data) !== Object.prototype && data.constructor) {
|
|
40
|
+
return data.constructor.name;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return "objektas";
|
|
44
|
+
}
|
|
45
|
+
//Zod types below
|
|
46
|
+
case "null": {
|
|
47
|
+
return "nulinė reikšmė";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return t;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const capitalizeFirstCharacter = (text: string): string => {
|
|
55
|
+
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
type UnitType = "one" | "few" | "many";
|
|
59
|
+
type SizeableComparisonType = "smaller" | "bigger";
|
|
60
|
+
|
|
61
|
+
function getUnitTypeFromNumber(number: number): UnitType {
|
|
62
|
+
const abs = Math.abs(number);
|
|
63
|
+
const last = abs % 10;
|
|
64
|
+
const last2 = abs % 100;
|
|
65
|
+
|
|
66
|
+
if ((last2 >= 11 && last2 <= 19) || last === 0) return "many";
|
|
67
|
+
if (last === 1) return "one";
|
|
68
|
+
return "few";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const error: () => errors.$ZodErrorMap = () => {
|
|
72
|
+
const Sizable: Record<
|
|
73
|
+
string,
|
|
74
|
+
{
|
|
75
|
+
unit: Record<UnitType, string>;
|
|
76
|
+
verb: Record<SizeableComparisonType, { inclusive: string; notInclusive: string }>;
|
|
77
|
+
}
|
|
78
|
+
> = {
|
|
79
|
+
string: {
|
|
80
|
+
unit: {
|
|
81
|
+
one: "simbolis",
|
|
82
|
+
few: "simboliai",
|
|
83
|
+
many: "simbolių",
|
|
84
|
+
},
|
|
85
|
+
verb: {
|
|
86
|
+
smaller: {
|
|
87
|
+
inclusive: "turi būti ne ilgesnė kaip",
|
|
88
|
+
notInclusive: "turi būti trumpesnė kaip",
|
|
89
|
+
},
|
|
90
|
+
bigger: {
|
|
91
|
+
inclusive: "turi būti ne trumpesnė kaip",
|
|
92
|
+
notInclusive: "turi būti ilgesnė kaip",
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
file: {
|
|
97
|
+
unit: {
|
|
98
|
+
one: "baitas",
|
|
99
|
+
few: "baitai",
|
|
100
|
+
many: "baitų",
|
|
101
|
+
},
|
|
102
|
+
verb: {
|
|
103
|
+
smaller: {
|
|
104
|
+
inclusive: "turi būti ne didesnis kaip",
|
|
105
|
+
notInclusive: "turi būti mažesnis kaip",
|
|
106
|
+
},
|
|
107
|
+
bigger: {
|
|
108
|
+
inclusive: "turi būti ne mažesnis kaip",
|
|
109
|
+
notInclusive: "turi būti didesnis kaip",
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
array: {
|
|
114
|
+
unit: {
|
|
115
|
+
one: "elementą",
|
|
116
|
+
few: "elementus",
|
|
117
|
+
many: "elementų",
|
|
118
|
+
},
|
|
119
|
+
verb: {
|
|
120
|
+
smaller: {
|
|
121
|
+
inclusive: "turi turėti ne daugiau kaip",
|
|
122
|
+
notInclusive: "turi turėti mažiau kaip",
|
|
123
|
+
},
|
|
124
|
+
bigger: {
|
|
125
|
+
inclusive: "turi turėti ne mažiau kaip",
|
|
126
|
+
notInclusive: "turi turėti daugiau kaip",
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
set: {
|
|
131
|
+
unit: {
|
|
132
|
+
one: "elementą",
|
|
133
|
+
few: "elementus",
|
|
134
|
+
many: "elementų",
|
|
135
|
+
},
|
|
136
|
+
verb: {
|
|
137
|
+
smaller: {
|
|
138
|
+
inclusive: "turi turėti ne daugiau kaip",
|
|
139
|
+
notInclusive: "turi turėti mažiau kaip",
|
|
140
|
+
},
|
|
141
|
+
bigger: {
|
|
142
|
+
inclusive: "turi turėti ne mažiau kaip",
|
|
143
|
+
notInclusive: "turi turėti daugiau kaip",
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
function getSizing(
|
|
150
|
+
origin: string,
|
|
151
|
+
unitType: UnitType,
|
|
152
|
+
inclusive: boolean,
|
|
153
|
+
targetShouldBe: SizeableComparisonType
|
|
154
|
+
): {
|
|
155
|
+
unit: string;
|
|
156
|
+
verb: string;
|
|
157
|
+
} | null {
|
|
158
|
+
const result = Sizable[origin] ?? null;
|
|
159
|
+
if (result === null) return result;
|
|
160
|
+
|
|
161
|
+
return {
|
|
162
|
+
unit: result.unit[unitType],
|
|
163
|
+
verb: result.verb[targetShouldBe][inclusive ? "inclusive" : "notInclusive"],
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const Nouns: {
|
|
168
|
+
[k in $ZodStringFormats | (string & {})]?: string;
|
|
169
|
+
} = {
|
|
170
|
+
regex: "įvestis",
|
|
171
|
+
email: "el. pašto adresas",
|
|
172
|
+
url: "URL",
|
|
173
|
+
emoji: "jaustukas",
|
|
174
|
+
uuid: "UUID",
|
|
175
|
+
uuidv4: "UUIDv4",
|
|
176
|
+
uuidv6: "UUIDv6",
|
|
177
|
+
nanoid: "nanoid",
|
|
178
|
+
guid: "GUID",
|
|
179
|
+
cuid: "cuid",
|
|
180
|
+
cuid2: "cuid2",
|
|
181
|
+
ulid: "ULID",
|
|
182
|
+
xid: "XID",
|
|
183
|
+
ksuid: "KSUID",
|
|
184
|
+
datetime: "ISO data ir laikas",
|
|
185
|
+
date: "ISO data",
|
|
186
|
+
time: "ISO laikas",
|
|
187
|
+
duration: "ISO trukmė",
|
|
188
|
+
ipv4: "IPv4 adresas",
|
|
189
|
+
ipv6: "IPv6 adresas",
|
|
190
|
+
cidrv4: "IPv4 tinklo prefiksas (CIDR)",
|
|
191
|
+
cidrv6: "IPv6 tinklo prefiksas (CIDR)",
|
|
192
|
+
base64: "base64 užkoduota eilutė",
|
|
193
|
+
base64url: "base64url užkoduota eilutė",
|
|
194
|
+
json_string: "JSON eilutė",
|
|
195
|
+
e164: "E.164 numeris",
|
|
196
|
+
jwt: "JWT",
|
|
197
|
+
template_literal: "įvestis",
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
return (issue) => {
|
|
201
|
+
switch (issue.code) {
|
|
202
|
+
case "invalid_type":
|
|
203
|
+
return `Gautas tipas ${parsedType(issue.input)}, o tikėtasi - ${parsedTypeFromType(issue.expected)}`;
|
|
204
|
+
case "invalid_value":
|
|
205
|
+
if (issue.values.length === 1) return `Privalo būti ${util.stringifyPrimitive(issue.values[0])}`;
|
|
206
|
+
return `Privalo būti vienas iš ${util.joinValues(issue.values, "|")} pasirinkimų`;
|
|
207
|
+
case "too_big": {
|
|
208
|
+
const origin = parsedTypeFromType(issue.origin);
|
|
209
|
+
const sizing = getSizing(
|
|
210
|
+
issue.origin,
|
|
211
|
+
getUnitTypeFromNumber(Number(issue.maximum)),
|
|
212
|
+
issue.inclusive ?? false,
|
|
213
|
+
"smaller"
|
|
214
|
+
);
|
|
215
|
+
if (sizing?.verb)
|
|
216
|
+
return `${capitalizeFirstCharacter(origin ?? issue.origin ?? "reikšmė")} ${sizing.verb} ${issue.maximum.toString()} ${sizing.unit ?? "elementų"}`;
|
|
217
|
+
const adj = issue.inclusive ? "ne didesnis kaip" : "mažesnis kaip";
|
|
218
|
+
return `${capitalizeFirstCharacter(origin ?? issue.origin ?? "reikšmė")} turi būti ${adj} ${issue.maximum.toString()} ${sizing?.unit}`;
|
|
219
|
+
}
|
|
220
|
+
case "too_small": {
|
|
221
|
+
const origin = parsedTypeFromType(issue.origin);
|
|
222
|
+
const sizing = getSizing(
|
|
223
|
+
issue.origin,
|
|
224
|
+
getUnitTypeFromNumber(Number(issue.minimum)),
|
|
225
|
+
issue.inclusive ?? false,
|
|
226
|
+
"bigger"
|
|
227
|
+
);
|
|
228
|
+
if (sizing?.verb)
|
|
229
|
+
return `${capitalizeFirstCharacter(origin ?? issue.origin ?? "reikšmė")} ${sizing.verb} ${issue.minimum.toString()} ${sizing.unit ?? "elementų"}`;
|
|
230
|
+
const adj = issue.inclusive ? "ne mažesnis kaip" : "didesnis kaip";
|
|
231
|
+
return `${capitalizeFirstCharacter(origin ?? issue.origin ?? "reikšmė")} turi būti ${adj} ${issue.minimum.toString()} ${sizing?.unit}`;
|
|
232
|
+
}
|
|
233
|
+
case "invalid_format": {
|
|
234
|
+
const _issue = issue as errors.$ZodStringFormatIssues;
|
|
235
|
+
if (_issue.format === "starts_with") {
|
|
236
|
+
return `Eilutė privalo prasidėti "${_issue.prefix}"`;
|
|
237
|
+
}
|
|
238
|
+
if (_issue.format === "ends_with") return `Eilutė privalo pasibaigti "${_issue.suffix}"`;
|
|
239
|
+
if (_issue.format === "includes") return `Eilutė privalo įtraukti "${_issue.includes}"`;
|
|
240
|
+
if (_issue.format === "regex") return `Eilutė privalo atitikti ${_issue.pattern}`;
|
|
241
|
+
return `Neteisingas ${Nouns[_issue.format] ?? issue.format}`;
|
|
242
|
+
}
|
|
243
|
+
case "not_multiple_of":
|
|
244
|
+
return `Skaičius privalo būti ${issue.divisor} kartotinis.`;
|
|
245
|
+
case "unrecognized_keys":
|
|
246
|
+
return `Neatpažint${issue.keys.length > 1 ? "i" : "as"} rakt${issue.keys.length > 1 ? "ai" : "as"}: ${util.joinValues(issue.keys, ", ")}`;
|
|
247
|
+
case "invalid_key":
|
|
248
|
+
return "Rastas klaidingas raktas";
|
|
249
|
+
case "invalid_union":
|
|
250
|
+
return "Klaidinga įvestis";
|
|
251
|
+
case "invalid_element": {
|
|
252
|
+
const origin = parsedTypeFromType(issue.origin);
|
|
253
|
+
return `${capitalizeFirstCharacter(origin ?? issue.origin ?? "reikšmė")} turi klaidingą įvestį`;
|
|
254
|
+
}
|
|
255
|
+
default:
|
|
256
|
+
return "Klaidinga įvestis";
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
export default function (): { localeError: errors.$ZodErrorMap } {
|
|
262
|
+
return {
|
|
263
|
+
localeError: error(),
|
|
264
|
+
};
|
|
265
|
+
}
|
package/src/v4/locales/ua.ts
CHANGED
|
@@ -1,126 +1,7 @@
|
|
|
1
|
-
import type { $ZodStringFormats } from "../core/checks.js";
|
|
2
1
|
import type * as errors from "../core/errors.js";
|
|
3
|
-
import
|
|
4
|
-
|
|
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: "матиме" },
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
function getSizing(origin: string): { unit: string; verb: string } | null {
|
|
14
|
-
return Sizable[origin] ?? null;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const parsedType = (data: any): string => {
|
|
18
|
-
const t = typeof data;
|
|
19
|
-
|
|
20
|
-
switch (t) {
|
|
21
|
-
case "number": {
|
|
22
|
-
return Number.isNaN(data) ? "NaN" : "число";
|
|
23
|
-
}
|
|
24
|
-
case "object": {
|
|
25
|
-
if (Array.isArray(data)) {
|
|
26
|
-
return "масив";
|
|
27
|
-
}
|
|
28
|
-
if (data === null) {
|
|
29
|
-
return "null";
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (Object.getPrototypeOf(data) !== Object.prototype && data.constructor) {
|
|
33
|
-
return data.constructor.name;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return t;
|
|
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
|
-
// return `Неправильні вхідні дані: очікується ${issue.expected}, отримано ${util.getParsedType(issue.input)}`;
|
|
78
|
-
case "invalid_value":
|
|
79
|
-
if (issue.values.length === 1)
|
|
80
|
-
return `Неправильні вхідні дані: очікується ${util.stringifyPrimitive(issue.values[0])}`;
|
|
81
|
-
return `Неправильна опція: очікується одне з ${util.joinValues(issue.values, "|")}`;
|
|
82
|
-
case "too_big": {
|
|
83
|
-
const adj = issue.inclusive ? "<=" : "<";
|
|
84
|
-
const sizing = getSizing(issue.origin);
|
|
85
|
-
if (sizing)
|
|
86
|
-
return `Занадто велике: очікується, що ${issue.origin ?? "значення"} ${sizing.verb} ${adj}${issue.maximum.toString()} ${sizing.unit ?? "елементів"}`;
|
|
87
|
-
return `Занадто велике: очікується, що ${issue.origin ?? "значення"} буде ${adj}${issue.maximum.toString()}`;
|
|
88
|
-
}
|
|
89
|
-
case "too_small": {
|
|
90
|
-
const adj = issue.inclusive ? ">=" : ">";
|
|
91
|
-
const sizing = getSizing(issue.origin);
|
|
92
|
-
if (sizing) {
|
|
93
|
-
return `Занадто мале: очікується, що ${issue.origin} ${sizing.verb} ${adj}${issue.minimum.toString()} ${sizing.unit}`;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return `Занадто мале: очікується, що ${issue.origin} буде ${adj}${issue.minimum.toString()}`;
|
|
97
|
-
}
|
|
98
|
-
case "invalid_format": {
|
|
99
|
-
const _issue = issue as errors.$ZodStringFormatIssues;
|
|
100
|
-
if (_issue.format === "starts_with") return `Неправильний рядок: повинен починатися з "${_issue.prefix}"`;
|
|
101
|
-
if (_issue.format === "ends_with") return `Неправильний рядок: повинен закінчуватися на "${_issue.suffix}"`;
|
|
102
|
-
if (_issue.format === "includes") return `Неправильний рядок: повинен містити "${_issue.includes}"`;
|
|
103
|
-
if (_issue.format === "regex") return `Неправильний рядок: повинен відповідати шаблону ${_issue.pattern}`;
|
|
104
|
-
return `Неправильний ${Nouns[_issue.format] ?? issue.format}`;
|
|
105
|
-
}
|
|
106
|
-
case "not_multiple_of":
|
|
107
|
-
return `Неправильне число: повинно бути кратним ${issue.divisor}`;
|
|
108
|
-
case "unrecognized_keys":
|
|
109
|
-
return `Нерозпізнаний ключ${issue.keys.length > 1 ? "і" : ""}: ${util.joinValues(issue.keys, ", ")}`;
|
|
110
|
-
case "invalid_key":
|
|
111
|
-
return `Неправильний ключ у ${issue.origin}`;
|
|
112
|
-
case "invalid_union":
|
|
113
|
-
return "Неправильні вхідні дані";
|
|
114
|
-
case "invalid_element":
|
|
115
|
-
return `Неправильне значення у ${issue.origin}`;
|
|
116
|
-
default:
|
|
117
|
-
return `Неправильні вхідні дані`;
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
};
|
|
2
|
+
import uk from "./uk.js";
|
|
121
3
|
|
|
4
|
+
/** @deprecated Use `uk` instead. */
|
|
122
5
|
export default function (): { localeError: errors.$ZodErrorMap } {
|
|
123
|
-
return
|
|
124
|
-
localeError: error(),
|
|
125
|
-
};
|
|
6
|
+
return uk();
|
|
126
7
|
}
|