he.jsā¢5.08 kB
import * as util from "../core/util.js";
const error = () => {
const Sizable = {
string: { unit: "×××Ŗ×××Ŗ", verb: "×××××" },
file: { unit: "××××××", verb: "×××××" },
array: { unit: "פר××××", verb: "×××××" },
set: { unit: "פר××××", verb: "×××××" },
};
function getSizing(origin) {
return Sizable[origin] ?? null;
}
const parsedType = (data) => {
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 = {
regex: "×§××",
email: "××Ŗ×××Ŗ ××××××",
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: "××ר×××Ŗ ×××”××” 64",
base64url: "××ר×××Ŗ ×××”××” 64 ×××Ŗ××××Ŗ רשת",
json_string: "××ר×××Ŗ JSON",
e164: "×הפר E.164",
jwt: "JWT",
template_literal: "×§××",
};
return (issue) => {
switch (issue.code) {
case "invalid_type":
return `×§×× ×× ×Ŗ×§××: צר×× ${issue.expected}, ××Ŗ×§×× ${parsedType(issue.input)}`;
// return `Invalid input: expected ${issue.expected}, received ${util.getParsedType(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 sizing = getSizing(issue.origin);
if (sizing)
return `×××× ×××: ${issue.origin ?? "value"} צר×× ×××××Ŗ ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elements"}`;
return `×××× ×××: ${issue.origin ?? "value"} צר×× ×××××Ŗ ${adj}${issue.maximum.toString()}`;
}
case "too_small": {
const adj = issue.inclusive ? ">=" : ">";
const sizing = getSizing(issue.origin);
if (sizing) {
return `×§×× ×××: ${issue.origin} צר×× ×××××Ŗ ${adj}${issue.minimum.toString()} ${sizing.unit}`;
}
return `×§×× ×××: ${issue.origin} צר×× ×××××Ŗ ${adj}${issue.minimum.toString()}`;
}
case "invalid_format": {
const _issue = issue;
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 `×פת×${issue.keys.length > 1 ? "××Ŗ" : ""} ×× ××××${issue.keys.length > 1 ? "××" : "×"}: ${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 () {
return {
localeError: error(),
};
}