144 lines
6.6 KiB
JavaScript
144 lines
6.6 KiB
JavaScript
"use strict";
|
||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||
if (k2 === undefined) k2 = k;
|
||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||
}
|
||
Object.defineProperty(o, k2, desc);
|
||
}) : (function(o, m, k, k2) {
|
||
if (k2 === undefined) k2 = k;
|
||
o[k2] = m[k];
|
||
}));
|
||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||
}) : function(o, v) {
|
||
o["default"] = v;
|
||
});
|
||
var __importStar = (this && this.__importStar) || function (mod) {
|
||
if (mod && mod.__esModule) return mod;
|
||
var result = {};
|
||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||
__setModuleDefault(result, mod);
|
||
return result;
|
||
};
|
||
Object.defineProperty(exports, "__esModule", { value: true });
|
||
exports.default = default_1;
|
||
const util = __importStar(require("../core/util.cjs"));
|
||
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" : "число";
|
||
}
|
||
case "object": {
|
||
if (Array.isArray(data)) {
|
||
return "масив";
|
||
}
|
||
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: "емодзі",
|
||
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)}`;
|
||
// return `Неправильні вхідні дані: очікується ${issue.expected}, отримано ${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 ?? "значення"} ${sizing.verb} ${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} ${sizing.verb} ${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 `Неправильні вхідні дані`;
|
||
}
|
||
};
|
||
};
|
||
function default_1() {
|
||
return {
|
||
localeError: error(),
|
||
};
|
||
}
|
||
module.exports = exports.default;
|