zod 4.0.5 → 4.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/v3/tests/string.test.ts +2 -2
- package/src/v3/types.ts +3 -1
- package/src/v4/classic/errors.ts +9 -2
- package/src/v4/classic/schemas.ts +11 -9
- package/src/v4/classic/tests/catch.test.ts +4 -5
- package/src/v4/classic/tests/discriminated-unions.test.ts +12 -0
- package/src/v4/classic/tests/error-utils.test.ts +43 -0
- package/src/v4/classic/tests/literal.test.ts +25 -0
- package/src/v4/classic/tests/partial.test.ts +193 -0
- package/src/v4/classic/tests/pickomit.test.ts +5 -5
- package/src/v4/classic/tests/preprocess.test.ts +4 -15
- package/src/v4/classic/tests/record.test.ts +15 -1
- package/src/v4/classic/tests/recursive-types.test.ts +67 -0
- package/src/v4/classic/tests/string.test.ts +81 -4
- package/src/v4/classic/tests/template-literal.test.ts +3 -0
- package/src/v4/classic/tests/to-json-schema.test.ts +1 -0
- package/src/v4/classic/tests/transform.test.ts +110 -0
- package/src/v4/classic/tests/union.test.ts +45 -3
- package/src/v4/core/checks.ts +2 -2
- package/src/v4/core/errors.ts +8 -15
- package/src/v4/core/regexes.ts +1 -1
- package/src/v4/core/registries.ts +3 -2
- package/src/v4/core/schemas.ts +90 -98
- package/src/v4/core/to-json-schema.ts +1 -0
- package/src/v4/core/util.ts +175 -115
- package/src/v4/core/versions.ts +1 -1
- package/src/v4/locales/bg.ts +136 -0
- package/src/v4/locales/da.ts +141 -0
- package/src/v4/locales/index.ts +2 -0
- package/src/v4/locales/is.ts +127 -0
- package/src/v4/mini/schemas.ts +3 -1
- package/v3/types.cjs +2 -0
- package/v3/types.d.cts +4 -1
- package/v3/types.d.ts +4 -1
- package/v3/types.js +2 -0
- package/v4/classic/errors.cjs +9 -2
- package/v4/classic/errors.js +9 -2
- package/v4/classic/schemas.cjs +5 -3
- package/v4/classic/schemas.d.cts +3 -3
- package/v4/classic/schemas.d.ts +3 -3
- package/v4/classic/schemas.js +5 -3
- package/v4/core/checks.d.cts +2 -2
- package/v4/core/checks.d.ts +2 -2
- package/v4/core/errors.cjs +4 -9
- package/v4/core/errors.d.cts +4 -6
- package/v4/core/errors.d.ts +4 -6
- package/v4/core/errors.js +4 -9
- package/v4/core/regexes.cjs +1 -1
- package/v4/core/regexes.d.cts +1 -1
- package/v4/core/regexes.d.ts +1 -1
- package/v4/core/regexes.js +1 -1
- package/v4/core/registries.cjs +2 -1
- package/v4/core/registries.d.cts +1 -1
- package/v4/core/registries.d.ts +1 -1
- package/v4/core/registries.js +2 -1
- package/v4/core/schemas.cjs +47 -87
- package/v4/core/schemas.d.cts +9 -4
- package/v4/core/schemas.d.ts +9 -4
- package/v4/core/schemas.js +47 -87
- package/v4/core/to-json-schema.cjs +1 -0
- package/v4/core/to-json-schema.js +1 -0
- package/v4/core/util.cjs +163 -112
- package/v4/core/util.d.cts +1 -0
- package/v4/core/util.d.ts +1 -0
- package/v4/core/util.js +162 -112
- package/v4/core/versions.cjs +1 -1
- package/v4/core/versions.js +1 -1
- package/v4/locales/bg.cjs +156 -0
- package/v4/locales/bg.d.cts +5 -0
- package/v4/locales/bg.d.ts +5 -0
- package/v4/locales/bg.js +128 -0
- package/v4/locales/da.cjs +157 -0
- package/v4/locales/da.d.cts +4 -0
- package/v4/locales/da.d.ts +4 -0
- package/v4/locales/da.js +131 -0
- package/v4/locales/index.cjs +5 -1
- package/v4/locales/index.d.cts +2 -0
- package/v4/locales/index.d.ts +2 -0
- package/v4/locales/index.js +2 -0
- package/v4/locales/is.cjs +145 -0
- package/v4/locales/is.d.cts +5 -0
- package/v4/locales/is.d.ts +5 -0
- package/v4/locales/is.js +117 -0
- package/v4/mini/schemas.cjs +3 -1
- package/v4/mini/schemas.js +3 -1
package/v4/core/util.js
CHANGED
|
@@ -83,6 +83,11 @@ export function assignProp(target, prop, value) {
|
|
|
83
83
|
configurable: true,
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
|
+
export function cloneDef(schema) {
|
|
87
|
+
const def = {};
|
|
88
|
+
Object.defineProperties(def, Object.getOwnPropertyDescriptors(schema._zod.def));
|
|
89
|
+
return def;
|
|
90
|
+
}
|
|
86
91
|
export function getElementAtPath(obj, path) {
|
|
87
92
|
if (!path)
|
|
88
93
|
return obj;
|
|
@@ -110,13 +115,12 @@ export function randomString(length = 10) {
|
|
|
110
115
|
export function esc(str) {
|
|
111
116
|
return JSON.stringify(str);
|
|
112
117
|
}
|
|
113
|
-
export const captureStackTrace = Error.captureStackTrace
|
|
114
|
-
? Error.captureStackTrace
|
|
115
|
-
: (..._args) => { };
|
|
118
|
+
export const captureStackTrace = ("captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => { });
|
|
116
119
|
export function isObject(data) {
|
|
117
120
|
return typeof data === "object" && data !== null && !Array.isArray(data);
|
|
118
121
|
}
|
|
119
122
|
export const allowsEval = cached(() => {
|
|
123
|
+
// @ts-ignore
|
|
120
124
|
if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) {
|
|
121
125
|
return false;
|
|
122
126
|
}
|
|
@@ -191,6 +195,7 @@ export const getParsedType = (data) => {
|
|
|
191
195
|
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
192
196
|
return "date";
|
|
193
197
|
}
|
|
198
|
+
// @ts-ignore
|
|
194
199
|
if (typeof File !== "undefined" && data instanceof File) {
|
|
195
200
|
return "file";
|
|
196
201
|
}
|
|
@@ -284,140 +289,184 @@ export const BIGINT_FORMAT_RANGES = {
|
|
|
284
289
|
uint64: [/* @__PURE__*/ BigInt(0), /* @__PURE__*/ BigInt("18446744073709551615")],
|
|
285
290
|
};
|
|
286
291
|
export function pick(schema, mask) {
|
|
287
|
-
const
|
|
288
|
-
const
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
292
|
+
const currDef = schema._zod.def;
|
|
293
|
+
const def = cloneDef(schema);
|
|
294
|
+
Object.defineProperties(def, {
|
|
295
|
+
shape: {
|
|
296
|
+
get() {
|
|
297
|
+
const newShape = {};
|
|
298
|
+
for (const key in mask) {
|
|
299
|
+
if (!(key in currDef.shape)) {
|
|
300
|
+
throw new Error(`Unrecognized key: "${key}"`);
|
|
301
|
+
}
|
|
302
|
+
if (!mask[key])
|
|
303
|
+
continue;
|
|
304
|
+
newShape[key] = currDef.shape[key];
|
|
305
|
+
}
|
|
306
|
+
assignProp(this, "shape", newShape); // self-caching
|
|
307
|
+
return newShape;
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
checks: {
|
|
311
|
+
value: [],
|
|
312
|
+
},
|
|
302
313
|
});
|
|
314
|
+
return clone(schema, def);
|
|
303
315
|
}
|
|
304
316
|
export function omit(schema, mask) {
|
|
305
|
-
const
|
|
306
|
-
const
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
317
|
+
const currDef = schema._zod.def;
|
|
318
|
+
const def = cloneDef(schema);
|
|
319
|
+
Object.defineProperties(def, {
|
|
320
|
+
shape: {
|
|
321
|
+
get() {
|
|
322
|
+
const newShape = { ...schema._zod.def.shape };
|
|
323
|
+
for (const key in mask) {
|
|
324
|
+
if (!(key in currDef.shape)) {
|
|
325
|
+
throw new Error(`Unrecognized key: "${key}"`);
|
|
326
|
+
}
|
|
327
|
+
if (!mask[key])
|
|
328
|
+
continue;
|
|
329
|
+
delete newShape[key];
|
|
330
|
+
}
|
|
331
|
+
assignProp(this, "shape", newShape); // self-caching
|
|
332
|
+
return newShape;
|
|
333
|
+
},
|
|
334
|
+
},
|
|
335
|
+
checks: {
|
|
336
|
+
value: [],
|
|
337
|
+
},
|
|
319
338
|
});
|
|
339
|
+
return clone(schema, def);
|
|
320
340
|
}
|
|
321
341
|
export function extend(schema, shape) {
|
|
322
342
|
if (!isPlainObject(shape)) {
|
|
323
343
|
throw new Error("Invalid input to extend: expected a plain object");
|
|
324
344
|
}
|
|
325
|
-
const def =
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
345
|
+
const def = cloneDef(schema);
|
|
346
|
+
Object.defineProperties(def, {
|
|
347
|
+
shape: {
|
|
348
|
+
get() {
|
|
349
|
+
const _shape = { ...schema._zod.def.shape, ...shape };
|
|
350
|
+
assignProp(this, "shape", _shape); // self-caching
|
|
351
|
+
return _shape;
|
|
352
|
+
},
|
|
331
353
|
},
|
|
332
|
-
checks:
|
|
333
|
-
|
|
354
|
+
checks: {
|
|
355
|
+
value: [],
|
|
356
|
+
},
|
|
357
|
+
});
|
|
334
358
|
return clone(schema, def);
|
|
335
359
|
}
|
|
336
360
|
export function merge(a, b) {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
361
|
+
const def = cloneDef(a);
|
|
362
|
+
Object.defineProperties(def, {
|
|
363
|
+
shape: {
|
|
364
|
+
get() {
|
|
365
|
+
const _shape = { ...a._zod.def.shape, ...b._zod.def.shape };
|
|
366
|
+
assignProp(this, "shape", _shape); // self-caching
|
|
367
|
+
return _shape;
|
|
368
|
+
},
|
|
369
|
+
},
|
|
370
|
+
catchall: {
|
|
371
|
+
get() {
|
|
372
|
+
return b._zod.def.catchall;
|
|
373
|
+
},
|
|
374
|
+
},
|
|
375
|
+
checks: {
|
|
376
|
+
value: [], // delete existing checks
|
|
343
377
|
},
|
|
344
|
-
catchall: b._zod.def.catchall,
|
|
345
|
-
checks: [], // delete existing checks
|
|
346
378
|
});
|
|
379
|
+
return clone(a, def);
|
|
347
380
|
}
|
|
348
381
|
export function partial(Class, schema, mask) {
|
|
349
|
-
const
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
+
const def = cloneDef(schema);
|
|
383
|
+
Object.defineProperties(def, {
|
|
384
|
+
shape: {
|
|
385
|
+
get() {
|
|
386
|
+
const oldShape = schema._zod.def.shape;
|
|
387
|
+
const shape = { ...oldShape };
|
|
388
|
+
if (mask) {
|
|
389
|
+
for (const key in mask) {
|
|
390
|
+
if (!(key in oldShape)) {
|
|
391
|
+
throw new Error(`Unrecognized key: "${key}"`);
|
|
392
|
+
}
|
|
393
|
+
if (!mask[key])
|
|
394
|
+
continue;
|
|
395
|
+
// if (oldShape[key]!._zod.optin === "optional") continue;
|
|
396
|
+
shape[key] = Class
|
|
397
|
+
? new Class({
|
|
398
|
+
type: "optional",
|
|
399
|
+
innerType: oldShape[key],
|
|
400
|
+
})
|
|
401
|
+
: oldShape[key];
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
for (const key in oldShape) {
|
|
406
|
+
// if (oldShape[key]!._zod.optin === "optional") continue;
|
|
407
|
+
shape[key] = Class
|
|
408
|
+
? new Class({
|
|
409
|
+
type: "optional",
|
|
410
|
+
innerType: oldShape[key],
|
|
411
|
+
})
|
|
412
|
+
: oldShape[key];
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
assignProp(this, "shape", shape); // self-caching
|
|
416
|
+
return shape;
|
|
417
|
+
},
|
|
418
|
+
},
|
|
419
|
+
checks: {
|
|
420
|
+
value: [],
|
|
421
|
+
},
|
|
382
422
|
});
|
|
423
|
+
return clone(schema, def);
|
|
383
424
|
}
|
|
384
425
|
export function required(Class, schema, mask) {
|
|
385
|
-
const
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
426
|
+
const def = cloneDef(schema);
|
|
427
|
+
Object.defineProperties(def, {
|
|
428
|
+
shape: {
|
|
429
|
+
get() {
|
|
430
|
+
const oldShape = schema._zod.def.shape;
|
|
431
|
+
const shape = { ...oldShape };
|
|
432
|
+
if (mask) {
|
|
433
|
+
for (const key in mask) {
|
|
434
|
+
if (!(key in shape)) {
|
|
435
|
+
throw new Error(`Unrecognized key: "${key}"`);
|
|
436
|
+
}
|
|
437
|
+
if (!mask[key])
|
|
438
|
+
continue;
|
|
439
|
+
// overwrite with non-optional
|
|
440
|
+
shape[key] = new Class({
|
|
441
|
+
type: "nonoptional",
|
|
442
|
+
innerType: oldShape[key],
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
else {
|
|
447
|
+
for (const key in oldShape) {
|
|
448
|
+
// overwrite with non-optional
|
|
449
|
+
shape[key] = new Class({
|
|
450
|
+
type: "nonoptional",
|
|
451
|
+
innerType: oldShape[key],
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
assignProp(this, "shape", shape); // self-caching
|
|
456
|
+
return shape;
|
|
457
|
+
},
|
|
458
|
+
},
|
|
459
|
+
checks: {
|
|
460
|
+
value: [],
|
|
461
|
+
},
|
|
415
462
|
});
|
|
463
|
+
return clone(schema, def);
|
|
416
464
|
}
|
|
417
465
|
export function aborted(x, startIndex = 0) {
|
|
418
466
|
for (let i = startIndex; i < x.issues.length; i++) {
|
|
419
|
-
if (x.issues[i]?.continue !== true)
|
|
467
|
+
if (x.issues[i]?.continue !== true) {
|
|
420
468
|
return true;
|
|
469
|
+
}
|
|
421
470
|
}
|
|
422
471
|
return false;
|
|
423
472
|
}
|
|
@@ -456,6 +505,7 @@ export function getSizableOrigin(input) {
|
|
|
456
505
|
return "set";
|
|
457
506
|
if (input instanceof Map)
|
|
458
507
|
return "map";
|
|
508
|
+
// @ts-ignore
|
|
459
509
|
if (input instanceof File)
|
|
460
510
|
return "file";
|
|
461
511
|
return "unknown";
|
package/v4/core/versions.cjs
CHANGED
package/v4/core/versions.js
CHANGED
|
@@ -0,0 +1,156 @@
|
|
|
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.parsedType = void 0;
|
|
27
|
+
exports.default = default_1;
|
|
28
|
+
const util = __importStar(require("../core/util.cjs"));
|
|
29
|
+
const parsedType = (data) => {
|
|
30
|
+
const t = typeof data;
|
|
31
|
+
switch (t) {
|
|
32
|
+
case "number": {
|
|
33
|
+
return Number.isNaN(data) ? "NaN" : "число";
|
|
34
|
+
}
|
|
35
|
+
case "object": {
|
|
36
|
+
if (Array.isArray(data)) {
|
|
37
|
+
return "масив";
|
|
38
|
+
}
|
|
39
|
+
if (data === null) {
|
|
40
|
+
return "null";
|
|
41
|
+
}
|
|
42
|
+
if (Object.getPrototypeOf(data) !== Object.prototype && data.constructor) {
|
|
43
|
+
return data.constructor.name;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return t;
|
|
48
|
+
};
|
|
49
|
+
exports.parsedType = parsedType;
|
|
50
|
+
const error = () => {
|
|
51
|
+
const Sizable = {
|
|
52
|
+
string: { unit: "символа", verb: "да съдържа" },
|
|
53
|
+
file: { unit: "байта", verb: "да съдържа" },
|
|
54
|
+
array: { unit: "елемента", verb: "да съдържа" },
|
|
55
|
+
set: { unit: "елемента", verb: "да съдържа" },
|
|
56
|
+
};
|
|
57
|
+
function getSizing(origin) {
|
|
58
|
+
return Sizable[origin] ?? null;
|
|
59
|
+
}
|
|
60
|
+
const Nouns = {
|
|
61
|
+
regex: "вход",
|
|
62
|
+
email: "имейл адрес",
|
|
63
|
+
url: "URL",
|
|
64
|
+
emoji: "емоджи",
|
|
65
|
+
uuid: "UUID",
|
|
66
|
+
uuidv4: "UUIDv4",
|
|
67
|
+
uuidv6: "UUIDv6",
|
|
68
|
+
nanoid: "nanoid",
|
|
69
|
+
guid: "GUID",
|
|
70
|
+
cuid: "cuid",
|
|
71
|
+
cuid2: "cuid2",
|
|
72
|
+
ulid: "ULID",
|
|
73
|
+
xid: "XID",
|
|
74
|
+
ksuid: "KSUID",
|
|
75
|
+
datetime: "ISO време",
|
|
76
|
+
date: "ISO дата",
|
|
77
|
+
time: "ISO време",
|
|
78
|
+
duration: "ISO продължителност",
|
|
79
|
+
ipv4: "IPv4 адрес",
|
|
80
|
+
ipv6: "IPv6 адрес",
|
|
81
|
+
cidrv4: "IPv4 диапазон",
|
|
82
|
+
cidrv6: "IPv6 диапазон",
|
|
83
|
+
base64: "base64-кодиран низ",
|
|
84
|
+
base64url: "base64url-кодиран низ",
|
|
85
|
+
json_string: "JSON низ",
|
|
86
|
+
e164: "E.164 номер",
|
|
87
|
+
jwt: "JWT",
|
|
88
|
+
template_literal: "вход",
|
|
89
|
+
};
|
|
90
|
+
return (issue) => {
|
|
91
|
+
switch (issue.code) {
|
|
92
|
+
case "invalid_type":
|
|
93
|
+
return `Невалиден вход: очакван ${issue.expected}, получен ${(0, exports.parsedType)(issue.input)}`;
|
|
94
|
+
case "invalid_value":
|
|
95
|
+
if (issue.values.length === 1)
|
|
96
|
+
return `Невалиден вход: очакван ${util.stringifyPrimitive(issue.values[0])}`;
|
|
97
|
+
return `Невалидна опция: очаквано едно от ${util.joinValues(issue.values, "|")}`;
|
|
98
|
+
case "too_big": {
|
|
99
|
+
const adj = issue.inclusive ? "<=" : "<";
|
|
100
|
+
const sizing = getSizing(issue.origin);
|
|
101
|
+
if (sizing)
|
|
102
|
+
return `Твърде голямо: очаква се ${issue.origin ?? "стойност"} да съдържа ${adj}${issue.maximum.toString()} ${sizing.unit ?? "елемента"}`;
|
|
103
|
+
return `Твърде голямо: очаква се ${issue.origin ?? "стойност"} да бъде ${adj}${issue.maximum.toString()}`;
|
|
104
|
+
}
|
|
105
|
+
case "too_small": {
|
|
106
|
+
const adj = issue.inclusive ? ">=" : ">";
|
|
107
|
+
const sizing = getSizing(issue.origin);
|
|
108
|
+
if (sizing) {
|
|
109
|
+
return `Твърде малко: очаква се ${issue.origin} да съдържа ${adj}${issue.minimum.toString()} ${sizing.unit}`;
|
|
110
|
+
}
|
|
111
|
+
return `Твърде малко: очаква се ${issue.origin} да бъде ${adj}${issue.minimum.toString()}`;
|
|
112
|
+
}
|
|
113
|
+
case "invalid_format": {
|
|
114
|
+
const _issue = issue;
|
|
115
|
+
if (_issue.format === "starts_with") {
|
|
116
|
+
return `Невалиден низ: трябва да започва с "${_issue.prefix}"`;
|
|
117
|
+
}
|
|
118
|
+
if (_issue.format === "ends_with")
|
|
119
|
+
return `Невалиден низ: трябва да завършва с "${_issue.suffix}"`;
|
|
120
|
+
if (_issue.format === "includes")
|
|
121
|
+
return `Невалиден низ: трябва да включва "${_issue.includes}"`;
|
|
122
|
+
if (_issue.format === "regex")
|
|
123
|
+
return `Невалиден низ: трябва да съвпада с ${_issue.pattern}`;
|
|
124
|
+
let invalid_adj = "Невалиден";
|
|
125
|
+
if (_issue.format === "emoji")
|
|
126
|
+
invalid_adj = "Невалидно";
|
|
127
|
+
if (_issue.format === "datetime")
|
|
128
|
+
invalid_adj = "Невалидно";
|
|
129
|
+
if (_issue.format === "date")
|
|
130
|
+
invalid_adj = "Невалидна";
|
|
131
|
+
if (_issue.format === "time")
|
|
132
|
+
invalid_adj = "Невалидно";
|
|
133
|
+
if (_issue.format === "duration")
|
|
134
|
+
invalid_adj = "Невалидна";
|
|
135
|
+
return `${invalid_adj} ${Nouns[_issue.format] ?? issue.format}`;
|
|
136
|
+
}
|
|
137
|
+
case "not_multiple_of":
|
|
138
|
+
return `Невалидно число: трябва да бъде кратно на ${issue.divisor}`;
|
|
139
|
+
case "unrecognized_keys":
|
|
140
|
+
return `Неразпознат${issue.keys.length > 1 ? "и" : ""} ключ${issue.keys.length > 1 ? "ове" : ""}: ${util.joinValues(issue.keys, ", ")}`;
|
|
141
|
+
case "invalid_key":
|
|
142
|
+
return `Невалиден ключ в ${issue.origin}`;
|
|
143
|
+
case "invalid_union":
|
|
144
|
+
return "Невалиден вход";
|
|
145
|
+
case "invalid_element":
|
|
146
|
+
return `Невалидна стойност в ${issue.origin}`;
|
|
147
|
+
default:
|
|
148
|
+
return `Невалиден вход`;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
function default_1() {
|
|
153
|
+
return {
|
|
154
|
+
localeError: error(),
|
|
155
|
+
};
|
|
156
|
+
}
|
package/v4/locales/bg.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import * as util from "../core/util.js";
|
|
2
|
+
export const parsedType = (data) => {
|
|
3
|
+
const t = typeof data;
|
|
4
|
+
switch (t) {
|
|
5
|
+
case "number": {
|
|
6
|
+
return Number.isNaN(data) ? "NaN" : "число";
|
|
7
|
+
}
|
|
8
|
+
case "object": {
|
|
9
|
+
if (Array.isArray(data)) {
|
|
10
|
+
return "масив";
|
|
11
|
+
}
|
|
12
|
+
if (data === null) {
|
|
13
|
+
return "null";
|
|
14
|
+
}
|
|
15
|
+
if (Object.getPrototypeOf(data) !== Object.prototype && data.constructor) {
|
|
16
|
+
return data.constructor.name;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
const error = () => {
|
|
23
|
+
const Sizable = {
|
|
24
|
+
string: { unit: "символа", verb: "да съдържа" },
|
|
25
|
+
file: { unit: "байта", verb: "да съдържа" },
|
|
26
|
+
array: { unit: "елемента", verb: "да съдържа" },
|
|
27
|
+
set: { unit: "елемента", verb: "да съдържа" },
|
|
28
|
+
};
|
|
29
|
+
function getSizing(origin) {
|
|
30
|
+
return Sizable[origin] ?? null;
|
|
31
|
+
}
|
|
32
|
+
const Nouns = {
|
|
33
|
+
regex: "вход",
|
|
34
|
+
email: "имейл адрес",
|
|
35
|
+
url: "URL",
|
|
36
|
+
emoji: "емоджи",
|
|
37
|
+
uuid: "UUID",
|
|
38
|
+
uuidv4: "UUIDv4",
|
|
39
|
+
uuidv6: "UUIDv6",
|
|
40
|
+
nanoid: "nanoid",
|
|
41
|
+
guid: "GUID",
|
|
42
|
+
cuid: "cuid",
|
|
43
|
+
cuid2: "cuid2",
|
|
44
|
+
ulid: "ULID",
|
|
45
|
+
xid: "XID",
|
|
46
|
+
ksuid: "KSUID",
|
|
47
|
+
datetime: "ISO време",
|
|
48
|
+
date: "ISO дата",
|
|
49
|
+
time: "ISO време",
|
|
50
|
+
duration: "ISO продължителност",
|
|
51
|
+
ipv4: "IPv4 адрес",
|
|
52
|
+
ipv6: "IPv6 адрес",
|
|
53
|
+
cidrv4: "IPv4 диапазон",
|
|
54
|
+
cidrv6: "IPv6 диапазон",
|
|
55
|
+
base64: "base64-кодиран низ",
|
|
56
|
+
base64url: "base64url-кодиран низ",
|
|
57
|
+
json_string: "JSON низ",
|
|
58
|
+
e164: "E.164 номер",
|
|
59
|
+
jwt: "JWT",
|
|
60
|
+
template_literal: "вход",
|
|
61
|
+
};
|
|
62
|
+
return (issue) => {
|
|
63
|
+
switch (issue.code) {
|
|
64
|
+
case "invalid_type":
|
|
65
|
+
return `Невалиден вход: очакван ${issue.expected}, получен ${parsedType(issue.input)}`;
|
|
66
|
+
case "invalid_value":
|
|
67
|
+
if (issue.values.length === 1)
|
|
68
|
+
return `Невалиден вход: очакван ${util.stringifyPrimitive(issue.values[0])}`;
|
|
69
|
+
return `Невалидна опция: очаквано едно от ${util.joinValues(issue.values, "|")}`;
|
|
70
|
+
case "too_big": {
|
|
71
|
+
const adj = issue.inclusive ? "<=" : "<";
|
|
72
|
+
const sizing = getSizing(issue.origin);
|
|
73
|
+
if (sizing)
|
|
74
|
+
return `Твърде голямо: очаква се ${issue.origin ?? "стойност"} да съдържа ${adj}${issue.maximum.toString()} ${sizing.unit ?? "елемента"}`;
|
|
75
|
+
return `Твърде голямо: очаква се ${issue.origin ?? "стойност"} да бъде ${adj}${issue.maximum.toString()}`;
|
|
76
|
+
}
|
|
77
|
+
case "too_small": {
|
|
78
|
+
const adj = issue.inclusive ? ">=" : ">";
|
|
79
|
+
const sizing = getSizing(issue.origin);
|
|
80
|
+
if (sizing) {
|
|
81
|
+
return `Твърде малко: очаква се ${issue.origin} да съдържа ${adj}${issue.minimum.toString()} ${sizing.unit}`;
|
|
82
|
+
}
|
|
83
|
+
return `Твърде малко: очаква се ${issue.origin} да бъде ${adj}${issue.minimum.toString()}`;
|
|
84
|
+
}
|
|
85
|
+
case "invalid_format": {
|
|
86
|
+
const _issue = issue;
|
|
87
|
+
if (_issue.format === "starts_with") {
|
|
88
|
+
return `Невалиден низ: трябва да започва с "${_issue.prefix}"`;
|
|
89
|
+
}
|
|
90
|
+
if (_issue.format === "ends_with")
|
|
91
|
+
return `Невалиден низ: трябва да завършва с "${_issue.suffix}"`;
|
|
92
|
+
if (_issue.format === "includes")
|
|
93
|
+
return `Невалиден низ: трябва да включва "${_issue.includes}"`;
|
|
94
|
+
if (_issue.format === "regex")
|
|
95
|
+
return `Невалиден низ: трябва да съвпада с ${_issue.pattern}`;
|
|
96
|
+
let invalid_adj = "Невалиден";
|
|
97
|
+
if (_issue.format === "emoji")
|
|
98
|
+
invalid_adj = "Невалидно";
|
|
99
|
+
if (_issue.format === "datetime")
|
|
100
|
+
invalid_adj = "Невалидно";
|
|
101
|
+
if (_issue.format === "date")
|
|
102
|
+
invalid_adj = "Невалидна";
|
|
103
|
+
if (_issue.format === "time")
|
|
104
|
+
invalid_adj = "Невалидно";
|
|
105
|
+
if (_issue.format === "duration")
|
|
106
|
+
invalid_adj = "Невалидна";
|
|
107
|
+
return `${invalid_adj} ${Nouns[_issue.format] ?? issue.format}`;
|
|
108
|
+
}
|
|
109
|
+
case "not_multiple_of":
|
|
110
|
+
return `Невалидно число: трябва да бъде кратно на ${issue.divisor}`;
|
|
111
|
+
case "unrecognized_keys":
|
|
112
|
+
return `Неразпознат${issue.keys.length > 1 ? "и" : ""} ключ${issue.keys.length > 1 ? "ове" : ""}: ${util.joinValues(issue.keys, ", ")}`;
|
|
113
|
+
case "invalid_key":
|
|
114
|
+
return `Невалиден ключ в ${issue.origin}`;
|
|
115
|
+
case "invalid_union":
|
|
116
|
+
return "Невалиден вход";
|
|
117
|
+
case "invalid_element":
|
|
118
|
+
return `Невалидна стойност в ${issue.origin}`;
|
|
119
|
+
default:
|
|
120
|
+
return `Невалиден вход`;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
export default function () {
|
|
125
|
+
return {
|
|
126
|
+
localeError: error(),
|
|
127
|
+
};
|
|
128
|
+
}
|