ja.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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" : "数値";
  43. }
  44. case "object": {
  45. if (Array.isArray(data)) {
  46. return "配列";
  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: "絵文字",
  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 ?? "値"}は${issue.maximum.toString()}${sizing.unit ?? "要素"}${adj}である必要があります`;
  102. return `大きすぎる値: ${issue.origin ?? "値"}は${issue.maximum.toString()}${adj}である必要があります`;
  103. }
  104. case "too_small": {
  105. const adj = issue.inclusive ? ">=" : ">";
  106. const sizing = getSizing(issue.origin);
  107. if (sizing)
  108. return `小さすぎる値: ${issue.origin}は${issue.minimum.toString()}${sizing.unit}${adj}である必要があります`;
  109. return `小さすぎる値: ${issue.origin}は${issue.minimum.toString()}${adj}である必要があります`;
  110. }
  111. case "invalid_format": {
  112. const _issue = issue;
  113. if (_issue.format === "starts_with")
  114. return `無効な文字列: "${_issue.prefix}"で始まる必要があります`;
  115. if (_issue.format === "ends_with")
  116. return `無効な文字列: "${_issue.suffix}"で終わる必要があります`;
  117. if (_issue.format === "includes")
  118. return `無効な文字列: "${_issue.includes}"を含む必要があります`;
  119. if (_issue.format === "regex")
  120. return `無効な文字列: パターン${_issue.pattern}に一致する必要があります`;
  121. return `無効な${Nouns[_issue.format] ?? issue.format}`;
  122. }
  123. case "not_multiple_of":
  124. return `無効な数値: ${issue.divisor}の倍数である必要があります`;
  125. case "unrecognized_keys":
  126. return `認識されていないキー${issue.keys.length > 1 ? "群" : ""}: ${util.joinValues(issue.keys, "、")}`;
  127. case "invalid_key":
  128. return `${issue.origin}内の無効なキー`;
  129. case "invalid_union":
  130. return "無効な入力";
  131. case "invalid_element":
  132. return `${issue.origin}内の無効な値`;
  133. default:
  134. return `無効な入力`;
  135. }
  136. };
  137. exports.error = error;
  138. function default_1() {
  139. return {
  140. localeError: error,
  141. };
  142. }