Files
klz-cables.com/.pnpm-store/v10/files/4a/21ef374ffc754646b57565b004f9fac50cd70543a224fd1de2c55d883b19d1ab5c322b22c21d4e4a969d9b3400018fb5395db79a4f08df3f027ece5ce5f39c
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

118 lines
4.5 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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: "URL",
emoji: "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 sizing = getSizing(issue.origin);
if (sizing)
return `數值過大:預期 ${issue.origin ?? "值"} 應為 ${adj}${issue.maximum.toString()} ${sizing.unit ?? "個元素"}`;
return `數值過大:預期 ${issue.origin ?? "值"} 應為 ${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 ? "們" : ""}${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(),
};
}