zh-tw.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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.error = exports.parsedType = void 0;
  27. exports.default = default_1;
  28. const util = __importStar(require("../core/util.js"));
  29. const Sizable = {
  30. string: { unit: "字元", verb: "擁有" },
  31. file: { unit: "位元組", verb: "擁有" },
  32. array: { unit: "項目", verb: "擁有" },
  33. set: { unit: "項目", verb: "擁有" },
  34. };
  35. function getSizing(origin) {
  36. return Sizable[origin] ?? null;
  37. }
  38. const parsedType = (data) => {
  39. const t = typeof data;
  40. switch (t) {
  41. case "number": {
  42. return Number.isNaN(data) ? "NaN" : "number";
  43. }
  44. case "object": {
  45. if (Array.isArray(data)) {
  46. return "array";
  47. }
  48. if (data === null) {
  49. return "null";
  50. }
  51. if (Object.getPrototypeOf(data) !== Object.prototype && data.constructor) {
  52. return data.constructor.name;
  53. }
  54. }
  55. }
  56. return t;
  57. };
  58. exports.parsedType = parsedType;
  59. const Nouns = {
  60. regex: "輸入",
  61. email: "郵件地址",
  62. url: "URL",
  63. emoji: "emoji",
  64. uuid: "UUID",
  65. uuidv4: "UUIDv4",
  66. uuidv6: "UUIDv6",
  67. nanoid: "nanoid",
  68. guid: "GUID",
  69. cuid: "cuid",
  70. cuid2: "cuid2",
  71. ulid: "ULID",
  72. xid: "XID",
  73. ksuid: "KSUID",
  74. datetime: "ISO 日期時間",
  75. date: "ISO 日期",
  76. time: "ISO 時間",
  77. duration: "ISO 期間",
  78. ipv4: "IPv4 位址",
  79. ipv6: "IPv6 位址",
  80. cidrv4: "IPv4 範圍",
  81. cidrv6: "IPv6 範圍",
  82. base64: "base64 編碼字串",
  83. base64url: "base64url 編碼字串",
  84. json_string: "JSON 字串",
  85. e164: "E.164 數值",
  86. jwt: "JWT",
  87. template_literal: "輸入",
  88. };
  89. const error = (issue) => {
  90. switch (issue.code) {
  91. case "invalid_type":
  92. return `無效的輸入值:預期為 ${issue.expected},但收到 ${(0, exports.parsedType)(issue.input)}`;
  93. case "invalid_value":
  94. if (issue.values.length === 1)
  95. return `無效的輸入值:預期為 ${util.stringifyPrimitive(issue.values[0])}`;
  96. return `無效的選項:預期為以下其中之一 ${util.joinValues(issue.values, "|")}`;
  97. case "too_big": {
  98. const adj = issue.inclusive ? "<=" : "<";
  99. const sizing = getSizing(issue.origin);
  100. if (sizing)
  101. return `數值過大:預期 ${issue.origin ?? "值"} 應為 ${adj}${issue.maximum.toString()} ${sizing.unit ?? "個元素"}`;
  102. return `數值過大:預期 ${issue.origin ?? "值"} 應為 ${adj}${issue.maximum.toString()}`;
  103. }
  104. case "too_small": {
  105. const adj = issue.inclusive ? ">=" : ">";
  106. const sizing = getSizing(issue.origin);
  107. if (sizing) {
  108. return `數值過小:預期 ${issue.origin} 應為 ${adj}${issue.minimum.toString()} ${sizing.unit}`;
  109. }
  110. return `數值過小:預期 ${issue.origin} 應為 ${adj}${issue.minimum.toString()}`;
  111. }
  112. case "invalid_format": {
  113. const _issue = issue;
  114. if (_issue.format === "starts_with") {
  115. return `無效的字串:必須以 "${_issue.prefix}" 開頭`;
  116. }
  117. if (_issue.format === "ends_with")
  118. return `無效的字串:必須以 "${_issue.suffix}" 結尾`;
  119. if (_issue.format === "includes")
  120. return `無效的字串:必須包含 "${_issue.includes}"`;
  121. if (_issue.format === "regex")
  122. return `無效的字串:必須符合格式 ${_issue.pattern}`;
  123. return `無效的 ${Nouns[_issue.format] ?? issue.format}`;
  124. }
  125. case "not_multiple_of":
  126. return `無效的數字:必須為 ${issue.divisor} 的倍數`;
  127. case "unrecognized_keys":
  128. return `無法識別的鍵值${issue.keys.length > 1 ? "們" : ""}:${util.joinValues(issue.keys, "、")}`;
  129. case "invalid_key":
  130. return `${issue.origin} 中有無效的鍵值`;
  131. case "invalid_union":
  132. return "無效的輸入值";
  133. case "invalid_element":
  134. return `${issue.origin} 中有無效的值`;
  135. default:
  136. return `無效的輸入值`;
  137. }
  138. };
  139. exports.error = error;
  140. function default_1() {
  141. return {
  142. localeError: error,
  143. };
  144. }