UEA-Prodem
This commit is contained in:
+197
@@ -0,0 +1,197 @@
|
||||
import { expect, test } from "vitest";
|
||||
import * as z from "zod/v4";
|
||||
|
||||
/**
|
||||
* Schema methods are exposed in a way that works when detached from the
|
||||
* schema instance — `const opt = schema.optional; opt()` must produce a
|
||||
* working `ZodOptional`, not a corrupt one. This pattern is used in real
|
||||
* code (e.g. `arr.map(schema.parse)`, `arr.map(schema.optional)`,
|
||||
* destructuring inside utility functions).
|
||||
*
|
||||
* This test caught a regression in colinhacks/zod#5870 where a memory
|
||||
* optimization moved methods to the prototype and made `this`-binding
|
||||
* required, silently breaking any detached usage.
|
||||
*/
|
||||
|
||||
const probeArgs: Record<string, unknown[]> = {
|
||||
// ZodType
|
||||
optional: [],
|
||||
exactOptional: [],
|
||||
nullable: [],
|
||||
nullish: [],
|
||||
array: [],
|
||||
describe: ["x"],
|
||||
brand: [],
|
||||
readonly: [],
|
||||
default: ["fallback"],
|
||||
catch: ["fallback"],
|
||||
// _ZodString
|
||||
min: [1],
|
||||
max: [10],
|
||||
length: [5],
|
||||
nonempty: [],
|
||||
trim: [],
|
||||
toLowerCase: [],
|
||||
toUpperCase: [],
|
||||
// ZodString format methods
|
||||
email: [],
|
||||
url: [],
|
||||
uuid: [],
|
||||
cuid: [],
|
||||
cuid2: [],
|
||||
ulid: [],
|
||||
base64: [],
|
||||
base64url: [],
|
||||
ipv4: [],
|
||||
ipv6: [],
|
||||
// ZodNumber
|
||||
int: [],
|
||||
positive: [],
|
||||
negative: [],
|
||||
finite: [],
|
||||
};
|
||||
|
||||
test("detached parse-family methods work without `this` binding", () => {
|
||||
const schema = z.string();
|
||||
const { parse, safeParse } = schema;
|
||||
|
||||
expect(parse("hello")).toBe("hello");
|
||||
expect(safeParse("hello").success).toBe(true);
|
||||
});
|
||||
|
||||
test("detached schema.optional() returns a working ZodOptional", () => {
|
||||
const schema = z.string();
|
||||
const opt = schema.optional;
|
||||
|
||||
const detached = opt();
|
||||
|
||||
expect(detached).toBeInstanceOf(z.ZodOptional);
|
||||
expect(detached.safeParse("hello").success).toBe(true);
|
||||
expect(detached.safeParse(undefined).success).toBe(true);
|
||||
expect(detached.safeParse(123).success).toBe(false);
|
||||
});
|
||||
|
||||
test("detached schema.nullable() returns a working ZodNullable", () => {
|
||||
const schema = z.string();
|
||||
const nul = schema.nullable;
|
||||
|
||||
const detached = nul();
|
||||
|
||||
expect(detached).toBeInstanceOf(z.ZodNullable);
|
||||
expect(detached.safeParse("hello").success).toBe(true);
|
||||
expect(detached.safeParse(null).success).toBe(true);
|
||||
expect(detached.safeParse(123).success).toBe(false);
|
||||
});
|
||||
|
||||
test("detached schema.array() returns a working ZodArray", () => {
|
||||
const schema = z.string();
|
||||
const arr = schema.array;
|
||||
|
||||
const detached = arr();
|
||||
|
||||
expect(detached).toBeInstanceOf(z.ZodArray);
|
||||
expect(detached.safeParse(["a", "b"]).success).toBe(true);
|
||||
expect(detached.safeParse([1, 2]).success).toBe(false);
|
||||
});
|
||||
|
||||
test("detached schema.describe() returns a described schema", () => {
|
||||
const schema = z.string();
|
||||
const describe = schema.describe;
|
||||
|
||||
const described = describe("hello world");
|
||||
|
||||
expect(described.description).toBe("hello world");
|
||||
});
|
||||
|
||||
test("detached refinement still validates", () => {
|
||||
const schema = z.string();
|
||||
const refine = schema.refine;
|
||||
|
||||
const refined = refine((s: string) => s.startsWith("x"), "must start with x");
|
||||
|
||||
expect(refined.safeParse("xhello").success).toBe(true);
|
||||
expect(refined.safeParse("hello").success).toBe(false);
|
||||
});
|
||||
|
||||
test("detached chained calls work — schema.optional then parse", () => {
|
||||
const schema = z.string();
|
||||
const opt = schema.optional;
|
||||
const optionalSchema = opt();
|
||||
const { parse } = optionalSchema;
|
||||
|
||||
expect(parse("hi")).toBe("hi");
|
||||
expect(parse(undefined)).toBe(undefined);
|
||||
});
|
||||
|
||||
test("detached parse can be called as a free function", () => {
|
||||
const schema = z.string();
|
||||
const parse = schema.parse;
|
||||
const inputs = ["a", "b", "c"];
|
||||
|
||||
const results = inputs.map((v) => parse(v));
|
||||
|
||||
expect(results).toEqual(["a", "b", "c"]);
|
||||
});
|
||||
|
||||
test("detached methods on z.number() work", () => {
|
||||
const schema = z.number();
|
||||
|
||||
const min = schema.min;
|
||||
const max = schema.max;
|
||||
const positive = schema.positive;
|
||||
|
||||
expect(min(5).safeParse(3).success).toBe(false);
|
||||
expect(max(5).safeParse(7).success).toBe(false);
|
||||
expect(positive().safeParse(-1).success).toBe(false);
|
||||
});
|
||||
|
||||
test("detached object methods work", () => {
|
||||
const schema = z.object({ a: z.string(), b: z.number() });
|
||||
|
||||
const pick = schema.pick;
|
||||
const omit = schema.omit;
|
||||
const partial = schema.partial;
|
||||
const extend = schema.extend;
|
||||
|
||||
expect(Object.keys(pick({ a: true })._zod.def.shape)).toEqual(["a"]);
|
||||
expect(Object.keys(omit({ a: true })._zod.def.shape)).toEqual(["b"]);
|
||||
expect(partial().safeParse({}).success).toBe(true);
|
||||
const extended = extend({ c: z.boolean() });
|
||||
expect(Object.keys(extended._zod.def.shape).sort()).toEqual(["a", "b", "c"]);
|
||||
});
|
||||
|
||||
// Sweep across many builder methods at once. If any of them break with the
|
||||
// `const m = schema.foo; m(...)` pattern, this test will report which.
|
||||
test("broad sweep: detaching builder methods does not throw or produce a corrupt schema", () => {
|
||||
const stringSchema = z.string();
|
||||
const numberSchema = z.number();
|
||||
|
||||
const broken: Array<{ method: string; reason: string }> = [];
|
||||
|
||||
for (const [methodName, args] of Object.entries(probeArgs)) {
|
||||
const target: any = methodName in stringSchema ? stringSchema : methodName in numberSchema ? numberSchema : null;
|
||||
if (!target) continue;
|
||||
|
||||
const detached = target[methodName] as Function | undefined;
|
||||
if (typeof detached !== "function") continue;
|
||||
|
||||
try {
|
||||
const result = detached(...args);
|
||||
// If the detached call returned a schema, sanity-check it parses
|
||||
// its base type. (e.g. `optional()` should accept its inner type.)
|
||||
if (result && typeof result === "object" && "_zod" in result && typeof (result as any).safeParse === "function") {
|
||||
const probeValue = target === stringSchema ? "x" : 1;
|
||||
const r = (result as any).safeParse(probeValue);
|
||||
// success or a clean failure are both fine — we only fail on throw or
|
||||
// on a schema with corrupt internal state (innerType undefined etc).
|
||||
if (r === undefined || (typeof r === "object" && !("success" in r))) {
|
||||
broken.push({ method: methodName, reason: "safeParse returned malformed result" });
|
||||
}
|
||||
}
|
||||
} catch (err: any) {
|
||||
broken.push({ method: methodName, reason: err?.message ?? String(err) });
|
||||
}
|
||||
}
|
||||
|
||||
expect(broken).toEqual([]);
|
||||
});
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
import { afterEach, expect, test } from "vitest";
|
||||
import * as z from "zod/v4";
|
||||
import * as core from "zod/v4/core";
|
||||
|
||||
// `globalConfig` is attached to `globalThis.__zod_globalConfig` so that a
|
||||
// single config object is shared across CJS/ESM builds and across multiple
|
||||
// bundled copies of Zod in a monorepo. This mirrors the existing
|
||||
// `globalRegistry` -> `globalThis.__zod_globalRegistry` treatment.
|
||||
//
|
||||
// See #5789 for the footgun this fixes: users with both CJS and ESM
|
||||
// instances of Zod loaded had to call `z.config({ jitless: true })`
|
||||
// twice — once per instance — because each module-scope `globalConfig`
|
||||
// was a different object. With this change, one call updates state seen
|
||||
// by every loaded copy.
|
||||
|
||||
afterEach(() => {
|
||||
// Don't leak config mutations into other test files.
|
||||
delete core.globalConfig.jitless;
|
||||
});
|
||||
|
||||
test("globalConfig is singleton and attached to globalThis", () => {
|
||||
expect(core.globalConfig).toBe((globalThis as any).__zod_globalConfig);
|
||||
});
|
||||
|
||||
test("z.config writes are observed via globalThis.__zod_globalConfig", () => {
|
||||
z.config({ jitless: true });
|
||||
expect((globalThis as any).__zod_globalConfig.jitless).toBe(true);
|
||||
});
|
||||
|
||||
test("pre-set globalThis.__zod_globalConfig is preserved on import", () => {
|
||||
// Object identity is preserved across reloads of the module: anyone who
|
||||
// pre-populates `globalThis.__zod_globalConfig` before Zod loads (e.g.
|
||||
// an inline script before the bundle) keeps that exact object as the
|
||||
// source of truth. Mutating it directly is equivalent to z.config().
|
||||
const direct = (globalThis as any).__zod_globalConfig;
|
||||
direct.jitless = true;
|
||||
expect(core.globalConfig.jitless).toBe(true);
|
||||
expect(z.config()).toBe(core.globalConfig);
|
||||
});
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
import { expect, test } from "vitest";
|
||||
import * as z from "zod/v4";
|
||||
import * as core from "zod/v4/core";
|
||||
|
||||
const { allowsEval } = core.util;
|
||||
|
||||
// Regression test for the CSP feature-probe issue (#4461, #5414):
|
||||
// `allowsEval` used to always invoke `new Function("")` even when the
|
||||
// user had opted into `z.config({ jitless: true })`, producing a
|
||||
// `securitypolicyviolation` report on strict-CSP pages (no 'unsafe-eval')
|
||||
// that Chrome DevTools surfaces as an Issue.
|
||||
//
|
||||
// The fix: when `globalConfig.jitless` is true, `allowsEval.value`
|
||||
// returns `false` without triggering the probe. This test lives in its
|
||||
// own file because vitest isolates ESM graphs per file, so the cached
|
||||
// `allowsEval.value` is fresh and is never accessed before the config
|
||||
// mutation below.
|
||||
|
||||
test("globalConfig.jitless=true short-circuits the allowsEval probe", () => {
|
||||
// Set BEFORE first access to allowsEval.value — the getter is memoised
|
||||
// via `cached()`, so the contract is "configure at app entry".
|
||||
z.config({ jitless: true });
|
||||
|
||||
// Sanity: config is wired
|
||||
expect(core.globalConfig.jitless).toBe(true);
|
||||
|
||||
// Spy: if the probe were still attempted, `new Function("")` would be
|
||||
// called. Swap the global `Function` constructor with a throwing stub
|
||||
// and verify the stub is NEVER invoked.
|
||||
const origFunction = globalThis.Function;
|
||||
let probeAttempted = false;
|
||||
// @ts-expect-error assigning a stub to the Function global for the test
|
||||
globalThis.Function = function StubFunction(..._args: unknown[]): never {
|
||||
probeAttempted = true;
|
||||
throw new Error("allowsEval probe should have been skipped under jitless=true");
|
||||
};
|
||||
|
||||
try {
|
||||
expect(allowsEval.value).toBe(false);
|
||||
expect(probeAttempted).toBe(false);
|
||||
} finally {
|
||||
globalThis.Function = origFunction;
|
||||
// Restore config so other test files in the same worker see default
|
||||
delete core.globalConfig.jitless;
|
||||
}
|
||||
});
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
import { expect, test } from "vitest";
|
||||
import * as z from "zod/v4";
|
||||
|
||||
test("Georgian locale uses 'ველი' instead of 'სტრინგი'", () => {
|
||||
// Save original error map to restore later if needed, though tests are usually isolated or we can reset
|
||||
// const originalErrorMap = z.getErrorMap(); // z.getErrorMap might not exist, but let's assume isolation or just set it
|
||||
|
||||
z.setErrorMap(z.locales.ka().localeError);
|
||||
|
||||
// Test 1: Invalid type (Expected string, received number)
|
||||
const stringSchema = z.string();
|
||||
const numberResult = stringSchema.safeParse(123);
|
||||
expect(numberResult.success).toBe(false);
|
||||
if (!numberResult.success) {
|
||||
// Expected: "არასწორი შეყვანა: მოსალოდნელი ველი, მიღებული რიცხვი"
|
||||
expect(numberResult.error.issues[0].message).toBe("არასწორი შეყვანა: მოსალოდნელი ველი, მიღებული რიცხვი");
|
||||
}
|
||||
|
||||
// Test 2: Invalid base64
|
||||
const base64Schema = z.string().base64();
|
||||
const base64Result = base64Schema.safeParse("not base64!");
|
||||
expect(base64Result.success).toBe(false);
|
||||
if (!base64Result.success) {
|
||||
// Expected: "არასწორი base64-კოდირებული ველი"
|
||||
// "არასწორი ${FormatDictionary[_issue.format] ?? issue.format}"
|
||||
// FormatDictionary['base64'] is "base64-კოდირებული ველი"
|
||||
expect(base64Result.error.issues[0].message).toBe("არასწორი base64-კოდირებული ველი");
|
||||
}
|
||||
});
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import { expect, test } from "vitest";
|
||||
import * as z from "zod/v4";
|
||||
|
||||
test("Romanian locale uses 'șir' instead of 'string'", () => {
|
||||
z.setErrorMap(z.locales.ro().localeError);
|
||||
|
||||
// Test 1: Invalid type (Expected string, received number)
|
||||
const stringSchema = z.string();
|
||||
const numberResult = stringSchema.safeParse(123);
|
||||
expect(numberResult.success).toBe(false);
|
||||
if (!numberResult.success) {
|
||||
// Expected: "Intrare invalidă: așteptat șir, primit număr"
|
||||
expect(numberResult.error.issues[0].message).toBe("Intrare invalidă: așteptat șir, primit număr");
|
||||
}
|
||||
|
||||
// Test 2: Invalid base64
|
||||
const base64Schema = z.string().base64();
|
||||
const base64Result = base64Schema.safeParse("not base64!");
|
||||
expect(base64Result.success).toBe(false);
|
||||
if (!base64Result.success) {
|
||||
// Expected: "Format invalid: șir codat base64"
|
||||
expect(base64Result.error.issues[0].message).toBe("Format invalid: șir codat base64");
|
||||
}
|
||||
});
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
import { expectTypeOf, test } from "vitest";
|
||||
import * as z from "zod/v4";
|
||||
|
||||
test("ZodPreprocess<B> assignable to ZodPipe<$ZodTransform, B>", () => {
|
||||
const pre = z.preprocess((v) => v, z.string().optional());
|
||||
const _asPipe: z.ZodPipe<z.core.$ZodTransform, z.ZodOptional<z.ZodString>> = pre;
|
||||
const _asCorePipe: z.core.$ZodPipe<z.core.$ZodTransform, z.ZodOptional<z.ZodString>> = pre;
|
||||
expectTypeOf(_asPipe).toMatchTypeOf<z.ZodPipe>();
|
||||
expectTypeOf(_asCorePipe).toMatchTypeOf<z.core.$ZodPipe>();
|
||||
});
|
||||
|
||||
test("ZodPreprocess optin/optout defer to B", () => {
|
||||
const optionalInside = z.preprocess((v) => v, z.string().optional());
|
||||
expectTypeOf<(typeof optionalInside)["_zod"]["optin"]>().toEqualTypeOf<"optional">();
|
||||
expectTypeOf<(typeof optionalInside)["_zod"]["optout"]>().toEqualTypeOf<"optional">();
|
||||
|
||||
const required = z.preprocess((v) => v, z.string());
|
||||
expectTypeOf<(typeof required)["_zod"]["optin"]>().toEqualTypeOf<"optional" | undefined>();
|
||||
expectTypeOf<(typeof required)["_zod"]["optout"]>().toEqualTypeOf<"optional" | undefined>();
|
||||
});
|
||||
|
||||
test("ZodPreprocess input/output inference", () => {
|
||||
const pre = z.preprocess((v) => v, z.number().optional());
|
||||
expectTypeOf<z.output<typeof pre>>().toEqualTypeOf<number | undefined>();
|
||||
expectTypeOf<z.input<typeof pre>>().toEqualTypeOf<unknown>();
|
||||
});
|
||||
+215
@@ -0,0 +1,215 @@
|
||||
import { expect, test } from "vitest";
|
||||
import { z } from "../../../../index.js";
|
||||
import el from "../../../locales/el.js";
|
||||
|
||||
test("Greek locale - too_small errors", () => {
|
||||
z.config(el());
|
||||
|
||||
// Test string type translation
|
||||
const stringSchema = z.string().min(5);
|
||||
const stringResult = stringSchema.safeParse("abc");
|
||||
expect(stringResult.success).toBe(false);
|
||||
if (!stringResult.success) {
|
||||
expect(stringResult.error.issues[0].message).toBe("Πολύ μικρό: αναμενόταν string να έχει >=5 χαρακτήρες");
|
||||
}
|
||||
|
||||
// Test number type translation
|
||||
const numberSchema = z.number().min(10);
|
||||
const numberResult = numberSchema.safeParse(5);
|
||||
expect(numberResult.success).toBe(false);
|
||||
if (!numberResult.success) {
|
||||
expect(numberResult.error.issues[0].message).toBe("Πολύ μικρό: αναμενόταν number να είναι >=10");
|
||||
}
|
||||
|
||||
// Test array type translation
|
||||
const arraySchema = z.array(z.string()).min(3);
|
||||
const arrayResult = arraySchema.safeParse(["a", "b"]);
|
||||
expect(arrayResult.success).toBe(false);
|
||||
if (!arrayResult.success) {
|
||||
expect(arrayResult.error.issues[0].message).toBe("Πολύ μικρό: αναμενόταν array να έχει >=3 στοιχεία");
|
||||
}
|
||||
|
||||
// Test set type translation
|
||||
const setSchema = z.set(z.string()).min(2);
|
||||
const setResult = setSchema.safeParse(new Set(["a"]));
|
||||
expect(setResult.success).toBe(false);
|
||||
if (!setResult.success) {
|
||||
expect(setResult.error.issues[0].message).toBe("Πολύ μικρό: αναμενόταν set να έχει >=2 στοιχεία");
|
||||
}
|
||||
});
|
||||
|
||||
test("Greek locale - too_big errors", () => {
|
||||
z.config(el());
|
||||
|
||||
// Test string type translation
|
||||
const stringSchema = z.string().max(3);
|
||||
const stringResult = stringSchema.safeParse("abcde");
|
||||
expect(stringResult.success).toBe(false);
|
||||
if (!stringResult.success) {
|
||||
expect(stringResult.error.issues[0].message).toBe("Πολύ μεγάλο: αναμενόταν string να έχει <=3 χαρακτήρες");
|
||||
}
|
||||
|
||||
// Test number type translation
|
||||
const numberSchema = z.number().max(10);
|
||||
const numberResult = numberSchema.safeParse(15);
|
||||
expect(numberResult.success).toBe(false);
|
||||
if (!numberResult.success) {
|
||||
expect(numberResult.error.issues[0].message).toBe("Πολύ μεγάλο: αναμενόταν number να είναι <=10");
|
||||
}
|
||||
|
||||
// Test array type translation
|
||||
const arraySchema = z.array(z.string()).max(2);
|
||||
const arrayResult = arraySchema.safeParse(["a", "b", "c"]);
|
||||
expect(arrayResult.success).toBe(false);
|
||||
if (!arrayResult.success) {
|
||||
expect(arrayResult.error.issues[0].message).toBe("Πολύ μεγάλο: αναμενόταν array να έχει <=2 στοιχεία");
|
||||
}
|
||||
});
|
||||
|
||||
test("Greek locale - invalid_type errors", () => {
|
||||
z.config(el());
|
||||
|
||||
// Test string expected, number received
|
||||
const stringSchema = z.string();
|
||||
const stringResult = stringSchema.safeParse(123);
|
||||
expect(stringResult.success).toBe(false);
|
||||
if (!stringResult.success) {
|
||||
expect(stringResult.error.issues[0].message).toBe("Μη έγκυρη είσοδος: αναμενόταν string, λήφθηκε number");
|
||||
}
|
||||
|
||||
// Test number expected, string received
|
||||
const numberSchema = z.number();
|
||||
const numberResult = numberSchema.safeParse("abc");
|
||||
expect(numberResult.success).toBe(false);
|
||||
if (!numberResult.success) {
|
||||
expect(numberResult.error.issues[0].message).toBe("Μη έγκυρη είσοδος: αναμενόταν number, λήφθηκε string");
|
||||
}
|
||||
|
||||
// Test boolean expected, null received
|
||||
const booleanSchema = z.boolean();
|
||||
const booleanResult = booleanSchema.safeParse(null);
|
||||
expect(booleanResult.success).toBe(false);
|
||||
if (!booleanResult.success) {
|
||||
expect(booleanResult.error.issues[0].message).toBe("Μη έγκυρη είσοδος: αναμενόταν boolean, λήφθηκε null");
|
||||
}
|
||||
|
||||
// Test array expected, object received
|
||||
const arraySchema = z.array(z.string());
|
||||
const arrayResult = arraySchema.safeParse({});
|
||||
expect(arrayResult.success).toBe(false);
|
||||
if (!arrayResult.success) {
|
||||
expect(arrayResult.error.issues[0].message).toBe("Μη έγκυρη είσοδος: αναμενόταν array, λήφθηκε object");
|
||||
}
|
||||
});
|
||||
|
||||
test("Greek locale - other error cases", () => {
|
||||
z.config(el());
|
||||
|
||||
// Test invalid_element with map (only "map" | "set" produce invalid_element)
|
||||
const mapSchema = z.map(z.bigint(), z.number());
|
||||
const mapResult = mapSchema.safeParse(new Map([[BigInt(123), BigInt(123)]]));
|
||||
expect(mapResult.success).toBe(false);
|
||||
if (!mapResult.success) {
|
||||
expect(mapResult.error.issues[0].code).toBe("invalid_element");
|
||||
expect(mapResult.error.issues[0].message).toBe("Μη έγκυρη τιμή στο map");
|
||||
}
|
||||
|
||||
// Test invalid_key with record (only "map" | "record" produce invalid_key)
|
||||
const recordSchema = z.record(z.number(), z.string());
|
||||
const recordResult = recordSchema.safeParse({ notANumber: "value" });
|
||||
expect(recordResult.success).toBe(false);
|
||||
if (!recordResult.success) {
|
||||
expect(recordResult.error.issues[0].code).toBe("invalid_key");
|
||||
expect(recordResult.error.issues[0].message).toBe("Μη έγκυρο κλειδί στο record");
|
||||
}
|
||||
|
||||
// Test invalid_value with enum
|
||||
const enumSchema = z.enum(["a", "b"]);
|
||||
const enumResult = enumSchema.safeParse("c");
|
||||
expect(enumResult.success).toBe(false);
|
||||
if (!enumResult.success) {
|
||||
expect(enumResult.error.issues[0].message).toBe('Μη έγκυρη επιλογή: αναμενόταν ένα από "a"|"b"');
|
||||
}
|
||||
|
||||
// Test not_multiple_of
|
||||
const multipleSchema = z.number().multipleOf(3);
|
||||
const multipleResult = multipleSchema.safeParse(10);
|
||||
expect(multipleResult.success).toBe(false);
|
||||
if (!multipleResult.success) {
|
||||
expect(multipleResult.error.issues[0].message).toBe("Μη έγκυρος αριθμός: πρέπει να είναι πολλαπλάσιο του 3");
|
||||
}
|
||||
|
||||
// Test unrecognized_keys (single key)
|
||||
const strictSchema = z.object({ a: z.string() }).strict();
|
||||
const strictResult = strictSchema.safeParse({ a: "test", b: "extra" });
|
||||
expect(strictResult.success).toBe(false);
|
||||
if (!strictResult.success) {
|
||||
expect(strictResult.error.issues[0].message).toBe('Άγνωστο κλειδί: "b"');
|
||||
}
|
||||
|
||||
// Test unrecognized_keys (multiple keys)
|
||||
const strictMultipleResult = strictSchema.safeParse({
|
||||
a: "test",
|
||||
b: "extra",
|
||||
c: "another",
|
||||
});
|
||||
expect(strictMultipleResult.success).toBe(false);
|
||||
if (!strictMultipleResult.success) {
|
||||
expect(strictMultipleResult.error.issues[0].message).toBe('Άγνωστα κλειδιά: "b", "c"');
|
||||
}
|
||||
|
||||
// Test invalid_union
|
||||
const unionSchema = z.union([z.string(), z.number()]);
|
||||
const unionResult = unionSchema.safeParse(true);
|
||||
expect(unionResult.success).toBe(false);
|
||||
if (!unionResult.success) {
|
||||
expect(unionResult.error.issues[0].message).toBe("Μη έγκυρη είσοδος");
|
||||
}
|
||||
|
||||
// Test invalid_format with regex
|
||||
const regexSchema = z.string().regex(/^[a-z]+$/);
|
||||
const regexResult = regexSchema.safeParse("ABC123");
|
||||
expect(regexResult.success).toBe(false);
|
||||
if (!regexResult.success) {
|
||||
expect(regexResult.error.issues[0].message).toBe(
|
||||
"Μη έγκυρη συμβολοσειρά: πρέπει να ταιριάζει με το μοτίβο /^[a-z]+$/"
|
||||
);
|
||||
}
|
||||
|
||||
// Test invalid_format with startsWith
|
||||
const startsWithSchema = z.string().startsWith("hello");
|
||||
const startsWithResult = startsWithSchema.safeParse("world");
|
||||
expect(startsWithResult.success).toBe(false);
|
||||
if (!startsWithResult.success) {
|
||||
expect(startsWithResult.error.issues[0].message).toBe('Μη έγκυρη συμβολοσειρά: πρέπει να ξεκινά με "hello"');
|
||||
}
|
||||
|
||||
// Test invalid_format with endsWith
|
||||
const endsWithSchema = z.string().endsWith("world");
|
||||
const endsWithResult = endsWithSchema.safeParse("hello");
|
||||
expect(endsWithResult.success).toBe(false);
|
||||
if (!endsWithResult.success) {
|
||||
expect(endsWithResult.error.issues[0].message).toBe('Μη έγκυρη συμβολοσειρά: πρέπει να τελειώνει με "world"');
|
||||
}
|
||||
|
||||
// Test invalid_format with includes
|
||||
const includesSchema = z.string().includes("test");
|
||||
const includesResult = includesSchema.safeParse("hello");
|
||||
expect(includesResult.success).toBe(false);
|
||||
if (!includesResult.success) {
|
||||
expect(includesResult.error.issues[0].message).toBe('Μη έγκυρη συμβολοσειρά: πρέπει να περιέχει "test"');
|
||||
}
|
||||
});
|
||||
|
||||
test("Greek locale - invalid_type with instanceof (class-name expected)", () => {
|
||||
z.config(el());
|
||||
|
||||
// When `expected` starts with a capital letter, render an `instanceof` message,
|
||||
// matching the convention used by most other locales (de, es, fr, it, etc.).
|
||||
const dateSchema = z.instanceof(Date);
|
||||
const dateResult = dateSchema.safeParse("not a date");
|
||||
expect(dateResult.success).toBe(false);
|
||||
if (!dateResult.success) {
|
||||
expect(dateResult.error.issues[0].message).toBe("Μη έγκυρη είσοδος: αναμενόταν instanceof Date, λήφθηκε string");
|
||||
}
|
||||
});
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
import { expect, test } from "vitest";
|
||||
import { z } from "../../../../index.js";
|
||||
import fr from "../../../locales/fr.js";
|
||||
|
||||
test("French locale - type name translations in too_small errors", () => {
|
||||
z.config(fr());
|
||||
|
||||
const stringResult = z.string().min(5).safeParse("abc");
|
||||
expect(stringResult.success).toBe(false);
|
||||
if (!stringResult.success) {
|
||||
expect(stringResult.error.issues[0].message).toBe("Trop petit : chaîne doit avoir >=5 caractères");
|
||||
}
|
||||
|
||||
const numberResult = z.number().min(10).safeParse(5);
|
||||
expect(numberResult.success).toBe(false);
|
||||
if (!numberResult.success) {
|
||||
expect(numberResult.error.issues[0].message).toBe("Trop petit : nombre doit être >=10");
|
||||
}
|
||||
|
||||
const arrayResult = z.array(z.string()).min(3).safeParse(["a", "b"]);
|
||||
expect(arrayResult.success).toBe(false);
|
||||
if (!arrayResult.success) {
|
||||
expect(arrayResult.error.issues[0].message).toBe("Trop petit : tableau doit avoir >=3 éléments");
|
||||
}
|
||||
|
||||
const setResult = z
|
||||
.set(z.string())
|
||||
.min(2)
|
||||
.safeParse(new Set(["a"]));
|
||||
expect(setResult.success).toBe(false);
|
||||
if (!setResult.success) {
|
||||
expect(setResult.error.issues[0].message).toBe("Trop petit : ensemble doit avoir >=2 éléments");
|
||||
}
|
||||
});
|
||||
|
||||
test("French locale - type name translations in too_big errors", () => {
|
||||
z.config(fr());
|
||||
|
||||
const stringResult = z.string().max(3).safeParse("abcde");
|
||||
expect(stringResult.success).toBe(false);
|
||||
if (!stringResult.success) {
|
||||
expect(stringResult.error.issues[0].message).toBe("Trop grand : chaîne doit avoir <=3 caractères");
|
||||
}
|
||||
|
||||
const numberResult = z.number().max(10).safeParse(15);
|
||||
expect(numberResult.success).toBe(false);
|
||||
if (!numberResult.success) {
|
||||
expect(numberResult.error.issues[0].message).toBe("Trop grand : nombre doit être <=10");
|
||||
}
|
||||
|
||||
const arrayResult = z.array(z.string()).max(2).safeParse(["a", "b", "c"]);
|
||||
expect(arrayResult.success).toBe(false);
|
||||
if (!arrayResult.success) {
|
||||
expect(arrayResult.error.issues[0].message).toBe("Trop grand : tableau doit avoir <=2 éléments");
|
||||
}
|
||||
});
|
||||
|
||||
test("French locale - type name translations in invalid_type errors", () => {
|
||||
z.config(fr());
|
||||
|
||||
const stringResult = z.string().safeParse(123);
|
||||
expect(stringResult.success).toBe(false);
|
||||
if (!stringResult.success) {
|
||||
expect(stringResult.error.issues[0].message).toBe("Entrée invalide : chaîne attendu, nombre reçu");
|
||||
}
|
||||
|
||||
const arrayResult = z.array(z.string()).safeParse({});
|
||||
expect(arrayResult.success).toBe(false);
|
||||
if (!arrayResult.success) {
|
||||
expect(arrayResult.error.issues[0].message).toBe("Entrée invalide : tableau attendu, objet reçu");
|
||||
}
|
||||
});
|
||||
+163
@@ -0,0 +1,163 @@
|
||||
import { expect, test } from "vitest";
|
||||
import { z } from "../../../../index.js";
|
||||
import hr from "../../../locales/hr.js";
|
||||
|
||||
test("Croatian locale - type name translations in too_small errors", () => {
|
||||
z.config(hr());
|
||||
|
||||
// Test string type translation
|
||||
const stringSchema = z.string().min(5);
|
||||
const stringResult = stringSchema.safeParse("abc");
|
||||
expect(stringResult.success).toBe(false);
|
||||
if (!stringResult.success) {
|
||||
expect(stringResult.error.issues[0].message).toBe("Premalo: očekivano da tekst ima >=5 znakova");
|
||||
}
|
||||
|
||||
// Test number type translation
|
||||
const numberSchema = z.number().min(10);
|
||||
const numberResult = numberSchema.safeParse(5);
|
||||
expect(numberResult.success).toBe(false);
|
||||
if (!numberResult.success) {
|
||||
expect(numberResult.error.issues[0].message).toBe("Premalo: očekivano da broj bude >=10");
|
||||
}
|
||||
|
||||
// Test array type translation
|
||||
const arraySchema = z.array(z.string()).min(3);
|
||||
const arrayResult = arraySchema.safeParse(["a", "b"]);
|
||||
expect(arrayResult.success).toBe(false);
|
||||
if (!arrayResult.success) {
|
||||
expect(arrayResult.error.issues[0].message).toBe("Premalo: očekivano da niz ima >=3 stavki");
|
||||
}
|
||||
|
||||
// Test set type translation
|
||||
const setSchema = z.set(z.string()).min(2);
|
||||
const setResult = setSchema.safeParse(new Set(["a"]));
|
||||
expect(setResult.success).toBe(false);
|
||||
if (!setResult.success) {
|
||||
expect(setResult.error.issues[0].message).toBe("Premalo: očekivano da skup ima >=2 stavki");
|
||||
}
|
||||
});
|
||||
|
||||
test("Croatian locale - type name translations in too_big errors", () => {
|
||||
z.config(hr());
|
||||
|
||||
// Test string type translation
|
||||
const stringSchema = z.string().max(3);
|
||||
const stringResult = stringSchema.safeParse("abcde");
|
||||
expect(stringResult.success).toBe(false);
|
||||
if (!stringResult.success) {
|
||||
expect(stringResult.error.issues[0].message).toBe("Preveliko: očekivano da tekst ima <=3 znakova");
|
||||
}
|
||||
|
||||
// Test number type translation
|
||||
const numberSchema = z.number().max(10);
|
||||
const numberResult = numberSchema.safeParse(15);
|
||||
expect(numberResult.success).toBe(false);
|
||||
if (!numberResult.success) {
|
||||
expect(numberResult.error.issues[0].message).toBe("Preveliko: očekivano da broj bude <=10");
|
||||
}
|
||||
|
||||
// Test array type translation
|
||||
const arraySchema = z.array(z.string()).max(2);
|
||||
const arrayResult = arraySchema.safeParse(["a", "b", "c"]);
|
||||
expect(arrayResult.success).toBe(false);
|
||||
if (!arrayResult.success) {
|
||||
expect(arrayResult.error.issues[0].message).toBe("Preveliko: očekivano da niz ima <=2 stavki");
|
||||
}
|
||||
});
|
||||
|
||||
test("Croatian locale - type name translations in invalid_type errors", () => {
|
||||
z.config(hr());
|
||||
|
||||
// Test string expected, number received
|
||||
const stringSchema = z.string();
|
||||
const stringResult = stringSchema.safeParse(123);
|
||||
expect(stringResult.success).toBe(false);
|
||||
if (!stringResult.success) {
|
||||
expect(stringResult.error.issues[0].message).toBe("Neispravan unos: očekuje se tekst, a primljeno je broj");
|
||||
}
|
||||
|
||||
// Test number expected, string received
|
||||
const numberSchema = z.number();
|
||||
const numberResult = numberSchema.safeParse("abc");
|
||||
expect(numberResult.success).toBe(false);
|
||||
if (!numberResult.success) {
|
||||
expect(numberResult.error.issues[0].message).toBe("Neispravan unos: očekuje se broj, a primljeno je tekst");
|
||||
}
|
||||
|
||||
// Test boolean expected, null received
|
||||
const booleanSchema = z.boolean();
|
||||
const booleanResult = booleanSchema.safeParse(null);
|
||||
expect(booleanResult.success).toBe(false);
|
||||
if (!booleanResult.success) {
|
||||
expect(booleanResult.error.issues[0].message).toBe("Neispravan unos: očekuje se boolean, a primljeno je null");
|
||||
}
|
||||
|
||||
// Test array expected, object received
|
||||
const arraySchema = z.array(z.string());
|
||||
const arrayResult = arraySchema.safeParse({});
|
||||
expect(arrayResult.success).toBe(false);
|
||||
if (!arrayResult.success) {
|
||||
expect(arrayResult.error.issues[0].message).toBe("Neispravan unos: očekuje se niz, a primljeno je objekt");
|
||||
}
|
||||
});
|
||||
|
||||
test("Croatian locale - other error cases", () => {
|
||||
z.config(hr());
|
||||
|
||||
// Test invalid_element with tuple
|
||||
const tupleSchema = z.tuple([z.string(), z.number()]);
|
||||
const tupleResult = tupleSchema.safeParse(["abc", "not a number"]);
|
||||
expect(tupleResult.success).toBe(false);
|
||||
if (!tupleResult.success) {
|
||||
expect(tupleResult.error.issues[0].message).toContain("Neispravan unos");
|
||||
}
|
||||
|
||||
// Test invalid_value with enum
|
||||
const enumSchema = z.enum(["a", "b"]);
|
||||
const enumResult = enumSchema.safeParse("c");
|
||||
expect(enumResult.success).toBe(false);
|
||||
if (!enumResult.success) {
|
||||
expect(enumResult.error.issues[0].message).toBe('Neispravna opcija: očekivano jedno od "a"|"b"');
|
||||
}
|
||||
|
||||
// Test not_multiple_of
|
||||
const multipleSchema = z.number().multipleOf(3);
|
||||
const multipleResult = multipleSchema.safeParse(10);
|
||||
expect(multipleResult.success).toBe(false);
|
||||
if (!multipleResult.success) {
|
||||
expect(multipleResult.error.issues[0].message).toBe("Neispravan broj: mora biti višekratnik od 3");
|
||||
}
|
||||
|
||||
// Test unrecognized_keys
|
||||
const strictSchema = z.object({ a: z.string() }).strict();
|
||||
const strictResult = strictSchema.safeParse({ a: "test", b: "extra" });
|
||||
expect(strictResult.success).toBe(false);
|
||||
if (!strictResult.success) {
|
||||
expect(strictResult.error.issues[0].message).toBe('Neprepoznat ključ: "b"');
|
||||
}
|
||||
|
||||
// Test invalid_union
|
||||
const unionSchema = z.union([z.string(), z.number()]);
|
||||
const unionResult = unionSchema.safeParse(true);
|
||||
expect(unionResult.success).toBe(false);
|
||||
if (!unionResult.success) {
|
||||
expect(unionResult.error.issues[0].message).toBe("Neispravan unos");
|
||||
}
|
||||
|
||||
// Test invalid_format with regex
|
||||
const regexSchema = z.string().regex(/^[a-z]+$/);
|
||||
const regexResult = regexSchema.safeParse("ABC123");
|
||||
expect(regexResult.success).toBe(false);
|
||||
if (!regexResult.success) {
|
||||
expect(regexResult.error.issues[0].message).toBe("Neispravan tekst: mora odgovarati uzorku /^[a-z]+$/");
|
||||
}
|
||||
|
||||
// Test invalid_format with startsWith
|
||||
const startsWithSchema = z.string().startsWith("hello");
|
||||
const startsWithResult = startsWithSchema.safeParse("world");
|
||||
expect(startsWithResult.success).toBe(false);
|
||||
if (!startsWithResult.success) {
|
||||
expect(startsWithResult.error.issues[0].message).toBe('Neispravan tekst: mora započinjati s "hello"');
|
||||
}
|
||||
});
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
import type { $ZodStringFormats } from "../core/checks.js";
|
||||
import type * as errors from "../core/errors.js";
|
||||
import * as util from "../core/util.js";
|
||||
|
||||
const error: () => errors.$ZodErrorMap = () => {
|
||||
const Sizable: Record<string, { unit: string; verb: string }> = {
|
||||
string: { unit: "χαρακτήρες", verb: "να έχει" },
|
||||
file: { unit: "bytes", verb: "να έχει" },
|
||||
array: { unit: "στοιχεία", verb: "να έχει" },
|
||||
set: { unit: "στοιχεία", verb: "να έχει" },
|
||||
map: { unit: "καταχωρήσεις", verb: "να έχει" },
|
||||
};
|
||||
|
||||
function getSizing(origin: string): { unit: string; verb: string } | null {
|
||||
return Sizable[origin] ?? null;
|
||||
}
|
||||
|
||||
const FormatDictionary: {
|
||||
[k in $ZodStringFormats | (string & {})]?: string;
|
||||
} = {
|
||||
regex: "είσοδος",
|
||||
email: "διεύθυνση 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",
|
||||
mac: "διεύθυνση MAC",
|
||||
cidrv4: "εύρος IPv4",
|
||||
cidrv6: "εύρος IPv6",
|
||||
base64: "συμβολοσειρά κωδικοποιημένη σε base64",
|
||||
base64url: "συμβολοσειρά κωδικοποιημένη σε base64url",
|
||||
json_string: "συμβολοσειρά JSON",
|
||||
e164: "αριθμός E.164",
|
||||
jwt: "JWT",
|
||||
template_literal: "είσοδος",
|
||||
};
|
||||
|
||||
const TypeDictionary: {
|
||||
[k in errors.$ZodInvalidTypeExpected | (string & {})]?: string;
|
||||
} = {
|
||||
nan: "NaN",
|
||||
};
|
||||
|
||||
return (issue) => {
|
||||
switch (issue.code) {
|
||||
case "invalid_type": {
|
||||
const expected = TypeDictionary[issue.expected] ?? issue.expected;
|
||||
const receivedType = util.parsedType(issue.input);
|
||||
const received = TypeDictionary[receivedType] ?? receivedType;
|
||||
if (typeof issue.expected === "string" && /^[A-Z]/.test(issue.expected)) {
|
||||
return `Μη έγκυρη είσοδος: αναμενόταν instanceof ${issue.expected}, λήφθηκε ${received}`;
|
||||
}
|
||||
return `Μη έγκυρη είσοδος: αναμενόταν ${expected}, λήφθηκε ${received}`;
|
||||
}
|
||||
|
||||
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 as errors.$ZodStringFormatIssues;
|
||||
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 `Μη έγκυρο: ${FormatDictionary[_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 (): { localeError: errors.$ZodErrorMap } {
|
||||
return {
|
||||
localeError: error(),
|
||||
};
|
||||
}
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
import type { $ZodStringFormats } from "../core/checks.js";
|
||||
import type * as errors from "../core/errors.js";
|
||||
import * as util from "../core/util.js";
|
||||
|
||||
const error: () => errors.$ZodErrorMap = () => {
|
||||
const Sizable: Record<string, { unit: string; verb: string }> = {
|
||||
string: { unit: "znakova", verb: "imati" },
|
||||
file: { unit: "bajtova", verb: "imati" },
|
||||
array: { unit: "stavki", verb: "imati" },
|
||||
set: { unit: "stavki", verb: "imati" },
|
||||
};
|
||||
|
||||
function getSizing(origin: string): { unit: string; verb: string } | null {
|
||||
return Sizable[origin] ?? null;
|
||||
}
|
||||
|
||||
const FormatDictionary: {
|
||||
[k in $ZodStringFormats | (string & {})]?: string;
|
||||
} = {
|
||||
regex: "unos",
|
||||
email: "email adresa",
|
||||
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 datum i vrijeme",
|
||||
date: "ISO datum",
|
||||
time: "ISO vrijeme",
|
||||
duration: "ISO trajanje",
|
||||
ipv4: "IPv4 adresa",
|
||||
ipv6: "IPv6 adresa",
|
||||
cidrv4: "IPv4 raspon",
|
||||
cidrv6: "IPv6 raspon",
|
||||
base64: "base64 kodirani tekst",
|
||||
base64url: "base64url kodirani tekst",
|
||||
json_string: "JSON tekst",
|
||||
e164: "E.164 broj",
|
||||
jwt: "JWT",
|
||||
template_literal: "unos",
|
||||
};
|
||||
|
||||
const TypeDictionary: {
|
||||
[k in errors.$ZodInvalidTypeExpected | (string & {})]?: string;
|
||||
} = {
|
||||
nan: "NaN",
|
||||
string: "tekst",
|
||||
number: "broj",
|
||||
boolean: "boolean",
|
||||
array: "niz",
|
||||
object: "objekt",
|
||||
set: "skup",
|
||||
file: "datoteka",
|
||||
date: "datum",
|
||||
bigint: "bigint",
|
||||
symbol: "simbol",
|
||||
undefined: "undefined",
|
||||
null: "null",
|
||||
function: "funkcija",
|
||||
map: "mapa",
|
||||
};
|
||||
|
||||
return (issue) => {
|
||||
switch (issue.code) {
|
||||
case "invalid_type": {
|
||||
const expected = TypeDictionary[issue.expected] ?? issue.expected;
|
||||
const receivedType = util.parsedType(issue.input);
|
||||
const received = TypeDictionary[receivedType] ?? receivedType;
|
||||
if (/^[A-Z]/.test(issue.expected)) {
|
||||
return `Neispravan unos: očekuje se instanceof ${issue.expected}, a primljeno je ${received}`;
|
||||
}
|
||||
return `Neispravan unos: očekuje se ${expected}, a primljeno je ${received}`;
|
||||
}
|
||||
case "invalid_value":
|
||||
if (issue.values.length === 1)
|
||||
return `Neispravna vrijednost: očekivano ${util.stringifyPrimitive(issue.values[0])}`;
|
||||
return `Neispravna opcija: očekivano jedno od ${util.joinValues(issue.values, "|")}`;
|
||||
case "too_big": {
|
||||
const adj = issue.inclusive ? "<=" : "<";
|
||||
const sizing = getSizing(issue.origin);
|
||||
const origin = TypeDictionary[issue.origin] ?? issue.origin;
|
||||
if (sizing)
|
||||
return `Preveliko: očekivano da ${origin ?? "vrijednost"} ima ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elemenata"}`;
|
||||
return `Preveliko: očekivano da ${origin ?? "vrijednost"} bude ${adj}${issue.maximum.toString()}`;
|
||||
}
|
||||
case "too_small": {
|
||||
const adj = issue.inclusive ? ">=" : ">";
|
||||
const sizing = getSizing(issue.origin);
|
||||
const origin = TypeDictionary[issue.origin] ?? issue.origin;
|
||||
if (sizing) {
|
||||
return `Premalo: očekivano da ${origin} ima ${adj}${issue.minimum.toString()} ${sizing.unit}`;
|
||||
}
|
||||
|
||||
return `Premalo: očekivano da ${origin} bude ${adj}${issue.minimum.toString()}`;
|
||||
}
|
||||
case "invalid_format": {
|
||||
const _issue = issue as errors.$ZodStringFormatIssues;
|
||||
if (_issue.format === "starts_with") return `Neispravan tekst: mora započinjati s "${_issue.prefix}"`;
|
||||
if (_issue.format === "ends_with") return `Neispravan tekst: mora završavati s "${_issue.suffix}"`;
|
||||
if (_issue.format === "includes") return `Neispravan tekst: mora sadržavati "${_issue.includes}"`;
|
||||
if (_issue.format === "regex") return `Neispravan tekst: mora odgovarati uzorku ${_issue.pattern}`;
|
||||
return `Neispravna ${FormatDictionary[_issue.format] ?? issue.format}`;
|
||||
}
|
||||
case "not_multiple_of":
|
||||
return `Neispravan broj: mora biti višekratnik od ${issue.divisor}`;
|
||||
case "unrecognized_keys":
|
||||
return `Neprepoznat${issue.keys.length > 1 ? "i ključevi" : " ključ"}: ${util.joinValues(issue.keys, ", ")}`;
|
||||
case "invalid_key":
|
||||
return `Neispravan ključ u ${TypeDictionary[issue.origin] ?? issue.origin}`;
|
||||
case "invalid_union":
|
||||
return "Neispravan unos";
|
||||
case "invalid_element":
|
||||
return `Neispravna vrijednost u ${TypeDictionary[issue.origin] ?? issue.origin}`;
|
||||
default:
|
||||
return `Neispravan unos`;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export default function (): { localeError: errors.$ZodErrorMap } {
|
||||
return {
|
||||
localeError: error(),
|
||||
};
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
import type { $ZodStringFormats } from "../core/checks.js";
|
||||
import type * as errors from "../core/errors.js";
|
||||
import * as util from "../core/util.js";
|
||||
|
||||
const error: () => errors.$ZodErrorMap = () => {
|
||||
const Sizable: Record<string, { unit: string; verb: string }> = {
|
||||
string: { unit: "caractere", verb: "să aibă" },
|
||||
file: { unit: "octeți", verb: "să aibă" },
|
||||
array: { unit: "elemente", verb: "să aibă" },
|
||||
set: { unit: "elemente", verb: "să aibă" },
|
||||
map: { unit: "intrări", verb: "să aibă" },
|
||||
};
|
||||
|
||||
function getSizing(origin: string): { unit: string; verb: string } | null {
|
||||
return Sizable[origin] ?? null;
|
||||
}
|
||||
|
||||
const FormatDictionary: {
|
||||
[k in $ZodStringFormats | (string & {})]?: string;
|
||||
} = {
|
||||
regex: "intrare",
|
||||
email: "adresă de 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: "dată și oră ISO",
|
||||
date: "dată ISO",
|
||||
time: "oră ISO",
|
||||
duration: "durată ISO",
|
||||
ipv4: "adresă IPv4",
|
||||
ipv6: "adresă IPv6",
|
||||
mac: "adresă MAC",
|
||||
cidrv4: "interval IPv4",
|
||||
cidrv6: "interval IPv6",
|
||||
base64: "șir codat base64",
|
||||
base64url: "șir codat base64url",
|
||||
json_string: "șir JSON",
|
||||
e164: "număr E.164",
|
||||
jwt: "JWT",
|
||||
template_literal: "intrare",
|
||||
};
|
||||
|
||||
const TypeDictionary: {
|
||||
[k in errors.$ZodInvalidTypeExpected | (string & {})]?: string;
|
||||
} = {
|
||||
nan: "NaN",
|
||||
string: "șir",
|
||||
number: "număr",
|
||||
boolean: "boolean",
|
||||
function: "funcție",
|
||||
array: "matrice",
|
||||
object: "obiect",
|
||||
undefined: "nedefinit",
|
||||
symbol: "simbol",
|
||||
bigint: "număr mare",
|
||||
void: "void",
|
||||
never: "never",
|
||||
map: "hartă",
|
||||
set: "set",
|
||||
};
|
||||
|
||||
return (issue) => {
|
||||
switch (issue.code) {
|
||||
case "invalid_type": {
|
||||
const expected = TypeDictionary[issue.expected] ?? issue.expected;
|
||||
const receivedType = util.parsedType(issue.input);
|
||||
const received = TypeDictionary[receivedType] ?? receivedType;
|
||||
return `Intrare invalidă: așteptat ${expected}, primit ${received}`;
|
||||
}
|
||||
|
||||
case "invalid_value":
|
||||
if (issue.values.length === 1) return `Intrare invalidă: așteptat ${util.stringifyPrimitive(issue.values[0])}`;
|
||||
return `Opțiune invalidă: așteptat una dintre ${util.joinValues(issue.values, "|")}`;
|
||||
case "too_big": {
|
||||
const adj = issue.inclusive ? "<=" : "<";
|
||||
const sizing = getSizing(issue.origin);
|
||||
if (sizing)
|
||||
return `Prea mare: așteptat ca ${issue.origin ?? "valoarea"} ${sizing.verb} ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elemente"}`;
|
||||
return `Prea mare: așteptat ca ${issue.origin ?? "valoarea"} să fie ${adj}${issue.maximum.toString()}`;
|
||||
}
|
||||
case "too_small": {
|
||||
const adj = issue.inclusive ? ">=" : ">";
|
||||
const sizing = getSizing(issue.origin);
|
||||
if (sizing) {
|
||||
return `Prea mic: așteptat ca ${issue.origin} ${sizing.verb} ${adj}${issue.minimum.toString()} ${sizing.unit}`;
|
||||
}
|
||||
|
||||
return `Prea mic: așteptat ca ${issue.origin} să fie ${adj}${issue.minimum.toString()}`;
|
||||
}
|
||||
case "invalid_format": {
|
||||
const _issue = issue as errors.$ZodStringFormatIssues;
|
||||
if (_issue.format === "starts_with") {
|
||||
return `Șir invalid: trebuie să înceapă cu "${_issue.prefix}"`;
|
||||
}
|
||||
if (_issue.format === "ends_with") return `Șir invalid: trebuie să se termine cu "${_issue.suffix}"`;
|
||||
if (_issue.format === "includes") return `Șir invalid: trebuie să includă "${_issue.includes}"`;
|
||||
if (_issue.format === "regex") return `Șir invalid: trebuie să se potrivească cu modelul ${_issue.pattern}`;
|
||||
return `Format invalid: ${FormatDictionary[_issue.format] ?? issue.format}`;
|
||||
}
|
||||
case "not_multiple_of":
|
||||
return `Număr invalid: trebuie să fie multiplu de ${issue.divisor}`;
|
||||
case "unrecognized_keys":
|
||||
return `Chei nerecunoscute: ${util.joinValues(issue.keys, ", ")}`;
|
||||
case "invalid_key":
|
||||
return `Cheie invalidă în ${issue.origin}`;
|
||||
case "invalid_union":
|
||||
return "Intrare invalidă";
|
||||
case "invalid_element":
|
||||
return `Valoare invalidă în ${issue.origin}`;
|
||||
default:
|
||||
return `Intrare invalidă`;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export default function (): { localeError: errors.$ZodErrorMap } {
|
||||
return {
|
||||
localeError: error(),
|
||||
};
|
||||
}
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
"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: "bytes", verb: "να έχει" },
|
||||
array: { unit: "στοιχεία", verb: "να έχει" },
|
||||
set: { unit: "στοιχεία", verb: "να έχει" },
|
||||
map: { unit: "καταχωρήσεις", verb: "να έχει" },
|
||||
};
|
||||
function getSizing(origin) {
|
||||
return Sizable[origin] ?? null;
|
||||
}
|
||||
const FormatDictionary = {
|
||||
regex: "είσοδος",
|
||||
email: "διεύθυνση 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",
|
||||
mac: "διεύθυνση MAC",
|
||||
cidrv4: "εύρος IPv4",
|
||||
cidrv6: "εύρος IPv6",
|
||||
base64: "συμβολοσειρά κωδικοποιημένη σε base64",
|
||||
base64url: "συμβολοσειρά κωδικοποιημένη σε base64url",
|
||||
json_string: "συμβολοσειρά JSON",
|
||||
e164: "αριθμός E.164",
|
||||
jwt: "JWT",
|
||||
template_literal: "είσοδος",
|
||||
};
|
||||
const TypeDictionary = {
|
||||
nan: "NaN",
|
||||
};
|
||||
return (issue) => {
|
||||
switch (issue.code) {
|
||||
case "invalid_type": {
|
||||
const expected = TypeDictionary[issue.expected] ?? issue.expected;
|
||||
const receivedType = util.parsedType(issue.input);
|
||||
const received = TypeDictionary[receivedType] ?? receivedType;
|
||||
if (typeof issue.expected === "string" && /^[A-Z]/.test(issue.expected)) {
|
||||
return `Μη έγκυρη είσοδος: αναμενόταν instanceof ${issue.expected}, λήφθηκε ${received}`;
|
||||
}
|
||||
return `Μη έγκυρη είσοδος: αναμενόταν ${expected}, λήφθηκε ${received}`;
|
||||
}
|
||||
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 `Μη έγκυρο: ${FormatDictionary[_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 `Μη έγκυρη είσοδος`;
|
||||
}
|
||||
};
|
||||
};
|
||||
function default_1() {
|
||||
return {
|
||||
localeError: error(),
|
||||
};
|
||||
}
|
||||
module.exports = exports.default;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import type * as errors from "../core/errors.cjs";
|
||||
declare function _default(): {
|
||||
localeError: errors.$ZodErrorMap;
|
||||
};
|
||||
export = _default;
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type * as errors from "../core/errors.js";
|
||||
export default function (): {
|
||||
localeError: errors.$ZodErrorMap;
|
||||
};
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
import * as util from "../core/util.js";
|
||||
const error = () => {
|
||||
const Sizable = {
|
||||
string: { unit: "χαρακτήρες", verb: "να έχει" },
|
||||
file: { unit: "bytes", verb: "να έχει" },
|
||||
array: { unit: "στοιχεία", verb: "να έχει" },
|
||||
set: { unit: "στοιχεία", verb: "να έχει" },
|
||||
map: { unit: "καταχωρήσεις", verb: "να έχει" },
|
||||
};
|
||||
function getSizing(origin) {
|
||||
return Sizable[origin] ?? null;
|
||||
}
|
||||
const FormatDictionary = {
|
||||
regex: "είσοδος",
|
||||
email: "διεύθυνση 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",
|
||||
mac: "διεύθυνση MAC",
|
||||
cidrv4: "εύρος IPv4",
|
||||
cidrv6: "εύρος IPv6",
|
||||
base64: "συμβολοσειρά κωδικοποιημένη σε base64",
|
||||
base64url: "συμβολοσειρά κωδικοποιημένη σε base64url",
|
||||
json_string: "συμβολοσειρά JSON",
|
||||
e164: "αριθμός E.164",
|
||||
jwt: "JWT",
|
||||
template_literal: "είσοδος",
|
||||
};
|
||||
const TypeDictionary = {
|
||||
nan: "NaN",
|
||||
};
|
||||
return (issue) => {
|
||||
switch (issue.code) {
|
||||
case "invalid_type": {
|
||||
const expected = TypeDictionary[issue.expected] ?? issue.expected;
|
||||
const receivedType = util.parsedType(issue.input);
|
||||
const received = TypeDictionary[receivedType] ?? receivedType;
|
||||
if (typeof issue.expected === "string" && /^[A-Z]/.test(issue.expected)) {
|
||||
return `Μη έγκυρη είσοδος: αναμενόταν instanceof ${issue.expected}, λήφθηκε ${received}`;
|
||||
}
|
||||
return `Μη έγκυρη είσοδος: αναμενόταν ${expected}, λήφθηκε ${received}`;
|
||||
}
|
||||
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 `Μη έγκυρο: ${FormatDictionary[_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(),
|
||||
};
|
||||
}
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
"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: "znakova", verb: "imati" },
|
||||
file: { unit: "bajtova", verb: "imati" },
|
||||
array: { unit: "stavki", verb: "imati" },
|
||||
set: { unit: "stavki", verb: "imati" },
|
||||
};
|
||||
function getSizing(origin) {
|
||||
return Sizable[origin] ?? null;
|
||||
}
|
||||
const FormatDictionary = {
|
||||
regex: "unos",
|
||||
email: "email adresa",
|
||||
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 datum i vrijeme",
|
||||
date: "ISO datum",
|
||||
time: "ISO vrijeme",
|
||||
duration: "ISO trajanje",
|
||||
ipv4: "IPv4 adresa",
|
||||
ipv6: "IPv6 adresa",
|
||||
cidrv4: "IPv4 raspon",
|
||||
cidrv6: "IPv6 raspon",
|
||||
base64: "base64 kodirani tekst",
|
||||
base64url: "base64url kodirani tekst",
|
||||
json_string: "JSON tekst",
|
||||
e164: "E.164 broj",
|
||||
jwt: "JWT",
|
||||
template_literal: "unos",
|
||||
};
|
||||
const TypeDictionary = {
|
||||
nan: "NaN",
|
||||
string: "tekst",
|
||||
number: "broj",
|
||||
boolean: "boolean",
|
||||
array: "niz",
|
||||
object: "objekt",
|
||||
set: "skup",
|
||||
file: "datoteka",
|
||||
date: "datum",
|
||||
bigint: "bigint",
|
||||
symbol: "simbol",
|
||||
undefined: "undefined",
|
||||
null: "null",
|
||||
function: "funkcija",
|
||||
map: "mapa",
|
||||
};
|
||||
return (issue) => {
|
||||
switch (issue.code) {
|
||||
case "invalid_type": {
|
||||
const expected = TypeDictionary[issue.expected] ?? issue.expected;
|
||||
const receivedType = util.parsedType(issue.input);
|
||||
const received = TypeDictionary[receivedType] ?? receivedType;
|
||||
if (/^[A-Z]/.test(issue.expected)) {
|
||||
return `Neispravan unos: očekuje se instanceof ${issue.expected}, a primljeno je ${received}`;
|
||||
}
|
||||
return `Neispravan unos: očekuje se ${expected}, a primljeno je ${received}`;
|
||||
}
|
||||
case "invalid_value":
|
||||
if (issue.values.length === 1)
|
||||
return `Neispravna vrijednost: očekivano ${util.stringifyPrimitive(issue.values[0])}`;
|
||||
return `Neispravna opcija: očekivano jedno od ${util.joinValues(issue.values, "|")}`;
|
||||
case "too_big": {
|
||||
const adj = issue.inclusive ? "<=" : "<";
|
||||
const sizing = getSizing(issue.origin);
|
||||
const origin = TypeDictionary[issue.origin] ?? issue.origin;
|
||||
if (sizing)
|
||||
return `Preveliko: očekivano da ${origin ?? "vrijednost"} ima ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elemenata"}`;
|
||||
return `Preveliko: očekivano da ${origin ?? "vrijednost"} bude ${adj}${issue.maximum.toString()}`;
|
||||
}
|
||||
case "too_small": {
|
||||
const adj = issue.inclusive ? ">=" : ">";
|
||||
const sizing = getSizing(issue.origin);
|
||||
const origin = TypeDictionary[issue.origin] ?? issue.origin;
|
||||
if (sizing) {
|
||||
return `Premalo: očekivano da ${origin} ima ${adj}${issue.minimum.toString()} ${sizing.unit}`;
|
||||
}
|
||||
return `Premalo: očekivano da ${origin} bude ${adj}${issue.minimum.toString()}`;
|
||||
}
|
||||
case "invalid_format": {
|
||||
const _issue = issue;
|
||||
if (_issue.format === "starts_with")
|
||||
return `Neispravan tekst: mora započinjati s "${_issue.prefix}"`;
|
||||
if (_issue.format === "ends_with")
|
||||
return `Neispravan tekst: mora završavati s "${_issue.suffix}"`;
|
||||
if (_issue.format === "includes")
|
||||
return `Neispravan tekst: mora sadržavati "${_issue.includes}"`;
|
||||
if (_issue.format === "regex")
|
||||
return `Neispravan tekst: mora odgovarati uzorku ${_issue.pattern}`;
|
||||
return `Neispravna ${FormatDictionary[_issue.format] ?? issue.format}`;
|
||||
}
|
||||
case "not_multiple_of":
|
||||
return `Neispravan broj: mora biti višekratnik od ${issue.divisor}`;
|
||||
case "unrecognized_keys":
|
||||
return `Neprepoznat${issue.keys.length > 1 ? "i ključevi" : " ključ"}: ${util.joinValues(issue.keys, ", ")}`;
|
||||
case "invalid_key":
|
||||
return `Neispravan ključ u ${TypeDictionary[issue.origin] ?? issue.origin}`;
|
||||
case "invalid_union":
|
||||
return "Neispravan unos";
|
||||
case "invalid_element":
|
||||
return `Neispravna vrijednost u ${TypeDictionary[issue.origin] ?? issue.origin}`;
|
||||
default:
|
||||
return `Neispravan unos`;
|
||||
}
|
||||
};
|
||||
};
|
||||
function default_1() {
|
||||
return {
|
||||
localeError: error(),
|
||||
};
|
||||
}
|
||||
module.exports = exports.default;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import type * as errors from "../core/errors.cjs";
|
||||
declare function _default(): {
|
||||
localeError: errors.$ZodErrorMap;
|
||||
};
|
||||
export = _default;
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type * as errors from "../core/errors.js";
|
||||
export default function (): {
|
||||
localeError: errors.$ZodErrorMap;
|
||||
};
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
import * as util from "../core/util.js";
|
||||
const error = () => {
|
||||
const Sizable = {
|
||||
string: { unit: "znakova", verb: "imati" },
|
||||
file: { unit: "bajtova", verb: "imati" },
|
||||
array: { unit: "stavki", verb: "imati" },
|
||||
set: { unit: "stavki", verb: "imati" },
|
||||
};
|
||||
function getSizing(origin) {
|
||||
return Sizable[origin] ?? null;
|
||||
}
|
||||
const FormatDictionary = {
|
||||
regex: "unos",
|
||||
email: "email adresa",
|
||||
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 datum i vrijeme",
|
||||
date: "ISO datum",
|
||||
time: "ISO vrijeme",
|
||||
duration: "ISO trajanje",
|
||||
ipv4: "IPv4 adresa",
|
||||
ipv6: "IPv6 adresa",
|
||||
cidrv4: "IPv4 raspon",
|
||||
cidrv6: "IPv6 raspon",
|
||||
base64: "base64 kodirani tekst",
|
||||
base64url: "base64url kodirani tekst",
|
||||
json_string: "JSON tekst",
|
||||
e164: "E.164 broj",
|
||||
jwt: "JWT",
|
||||
template_literal: "unos",
|
||||
};
|
||||
const TypeDictionary = {
|
||||
nan: "NaN",
|
||||
string: "tekst",
|
||||
number: "broj",
|
||||
boolean: "boolean",
|
||||
array: "niz",
|
||||
object: "objekt",
|
||||
set: "skup",
|
||||
file: "datoteka",
|
||||
date: "datum",
|
||||
bigint: "bigint",
|
||||
symbol: "simbol",
|
||||
undefined: "undefined",
|
||||
null: "null",
|
||||
function: "funkcija",
|
||||
map: "mapa",
|
||||
};
|
||||
return (issue) => {
|
||||
switch (issue.code) {
|
||||
case "invalid_type": {
|
||||
const expected = TypeDictionary[issue.expected] ?? issue.expected;
|
||||
const receivedType = util.parsedType(issue.input);
|
||||
const received = TypeDictionary[receivedType] ?? receivedType;
|
||||
if (/^[A-Z]/.test(issue.expected)) {
|
||||
return `Neispravan unos: očekuje se instanceof ${issue.expected}, a primljeno je ${received}`;
|
||||
}
|
||||
return `Neispravan unos: očekuje se ${expected}, a primljeno je ${received}`;
|
||||
}
|
||||
case "invalid_value":
|
||||
if (issue.values.length === 1)
|
||||
return `Neispravna vrijednost: očekivano ${util.stringifyPrimitive(issue.values[0])}`;
|
||||
return `Neispravna opcija: očekivano jedno od ${util.joinValues(issue.values, "|")}`;
|
||||
case "too_big": {
|
||||
const adj = issue.inclusive ? "<=" : "<";
|
||||
const sizing = getSizing(issue.origin);
|
||||
const origin = TypeDictionary[issue.origin] ?? issue.origin;
|
||||
if (sizing)
|
||||
return `Preveliko: očekivano da ${origin ?? "vrijednost"} ima ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elemenata"}`;
|
||||
return `Preveliko: očekivano da ${origin ?? "vrijednost"} bude ${adj}${issue.maximum.toString()}`;
|
||||
}
|
||||
case "too_small": {
|
||||
const adj = issue.inclusive ? ">=" : ">";
|
||||
const sizing = getSizing(issue.origin);
|
||||
const origin = TypeDictionary[issue.origin] ?? issue.origin;
|
||||
if (sizing) {
|
||||
return `Premalo: očekivano da ${origin} ima ${adj}${issue.minimum.toString()} ${sizing.unit}`;
|
||||
}
|
||||
return `Premalo: očekivano da ${origin} bude ${adj}${issue.minimum.toString()}`;
|
||||
}
|
||||
case "invalid_format": {
|
||||
const _issue = issue;
|
||||
if (_issue.format === "starts_with")
|
||||
return `Neispravan tekst: mora započinjati s "${_issue.prefix}"`;
|
||||
if (_issue.format === "ends_with")
|
||||
return `Neispravan tekst: mora završavati s "${_issue.suffix}"`;
|
||||
if (_issue.format === "includes")
|
||||
return `Neispravan tekst: mora sadržavati "${_issue.includes}"`;
|
||||
if (_issue.format === "regex")
|
||||
return `Neispravan tekst: mora odgovarati uzorku ${_issue.pattern}`;
|
||||
return `Neispravna ${FormatDictionary[_issue.format] ?? issue.format}`;
|
||||
}
|
||||
case "not_multiple_of":
|
||||
return `Neispravan broj: mora biti višekratnik od ${issue.divisor}`;
|
||||
case "unrecognized_keys":
|
||||
return `Neprepoznat${issue.keys.length > 1 ? "i ključevi" : " ključ"}: ${util.joinValues(issue.keys, ", ")}`;
|
||||
case "invalid_key":
|
||||
return `Neispravan ključ u ${TypeDictionary[issue.origin] ?? issue.origin}`;
|
||||
case "invalid_union":
|
||||
return "Neispravan unos";
|
||||
case "invalid_element":
|
||||
return `Neispravna vrijednost u ${TypeDictionary[issue.origin] ?? issue.origin}`;
|
||||
default:
|
||||
return `Neispravan unos`;
|
||||
}
|
||||
};
|
||||
};
|
||||
export default function () {
|
||||
return {
|
||||
localeError: error(),
|
||||
};
|
||||
}
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
"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: "caractere", verb: "să aibă" },
|
||||
file: { unit: "octeți", verb: "să aibă" },
|
||||
array: { unit: "elemente", verb: "să aibă" },
|
||||
set: { unit: "elemente", verb: "să aibă" },
|
||||
map: { unit: "intrări", verb: "să aibă" },
|
||||
};
|
||||
function getSizing(origin) {
|
||||
return Sizable[origin] ?? null;
|
||||
}
|
||||
const FormatDictionary = {
|
||||
regex: "intrare",
|
||||
email: "adresă de 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: "dată și oră ISO",
|
||||
date: "dată ISO",
|
||||
time: "oră ISO",
|
||||
duration: "durată ISO",
|
||||
ipv4: "adresă IPv4",
|
||||
ipv6: "adresă IPv6",
|
||||
mac: "adresă MAC",
|
||||
cidrv4: "interval IPv4",
|
||||
cidrv6: "interval IPv6",
|
||||
base64: "șir codat base64",
|
||||
base64url: "șir codat base64url",
|
||||
json_string: "șir JSON",
|
||||
e164: "număr E.164",
|
||||
jwt: "JWT",
|
||||
template_literal: "intrare",
|
||||
};
|
||||
const TypeDictionary = {
|
||||
nan: "NaN",
|
||||
string: "șir",
|
||||
number: "număr",
|
||||
boolean: "boolean",
|
||||
function: "funcție",
|
||||
array: "matrice",
|
||||
object: "obiect",
|
||||
undefined: "nedefinit",
|
||||
symbol: "simbol",
|
||||
bigint: "număr mare",
|
||||
void: "void",
|
||||
never: "never",
|
||||
map: "hartă",
|
||||
set: "set",
|
||||
};
|
||||
return (issue) => {
|
||||
switch (issue.code) {
|
||||
case "invalid_type": {
|
||||
const expected = TypeDictionary[issue.expected] ?? issue.expected;
|
||||
const receivedType = util.parsedType(issue.input);
|
||||
const received = TypeDictionary[receivedType] ?? receivedType;
|
||||
return `Intrare invalidă: așteptat ${expected}, primit ${received}`;
|
||||
}
|
||||
case "invalid_value":
|
||||
if (issue.values.length === 1)
|
||||
return `Intrare invalidă: așteptat ${util.stringifyPrimitive(issue.values[0])}`;
|
||||
return `Opțiune invalidă: așteptat una dintre ${util.joinValues(issue.values, "|")}`;
|
||||
case "too_big": {
|
||||
const adj = issue.inclusive ? "<=" : "<";
|
||||
const sizing = getSizing(issue.origin);
|
||||
if (sizing)
|
||||
return `Prea mare: așteptat ca ${issue.origin ?? "valoarea"} ${sizing.verb} ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elemente"}`;
|
||||
return `Prea mare: așteptat ca ${issue.origin ?? "valoarea"} să fie ${adj}${issue.maximum.toString()}`;
|
||||
}
|
||||
case "too_small": {
|
||||
const adj = issue.inclusive ? ">=" : ">";
|
||||
const sizing = getSizing(issue.origin);
|
||||
if (sizing) {
|
||||
return `Prea mic: așteptat ca ${issue.origin} ${sizing.verb} ${adj}${issue.minimum.toString()} ${sizing.unit}`;
|
||||
}
|
||||
return `Prea mic: așteptat ca ${issue.origin} să fie ${adj}${issue.minimum.toString()}`;
|
||||
}
|
||||
case "invalid_format": {
|
||||
const _issue = issue;
|
||||
if (_issue.format === "starts_with") {
|
||||
return `Șir invalid: trebuie să înceapă cu "${_issue.prefix}"`;
|
||||
}
|
||||
if (_issue.format === "ends_with")
|
||||
return `Șir invalid: trebuie să se termine cu "${_issue.suffix}"`;
|
||||
if (_issue.format === "includes")
|
||||
return `Șir invalid: trebuie să includă "${_issue.includes}"`;
|
||||
if (_issue.format === "regex")
|
||||
return `Șir invalid: trebuie să se potrivească cu modelul ${_issue.pattern}`;
|
||||
return `Format invalid: ${FormatDictionary[_issue.format] ?? issue.format}`;
|
||||
}
|
||||
case "not_multiple_of":
|
||||
return `Număr invalid: trebuie să fie multiplu de ${issue.divisor}`;
|
||||
case "unrecognized_keys":
|
||||
return `Chei nerecunoscute: ${util.joinValues(issue.keys, ", ")}`;
|
||||
case "invalid_key":
|
||||
return `Cheie invalidă în ${issue.origin}`;
|
||||
case "invalid_union":
|
||||
return "Intrare invalidă";
|
||||
case "invalid_element":
|
||||
return `Valoare invalidă în ${issue.origin}`;
|
||||
default:
|
||||
return `Intrare invalidă`;
|
||||
}
|
||||
};
|
||||
};
|
||||
function default_1() {
|
||||
return {
|
||||
localeError: error(),
|
||||
};
|
||||
}
|
||||
module.exports = exports.default;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import type * as errors from "../core/errors.cjs";
|
||||
declare function _default(): {
|
||||
localeError: errors.$ZodErrorMap;
|
||||
};
|
||||
export = _default;
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type * as errors from "../core/errors.js";
|
||||
export default function (): {
|
||||
localeError: errors.$ZodErrorMap;
|
||||
};
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
import * as util from "../core/util.js";
|
||||
const error = () => {
|
||||
const Sizable = {
|
||||
string: { unit: "caractere", verb: "să aibă" },
|
||||
file: { unit: "octeți", verb: "să aibă" },
|
||||
array: { unit: "elemente", verb: "să aibă" },
|
||||
set: { unit: "elemente", verb: "să aibă" },
|
||||
map: { unit: "intrări", verb: "să aibă" },
|
||||
};
|
||||
function getSizing(origin) {
|
||||
return Sizable[origin] ?? null;
|
||||
}
|
||||
const FormatDictionary = {
|
||||
regex: "intrare",
|
||||
email: "adresă de 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: "dată și oră ISO",
|
||||
date: "dată ISO",
|
||||
time: "oră ISO",
|
||||
duration: "durată ISO",
|
||||
ipv4: "adresă IPv4",
|
||||
ipv6: "adresă IPv6",
|
||||
mac: "adresă MAC",
|
||||
cidrv4: "interval IPv4",
|
||||
cidrv6: "interval IPv6",
|
||||
base64: "șir codat base64",
|
||||
base64url: "șir codat base64url",
|
||||
json_string: "șir JSON",
|
||||
e164: "număr E.164",
|
||||
jwt: "JWT",
|
||||
template_literal: "intrare",
|
||||
};
|
||||
const TypeDictionary = {
|
||||
nan: "NaN",
|
||||
string: "șir",
|
||||
number: "număr",
|
||||
boolean: "boolean",
|
||||
function: "funcție",
|
||||
array: "matrice",
|
||||
object: "obiect",
|
||||
undefined: "nedefinit",
|
||||
symbol: "simbol",
|
||||
bigint: "număr mare",
|
||||
void: "void",
|
||||
never: "never",
|
||||
map: "hartă",
|
||||
set: "set",
|
||||
};
|
||||
return (issue) => {
|
||||
switch (issue.code) {
|
||||
case "invalid_type": {
|
||||
const expected = TypeDictionary[issue.expected] ?? issue.expected;
|
||||
const receivedType = util.parsedType(issue.input);
|
||||
const received = TypeDictionary[receivedType] ?? receivedType;
|
||||
return `Intrare invalidă: așteptat ${expected}, primit ${received}`;
|
||||
}
|
||||
case "invalid_value":
|
||||
if (issue.values.length === 1)
|
||||
return `Intrare invalidă: așteptat ${util.stringifyPrimitive(issue.values[0])}`;
|
||||
return `Opțiune invalidă: așteptat una dintre ${util.joinValues(issue.values, "|")}`;
|
||||
case "too_big": {
|
||||
const adj = issue.inclusive ? "<=" : "<";
|
||||
const sizing = getSizing(issue.origin);
|
||||
if (sizing)
|
||||
return `Prea mare: așteptat ca ${issue.origin ?? "valoarea"} ${sizing.verb} ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elemente"}`;
|
||||
return `Prea mare: așteptat ca ${issue.origin ?? "valoarea"} să fie ${adj}${issue.maximum.toString()}`;
|
||||
}
|
||||
case "too_small": {
|
||||
const adj = issue.inclusive ? ">=" : ">";
|
||||
const sizing = getSizing(issue.origin);
|
||||
if (sizing) {
|
||||
return `Prea mic: așteptat ca ${issue.origin} ${sizing.verb} ${adj}${issue.minimum.toString()} ${sizing.unit}`;
|
||||
}
|
||||
return `Prea mic: așteptat ca ${issue.origin} să fie ${adj}${issue.minimum.toString()}`;
|
||||
}
|
||||
case "invalid_format": {
|
||||
const _issue = issue;
|
||||
if (_issue.format === "starts_with") {
|
||||
return `Șir invalid: trebuie să înceapă cu "${_issue.prefix}"`;
|
||||
}
|
||||
if (_issue.format === "ends_with")
|
||||
return `Șir invalid: trebuie să se termine cu "${_issue.suffix}"`;
|
||||
if (_issue.format === "includes")
|
||||
return `Șir invalid: trebuie să includă "${_issue.includes}"`;
|
||||
if (_issue.format === "regex")
|
||||
return `Șir invalid: trebuie să se potrivească cu modelul ${_issue.pattern}`;
|
||||
return `Format invalid: ${FormatDictionary[_issue.format] ?? issue.format}`;
|
||||
}
|
||||
case "not_multiple_of":
|
||||
return `Număr invalid: trebuie să fie multiplu de ${issue.divisor}`;
|
||||
case "unrecognized_keys":
|
||||
return `Chei nerecunoscute: ${util.joinValues(issue.keys, ", ")}`;
|
||||
case "invalid_key":
|
||||
return `Cheie invalidă în ${issue.origin}`;
|
||||
case "invalid_union":
|
||||
return "Intrare invalidă";
|
||||
case "invalid_element":
|
||||
return `Valoare invalidă în ${issue.origin}`;
|
||||
default:
|
||||
return `Intrare invalidă`;
|
||||
}
|
||||
};
|
||||
};
|
||||
export default function () {
|
||||
return {
|
||||
localeError: error(),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user