ko.tsā¢4.71 kB
import type { $ZodStringFormats } from "../core/checks.js";
import type * as errors from "../core/errors.js";
import * as util from "../core/util.js";
const error: () => errors.$ZodErrorMap = () => {
const Sizable: Record<string, { unit: string; verb: string }> = {
string: { unit: "문ģ", verb: "to have" },
file: { unit: "ė°ģ“ķø", verb: "to have" },
array: { unit: "ź°", verb: "to have" },
set: { unit: "ź°", verb: "to have" },
};
function getSizing(origin: string): { unit: string; verb: string } | null {
return Sizable[origin] ?? null;
}
const parsedType = (data: any): string => {
const t = typeof data;
switch (t) {
case "number": {
return Number.isNaN(data) ? "NaN" : "number";
}
case "object": {
if (Array.isArray(data)) {
return "array";
}
if (data === null) {
return "null";
}
if (Object.getPrototypeOf(data) !== Object.prototype && data.constructor) {
return data.constructor.name;
}
}
}
return t;
};
const Nouns: {
[k in $ZodStringFormats | (string & {})]?: string;
} = {
regex: "ģ
ė „",
email: "ģ“ė©ģ¼ 주ģ",
url: "URL",
emoji: "ģ“ėŖØģ§",
uuid: "UUID",
uuidv4: "UUIDv4",
uuidv6: "UUIDv6",
nanoid: "nanoid",
guid: "GUID",
cuid: "cuid",
cuid2: "cuid2",
ulid: "ULID",
xid: "XID",
ksuid: "KSUID",
datetime: "ISO ė ģ§ģź°",
date: "ISO ė ģ§",
time: "ISO ģź°",
duration: "ISO źø°ź°",
ipv4: "IPv4 주ģ",
ipv6: "IPv6 주ģ",
cidrv4: "IPv4 ė²ģ",
cidrv6: "IPv6 ė²ģ",
base64: "base64 ģøģ½ė© 문ģģ“",
base64url: "base64url ģøģ½ė© 문ģģ“",
json_string: "JSON 문ģģ“",
e164: "E.164 ė²ķø",
jwt: "JWT",
template_literal: "ģ
ė „",
};
return (issue) => {
switch (issue.code) {
case "invalid_type":
return `ģėŖ»ė ģ
ė „: ģģ ķģ
ģ ${issue.expected}, ė°ģ ķģ
ģ ${parsedType(issue.input)}ģ
ėė¤`;
case "invalid_value":
if (issue.values.length === 1)
return `ģėŖ»ė ģ
ė „: ź°ģ ${util.stringifyPrimitive(issue.values[0])} ģ“ģ“ģ¼ ķ©ėė¤`;
return `ģėŖ»ė ģµģ
: ${util.joinValues(issue.values, "ėė ")} ģ¤ ķėģ¬ģ¼ ķ©ėė¤`;
case "too_big": {
const adj = issue.inclusive ? "ģ“ķ" : "미ė§";
const suffix = adj === "미ė§" ? "ģ“ģ“ģ¼ ķ©ėė¤" : "ģ¬ģ¼ ķ©ėė¤";
const sizing = getSizing(issue.origin);
const unit = sizing?.unit ?? "ģģ";
if (sizing) return `${issue.origin ?? "ź°"}ģ“ ė묓 ķ½ėė¤: ${issue.maximum.toString()}${unit} ${adj}${suffix}`;
return `${issue.origin ?? "ź°"}ģ“ ė묓 ķ½ėė¤: ${issue.maximum.toString()} ${adj}${suffix}`;
}
case "too_small": {
const adj = issue.inclusive ? "ģ“ģ" : "ģ“ź³¼";
const suffix = adj === "ģ“ģ" ? "ģ“ģ“ģ¼ ķ©ėė¤" : "ģ¬ģ¼ ķ©ėė¤";
const sizing = getSizing(issue.origin);
const unit = sizing?.unit ?? "ģģ";
if (sizing) {
return `${issue.origin ?? "ź°"}ģ“ ė묓 ģģµėė¤: ${issue.minimum.toString()}${unit} ${adj}${suffix}`;
}
return `${issue.origin ?? "ź°"}ģ“ ė묓 ģģµėė¤: ${issue.minimum.toString()} ${adj}${suffix}`;
}
case "invalid_format": {
const _issue = issue as errors.$ZodStringFormatIssues;
if (_issue.format === "starts_with") {
return `ģėŖ»ė 문ģģ“: "${_issue.prefix}"(ģ¼)ė” ģģķ“ģ¼ ķ©ėė¤`;
}
if (_issue.format === "ends_with") return `ģėŖ»ė 문ģģ“: "${_issue.suffix}"(ģ¼)ė” ėėģ¼ ķ©ėė¤`;
if (_issue.format === "includes") return `ģėŖ»ė 문ģģ“: "${_issue.includes}"ģ(넼) ķ¬ķØķ“ģ¼ ķ©ėė¤`;
if (_issue.format === "regex") return `ģėŖ»ė 문ģģ“: ģ ź·ģ ${_issue.pattern} ķØķ“ź³¼ ģ¼ģ¹ķ“ģ¼ ķ©ėė¤`;
return `ģėŖ»ė ${Nouns[_issue.format] ?? issue.format}`;
}
case "not_multiple_of":
return `ģėŖ»ė ģ«ģ: ${issue.divisor}ģ ė°°ģģ¬ģ¼ ķ©ėė¤`;
case "unrecognized_keys":
return `ģøģķ ģ ģė ķ¤: ${util.joinValues(issue.keys, ", ")}`;
case "invalid_key":
return `ģėŖ»ė ķ¤: ${issue.origin}`;
case "invalid_union":
return `ģėŖ»ė ģ
ė „`;
case "invalid_element":
return `ģėŖ»ė ź°: ${issue.origin}`;
default:
return `ģėŖ»ė ģ
ė „`;
}
};
};
export default function (): { localeError: errors.$ZodErrorMap } {
return {
localeError: error(),
};
}