@hy_ong/zod-kit 0.2.1 → 0.2.3
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/dist/{chunk-MCDESS3T.js → chunk-2JGRV3JO.js} +1 -1
- package/dist/{chunk-4LYZAO3P.js → chunk-3QLUXIY2.js} +1 -1
- package/dist/chunk-3ZF5JO3F.js +61 -0
- package/dist/{chunk-OP4KV3BY.cjs → chunk-4AQB4RSU.cjs} +3 -3
- package/dist/{chunk-UFNVCUPQ.cjs → chunk-53EEWALQ.cjs} +3 -3
- package/dist/{chunk-R5G4V7C6.cjs → chunk-5ZMTAI4G.cjs} +3 -3
- package/dist/{chunk-RKHX3DGH.js → chunk-6DFP7XY2.js} +1 -1
- package/dist/{chunk-P2NONIMS.js → chunk-6IAPM7BP.js} +1 -1
- package/dist/{chunk-AWV2IT66.js → chunk-7SKH66CM.js} +1 -1
- package/dist/chunk-7X3XPK6A.js +92 -0
- package/dist/{chunk-FVO4743A.cjs → chunk-A2GAEU4O.cjs} +3 -3
- package/dist/{chunk-P364KRO5.js → chunk-AI4U42JV.js} +1 -1
- package/dist/{chunk-5ZEKWPSE.cjs → chunk-AYCXAJRA.cjs} +3 -3
- package/dist/{chunk-5LS4DSRQ.cjs → chunk-BZSPJJYT.cjs} +3 -3
- package/dist/chunk-BZWQPSHO.cjs +92 -0
- package/dist/{chunk-KARFFIMP.js → chunk-D55YFP5R.js} +1 -1
- package/dist/{chunk-I2RJMDXN.js → chunk-E52GRXYY.js} +1 -1
- package/dist/{chunk-VDOAPLA6.cjs → chunk-EDTNS2XL.cjs} +3 -3
- package/dist/{chunk-YALLOVNO.cjs → chunk-FEL432I2.cjs} +3 -3
- package/dist/chunk-FMPHW7ID.cjs +61 -0
- package/dist/{chunk-OMFQ7Z63.cjs → chunk-FP4O2ICM.cjs} +3 -3
- package/dist/{chunk-AANSHH2O.cjs → chunk-G747FHUZ.cjs} +3 -3
- package/dist/{chunk-JZ2SHRGZ.js → chunk-G7FLGJYD.js} +1 -1
- package/dist/{chunk-LKPXHW5N.cjs → chunk-H25N5GP6.cjs} +3 -3
- package/dist/{chunk-FC6VDOC7.js → chunk-H6STFX4I.js} +11 -2
- package/dist/{chunk-MAQRXYE6.js → chunk-HQ4RAMSD.js} +1 -1
- package/dist/{chunk-6X22I6NQ.cjs → chunk-HZ2WESSL.cjs} +3 -3
- package/dist/{chunk-W2EWMV3A.cjs → chunk-IWR3H7IH.cjs} +3 -3
- package/dist/{chunk-5GAZQDVS.cjs → chunk-JZEF5Q3W.cjs} +13 -4
- package/dist/{chunk-77KZUPPN.cjs → chunk-KIUO2HIR.cjs} +3 -3
- package/dist/{chunk-OEK7QSQP.js → chunk-LBH5U2DZ.js} +1 -1
- package/dist/{chunk-PGSDXR2I.js → chunk-LC4RNKBM.js} +1 -1
- package/dist/{chunk-YAU6JCYL.cjs → chunk-LNWEJED7.cjs} +3 -3
- package/dist/{chunk-WWRFBLCR.cjs → chunk-LXFRQLH4.cjs} +3 -3
- package/dist/{chunk-B3U5G3AA.js → chunk-NWQSOSNF.js} +1 -1
- package/dist/{chunk-LIQSVJLS.js → chunk-OGU7AIZF.js} +1 -1
- package/dist/{chunk-NKCYXBGX.js → chunk-OKO6WO6M.js} +1 -1
- package/dist/{chunk-6OGDPSWT.js → chunk-OSUPJCBA.js} +1 -1
- package/dist/{chunk-ZBOQCXD4.js → chunk-POIDES2L.js} +190 -0
- package/dist/{chunk-MG25BEV4.cjs → chunk-Q24GYUTO.cjs} +3 -3
- package/dist/{chunk-YWV2BBXN.cjs → chunk-Q7TUNJD4.cjs} +190 -0
- package/dist/{chunk-DRXPGQM6.cjs → chunk-QQWX3ICK.cjs} +3 -3
- package/dist/{chunk-EAU42EVH.js → chunk-RFWCYULE.js} +1 -1
- package/dist/{chunk-VCRKYMJM.js → chunk-RHKBT3M2.js} +1 -1
- package/dist/{chunk-36NWHESN.js → chunk-RVGCMQ4J.js} +1 -1
- package/dist/{chunk-IJEEM3DI.js → chunk-T7PG4JDW.js} +1 -1
- package/dist/{chunk-JBNCMS42.cjs → chunk-TDEXEIHH.cjs} +3 -3
- package/dist/{chunk-VP5CCP5F.cjs → chunk-TPXRQT2H.cjs} +3 -3
- package/dist/{chunk-DPXRMSB2.js → chunk-TRQMRHFM.js} +1 -1
- package/dist/{chunk-ZFQQXWNB.js → chunk-U2PB6XEO.js} +1 -1
- package/dist/{chunk-G6DV7LX7.cjs → chunk-UCPKW43K.cjs} +3 -3
- package/dist/{chunk-PL2GERLG.cjs → chunk-V2KKGSKQ.cjs} +3 -3
- package/dist/{chunk-AI72FMOF.cjs → chunk-VKBNKPFO.cjs} +3 -3
- package/dist/{chunk-5OGW2ERW.js → chunk-XAN4CAVH.js} +1 -1
- package/dist/{chunk-CFFCBWYL.cjs → chunk-ZCX22PY4.cjs} +3 -3
- package/dist/{chunk-TSHL7ZO2.js → chunk-ZXPRRNZR.js} +1 -1
- package/dist/common/boolean.cjs +3 -3
- package/dist/common/boolean.js +2 -2
- package/dist/common/color.cjs +3 -3
- package/dist/common/color.js +2 -2
- package/dist/common/coordinate.cjs +3 -3
- package/dist/common/coordinate.js +2 -2
- package/dist/common/credit-card.cjs +3 -3
- package/dist/common/credit-card.js +2 -2
- package/dist/common/date.cjs +3 -3
- package/dist/common/date.js +2 -2
- package/dist/common/datetime.cjs +3 -3
- package/dist/common/datetime.js +2 -2
- package/dist/common/email.cjs +3 -3
- package/dist/common/email.js +2 -2
- package/dist/common/file.cjs +3 -3
- package/dist/common/file.js +2 -2
- package/dist/common/id.cjs +3 -3
- package/dist/common/id.d.cts +34 -8
- package/dist/common/id.d.ts +34 -8
- package/dist/common/id.js +2 -2
- package/dist/common/ip.cjs +3 -3
- package/dist/common/ip.js +2 -2
- package/dist/common/many-of.cjs +7 -0
- package/dist/common/many-of.d.cts +111 -0
- package/dist/common/many-of.d.ts +111 -0
- package/dist/common/many-of.js +7 -0
- package/dist/common/number.cjs +3 -3
- package/dist/common/number.js +2 -2
- package/dist/common/one-of.cjs +7 -0
- package/dist/common/one-of.d.cts +104 -0
- package/dist/common/one-of.d.ts +104 -0
- package/dist/common/one-of.js +7 -0
- package/dist/common/password.cjs +3 -3
- package/dist/common/password.js +2 -2
- package/dist/common/text.cjs +3 -3
- package/dist/common/text.js +2 -2
- package/dist/common/time.cjs +3 -3
- package/dist/common/time.js +2 -2
- package/dist/common/url.cjs +3 -3
- package/dist/common/url.js +2 -2
- package/dist/index.cjs +35 -27
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +46 -38
- package/dist/taiwan/bank-account.cjs +3 -3
- package/dist/taiwan/bank-account.js +2 -2
- package/dist/taiwan/business-id.cjs +3 -3
- package/dist/taiwan/business-id.js +2 -2
- package/dist/taiwan/fax.cjs +3 -3
- package/dist/taiwan/fax.js +2 -2
- package/dist/taiwan/invoice.cjs +3 -3
- package/dist/taiwan/invoice.js +2 -2
- package/dist/taiwan/license-plate.cjs +3 -3
- package/dist/taiwan/license-plate.js +2 -2
- package/dist/taiwan/mobile.cjs +3 -3
- package/dist/taiwan/mobile.js +2 -2
- package/dist/taiwan/national-id.cjs +3 -3
- package/dist/taiwan/national-id.js +2 -2
- package/dist/taiwan/passport.cjs +3 -3
- package/dist/taiwan/passport.js +2 -2
- package/dist/taiwan/postal-code.cjs +3 -3
- package/dist/taiwan/postal-code.js +2 -2
- package/dist/taiwan/tel.cjs +3 -3
- package/dist/taiwan/tel.js +2 -2
- package/package.json +15 -5
- package/src/i18n/locales/en-GB.json +19 -0
- package/src/i18n/locales/en-US.json +20 -1
- package/src/i18n/locales/id-ID.json +19 -0
- package/src/i18n/locales/ja-JP.json +19 -0
- package/src/i18n/locales/ko-KR.json +19 -0
- package/src/i18n/locales/ms-MY.json +19 -0
- package/src/i18n/locales/th-TH.json +19 -0
- package/src/i18n/locales/vi-VN.json +19 -0
- package/src/i18n/locales/zh-CN.json +19 -0
- package/src/i18n/locales/zh-TW.json +19 -0
- package/src/index.ts +2 -0
- package/src/validators/common/id.ts +45 -3
- package/src/validators/common/many-of.ts +219 -0
- package/src/validators/common/one-of.ts +172 -0
- package/tests/common/id.test.ts +68 -3
- package/tests/common/many-of.test.ts +198 -0
- package/tests/common/one-of.test.ts +136 -0
- package/tsup.config.ts +2 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkQ7TUNJD4cjs = require('./chunk-Q7TUNJD4.cjs');
|
|
5
5
|
|
|
6
6
|
// src/validators/common/credit-card.ts
|
|
7
7
|
var _zod = require('zod');
|
|
@@ -37,14 +37,14 @@ function creditCard(required, options) {
|
|
|
37
37
|
const actualDefaultValue = _nullishCoalesce(defaultValue, () => ( (isRequired ? "" : null)));
|
|
38
38
|
const getMessage = (key, params) => {
|
|
39
39
|
if (i18n) {
|
|
40
|
-
const currentLocale =
|
|
40
|
+
const currentLocale = _chunkQ7TUNJD4cjs.getLocale.call(void 0, );
|
|
41
41
|
const customMessages = i18n[currentLocale];
|
|
42
42
|
if (customMessages && customMessages[key]) {
|
|
43
43
|
const template = customMessages[key];
|
|
44
44
|
return template.replace(/\$\{(\w+)}/g, (_, k) => _nullishCoalesce(_optionalChain([params, 'optionalAccess', _2 => _2[k]]), () => ( "")));
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
return
|
|
47
|
+
return _chunkQ7TUNJD4cjs.t.call(void 0, `common.creditCard.${key}`, params);
|
|
48
48
|
};
|
|
49
49
|
const preprocessFn = (val) => {
|
|
50
50
|
if (val === "" || val === null || val === void 0) {
|
package/dist/common/boolean.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
3
|
+
var _chunkLNWEJED7cjs = require('../chunk-LNWEJED7.cjs');
|
|
4
|
+
require('../chunk-Q7TUNJD4.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
exports.boolean =
|
|
7
|
+
exports.boolean = _chunkLNWEJED7cjs.boolean;
|
package/dist/common/boolean.js
CHANGED
package/dist/common/color.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
5
|
-
require('../chunk-
|
|
4
|
+
var _chunkA2GAEU4Ocjs = require('../chunk-A2GAEU4O.cjs');
|
|
5
|
+
require('../chunk-Q7TUNJD4.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
exports.color =
|
|
9
|
+
exports.color = _chunkA2GAEU4Ocjs.color; exports.validateColor = _chunkA2GAEU4Ocjs.validateColor;
|
package/dist/common/color.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
require('../chunk-
|
|
5
|
+
var _chunkFEL432I2cjs = require('../chunk-FEL432I2.cjs');
|
|
6
|
+
require('../chunk-Q7TUNJD4.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
exports.coordinate =
|
|
11
|
+
exports.coordinate = _chunkFEL432I2cjs.coordinate; exports.validateLatitude = _chunkFEL432I2cjs.validateLatitude; exports.validateLongitude = _chunkFEL432I2cjs.validateLongitude;
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
require('../chunk-
|
|
5
|
+
var _chunkZCX22PY4cjs = require('../chunk-ZCX22PY4.cjs');
|
|
6
|
+
require('../chunk-Q7TUNJD4.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
exports.creditCard =
|
|
11
|
+
exports.creditCard = _chunkZCX22PY4cjs.creditCard; exports.detectCardType = _chunkZCX22PY4cjs.detectCardType; exports.validateCreditCard = _chunkZCX22PY4cjs.validateCreditCard;
|
package/dist/common/date.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
3
|
+
var _chunk4AQB4RSUcjs = require('../chunk-4AQB4RSU.cjs');
|
|
4
|
+
require('../chunk-Q7TUNJD4.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
exports.date =
|
|
7
|
+
exports.date = _chunk4AQB4RSUcjs.date;
|
package/dist/common/date.js
CHANGED
package/dist/common/datetime.cjs
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
8
|
-
require('../chunk-
|
|
7
|
+
var _chunk53EEWALQcjs = require('../chunk-53EEWALQ.cjs');
|
|
8
|
+
require('../chunk-Q7TUNJD4.cjs');
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
exports.DATETIME_PATTERNS =
|
|
15
|
+
exports.DATETIME_PATTERNS = _chunk53EEWALQcjs.DATETIME_PATTERNS; exports.datetime = _chunk53EEWALQcjs.datetime; exports.normalizeDateTimeValue = _chunk53EEWALQcjs.normalizeDateTimeValue; exports.parseDateTimeValue = _chunk53EEWALQcjs.parseDateTimeValue; exports.validateDateTimeFormat = _chunk53EEWALQcjs.validateDateTimeFormat;
|
package/dist/common/datetime.js
CHANGED
package/dist/common/email.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
3
|
+
var _chunkH25N5GP6cjs = require('../chunk-H25N5GP6.cjs');
|
|
4
|
+
require('../chunk-Q7TUNJD4.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
exports.email =
|
|
7
|
+
exports.email = _chunkH25N5GP6cjs.email;
|
package/dist/common/email.js
CHANGED
package/dist/common/file.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
3
|
+
var _chunkKIUO2HIRcjs = require('../chunk-KIUO2HIR.cjs');
|
|
4
|
+
require('../chunk-Q7TUNJD4.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
exports.file =
|
|
7
|
+
exports.file = _chunkKIUO2HIRcjs.file;
|
package/dist/common/file.js
CHANGED
package/dist/common/id.cjs
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
7
|
-
require('../chunk-
|
|
6
|
+
var _chunkJZEF5Q3Wcjs = require('../chunk-JZEF5Q3W.cjs');
|
|
7
|
+
require('../chunk-Q7TUNJD4.cjs');
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
exports.ID_PATTERNS =
|
|
13
|
+
exports.ID_PATTERNS = _chunkJZEF5Q3Wcjs.ID_PATTERNS; exports.detectIdType = _chunkJZEF5Q3Wcjs.detectIdType; exports.id = _chunkJZEF5Q3Wcjs.id; exports.validateIdType = _chunkJZEF5Q3Wcjs.validateIdType;
|
package/dist/common/id.d.cts
CHANGED
|
@@ -21,6 +21,14 @@ import { L as Locale } from '../config-CABSSvAp.cjs';
|
|
|
21
21
|
* @property {string} [maxLength] - Message when ID is too long
|
|
22
22
|
* @property {string} [numeric] - Message when numeric ID format is invalid
|
|
23
23
|
* @property {string} [uuid] - Message when UUID format is invalid
|
|
24
|
+
* @property {string} [uuidv1] - Message when UUID v1 format is invalid
|
|
25
|
+
* @property {string} [uuidv2] - Message when UUID v2 format is invalid
|
|
26
|
+
* @property {string} [uuidv3] - Message when UUID v3 format is invalid
|
|
27
|
+
* @property {string} [uuidv4] - Message when UUID v4 format is invalid
|
|
28
|
+
* @property {string} [uuidv5] - Message when UUID v5 format is invalid
|
|
29
|
+
* @property {string} [uuidv6] - Message when UUID v6 format is invalid
|
|
30
|
+
* @property {string} [uuidv7] - Message when UUID v7 format is invalid
|
|
31
|
+
* @property {string} [uuidv8] - Message when UUID v8 format is invalid
|
|
24
32
|
* @property {string} [objectId] - Message when MongoDB ObjectId format is invalid
|
|
25
33
|
* @property {string} [nanoid] - Message when Nano ID format is invalid
|
|
26
34
|
* @property {string} [snowflake] - Message when Snowflake ID format is invalid
|
|
@@ -40,6 +48,14 @@ type IdMessages = {
|
|
|
40
48
|
maxLength?: string;
|
|
41
49
|
numeric?: string;
|
|
42
50
|
uuid?: string;
|
|
51
|
+
uuidv1?: string;
|
|
52
|
+
uuidv2?: string;
|
|
53
|
+
uuidv3?: string;
|
|
54
|
+
uuidv4?: string;
|
|
55
|
+
uuidv5?: string;
|
|
56
|
+
uuidv6?: string;
|
|
57
|
+
uuidv7?: string;
|
|
58
|
+
uuidv8?: string;
|
|
43
59
|
objectId?: string;
|
|
44
60
|
nanoid?: string;
|
|
45
61
|
snowflake?: string;
|
|
@@ -59,7 +75,15 @@ type IdMessages = {
|
|
|
59
75
|
*
|
|
60
76
|
* Available types:
|
|
61
77
|
* - numeric: Pure numeric IDs (1, 123, 999999)
|
|
62
|
-
* - uuid: UUID
|
|
78
|
+
* - uuid: UUID any version (v1–v8)
|
|
79
|
+
* - uuidv1: UUID v1 (timestamp-based)
|
|
80
|
+
* - uuidv2: UUID v2 (DCE security)
|
|
81
|
+
* - uuidv3: UUID v3 (MD5 name-based)
|
|
82
|
+
* - uuidv4: UUID v4 (random)
|
|
83
|
+
* - uuidv5: UUID v5 (SHA-1 name-based)
|
|
84
|
+
* - uuidv6: UUID v6 (reordered timestamp, RFC 9562)
|
|
85
|
+
* - uuidv7: UUID v7 (Unix timestamp, sortable, RFC 9562)
|
|
86
|
+
* - uuidv8: UUID v8 (custom, RFC 9562)
|
|
63
87
|
* - objectId: MongoDB ObjectId (24-character hexadecimal)
|
|
64
88
|
* - nanoid: Nano ID format (21-character URL-safe)
|
|
65
89
|
* - snowflake: Twitter Snowflake (19-digit number)
|
|
@@ -68,7 +92,7 @@ type IdMessages = {
|
|
|
68
92
|
* - shortid: ShortId format (7-14 character URL-safe)
|
|
69
93
|
* - auto: Auto-detect format from the value
|
|
70
94
|
*/
|
|
71
|
-
type IdType = "numeric" | "uuid" | "objectId" | "nanoid" | "snowflake" | "cuid" | "ulid" | "shortid" | "auto";
|
|
95
|
+
type IdType = "numeric" | "uuid" | "uuidv1" | "uuidv2" | "uuidv3" | "uuidv4" | "uuidv5" | "uuidv6" | "uuidv7" | "uuidv8" | "objectId" | "nanoid" | "snowflake" | "cuid" | "ulid" | "shortid" | "auto";
|
|
72
96
|
/**
|
|
73
97
|
* Configuration options for ID validation
|
|
74
98
|
*
|
|
@@ -117,15 +141,17 @@ type IdOptions<Type extends IdType | undefined = undefined> = {
|
|
|
117
141
|
* - other types: ZodString or ZodNullable<ZodString>
|
|
118
142
|
*/
|
|
119
143
|
type IdSchema<IsRequired extends boolean, Type extends IdType | undefined = undefined> = Type extends "numeric" ? IsRequired extends true ? ZodNumber : ZodNullable<ZodNumber> : IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
120
|
-
/**
|
|
121
|
-
* Regular expression patterns for different ID formats
|
|
122
|
-
*
|
|
123
|
-
* @constant {Record<string, RegExp>} ID_PATTERNS
|
|
124
|
-
* @description Maps each ID type to its corresponding regex pattern
|
|
125
|
-
*/
|
|
126
144
|
declare const ID_PATTERNS: {
|
|
127
145
|
readonly numeric: RegExp;
|
|
128
146
|
readonly uuid: RegExp;
|
|
147
|
+
readonly uuidv1: RegExp;
|
|
148
|
+
readonly uuidv2: RegExp;
|
|
149
|
+
readonly uuidv3: RegExp;
|
|
150
|
+
readonly uuidv4: RegExp;
|
|
151
|
+
readonly uuidv5: RegExp;
|
|
152
|
+
readonly uuidv6: RegExp;
|
|
153
|
+
readonly uuidv7: RegExp;
|
|
154
|
+
readonly uuidv8: RegExp;
|
|
129
155
|
readonly objectId: RegExp;
|
|
130
156
|
readonly nanoid: RegExp;
|
|
131
157
|
readonly snowflake: RegExp;
|
package/dist/common/id.d.ts
CHANGED
|
@@ -21,6 +21,14 @@ import { L as Locale } from '../config-CABSSvAp.js';
|
|
|
21
21
|
* @property {string} [maxLength] - Message when ID is too long
|
|
22
22
|
* @property {string} [numeric] - Message when numeric ID format is invalid
|
|
23
23
|
* @property {string} [uuid] - Message when UUID format is invalid
|
|
24
|
+
* @property {string} [uuidv1] - Message when UUID v1 format is invalid
|
|
25
|
+
* @property {string} [uuidv2] - Message when UUID v2 format is invalid
|
|
26
|
+
* @property {string} [uuidv3] - Message when UUID v3 format is invalid
|
|
27
|
+
* @property {string} [uuidv4] - Message when UUID v4 format is invalid
|
|
28
|
+
* @property {string} [uuidv5] - Message when UUID v5 format is invalid
|
|
29
|
+
* @property {string} [uuidv6] - Message when UUID v6 format is invalid
|
|
30
|
+
* @property {string} [uuidv7] - Message when UUID v7 format is invalid
|
|
31
|
+
* @property {string} [uuidv8] - Message when UUID v8 format is invalid
|
|
24
32
|
* @property {string} [objectId] - Message when MongoDB ObjectId format is invalid
|
|
25
33
|
* @property {string} [nanoid] - Message when Nano ID format is invalid
|
|
26
34
|
* @property {string} [snowflake] - Message when Snowflake ID format is invalid
|
|
@@ -40,6 +48,14 @@ type IdMessages = {
|
|
|
40
48
|
maxLength?: string;
|
|
41
49
|
numeric?: string;
|
|
42
50
|
uuid?: string;
|
|
51
|
+
uuidv1?: string;
|
|
52
|
+
uuidv2?: string;
|
|
53
|
+
uuidv3?: string;
|
|
54
|
+
uuidv4?: string;
|
|
55
|
+
uuidv5?: string;
|
|
56
|
+
uuidv6?: string;
|
|
57
|
+
uuidv7?: string;
|
|
58
|
+
uuidv8?: string;
|
|
43
59
|
objectId?: string;
|
|
44
60
|
nanoid?: string;
|
|
45
61
|
snowflake?: string;
|
|
@@ -59,7 +75,15 @@ type IdMessages = {
|
|
|
59
75
|
*
|
|
60
76
|
* Available types:
|
|
61
77
|
* - numeric: Pure numeric IDs (1, 123, 999999)
|
|
62
|
-
* - uuid: UUID
|
|
78
|
+
* - uuid: UUID any version (v1–v8)
|
|
79
|
+
* - uuidv1: UUID v1 (timestamp-based)
|
|
80
|
+
* - uuidv2: UUID v2 (DCE security)
|
|
81
|
+
* - uuidv3: UUID v3 (MD5 name-based)
|
|
82
|
+
* - uuidv4: UUID v4 (random)
|
|
83
|
+
* - uuidv5: UUID v5 (SHA-1 name-based)
|
|
84
|
+
* - uuidv6: UUID v6 (reordered timestamp, RFC 9562)
|
|
85
|
+
* - uuidv7: UUID v7 (Unix timestamp, sortable, RFC 9562)
|
|
86
|
+
* - uuidv8: UUID v8 (custom, RFC 9562)
|
|
63
87
|
* - objectId: MongoDB ObjectId (24-character hexadecimal)
|
|
64
88
|
* - nanoid: Nano ID format (21-character URL-safe)
|
|
65
89
|
* - snowflake: Twitter Snowflake (19-digit number)
|
|
@@ -68,7 +92,7 @@ type IdMessages = {
|
|
|
68
92
|
* - shortid: ShortId format (7-14 character URL-safe)
|
|
69
93
|
* - auto: Auto-detect format from the value
|
|
70
94
|
*/
|
|
71
|
-
type IdType = "numeric" | "uuid" | "objectId" | "nanoid" | "snowflake" | "cuid" | "ulid" | "shortid" | "auto";
|
|
95
|
+
type IdType = "numeric" | "uuid" | "uuidv1" | "uuidv2" | "uuidv3" | "uuidv4" | "uuidv5" | "uuidv6" | "uuidv7" | "uuidv8" | "objectId" | "nanoid" | "snowflake" | "cuid" | "ulid" | "shortid" | "auto";
|
|
72
96
|
/**
|
|
73
97
|
* Configuration options for ID validation
|
|
74
98
|
*
|
|
@@ -117,15 +141,17 @@ type IdOptions<Type extends IdType | undefined = undefined> = {
|
|
|
117
141
|
* - other types: ZodString or ZodNullable<ZodString>
|
|
118
142
|
*/
|
|
119
143
|
type IdSchema<IsRequired extends boolean, Type extends IdType | undefined = undefined> = Type extends "numeric" ? IsRequired extends true ? ZodNumber : ZodNullable<ZodNumber> : IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
120
|
-
/**
|
|
121
|
-
* Regular expression patterns for different ID formats
|
|
122
|
-
*
|
|
123
|
-
* @constant {Record<string, RegExp>} ID_PATTERNS
|
|
124
|
-
* @description Maps each ID type to its corresponding regex pattern
|
|
125
|
-
*/
|
|
126
144
|
declare const ID_PATTERNS: {
|
|
127
145
|
readonly numeric: RegExp;
|
|
128
146
|
readonly uuid: RegExp;
|
|
147
|
+
readonly uuidv1: RegExp;
|
|
148
|
+
readonly uuidv2: RegExp;
|
|
149
|
+
readonly uuidv3: RegExp;
|
|
150
|
+
readonly uuidv4: RegExp;
|
|
151
|
+
readonly uuidv5: RegExp;
|
|
152
|
+
readonly uuidv6: RegExp;
|
|
153
|
+
readonly uuidv7: RegExp;
|
|
154
|
+
readonly uuidv8: RegExp;
|
|
129
155
|
readonly objectId: RegExp;
|
|
130
156
|
readonly nanoid: RegExp;
|
|
131
157
|
readonly snowflake: RegExp;
|
package/dist/common/id.js
CHANGED
package/dist/common/ip.cjs
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
require('../chunk-
|
|
5
|
+
var _chunkLXFRQLH4cjs = require('../chunk-LXFRQLH4.cjs');
|
|
6
|
+
require('../chunk-Q7TUNJD4.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
exports.ip =
|
|
11
|
+
exports.ip = _chunkLXFRQLH4cjs.ip; exports.validateIPv4 = _chunkLXFRQLH4cjs.validateIPv4; exports.validateIPv6 = _chunkLXFRQLH4cjs.validateIPv6;
|
package/dist/common/ip.js
CHANGED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { ZodType } from 'zod';
|
|
2
|
+
import { L as Locale } from '../config-CABSSvAp.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview ManyOf validator for Zod Kit
|
|
6
|
+
*
|
|
7
|
+
* Provides multi-select validation that restricts input to an array of values
|
|
8
|
+
* from a predefined set, with min/max selection, duplicate control, and transformation.
|
|
9
|
+
*
|
|
10
|
+
* @author Ong Hoe Yuan
|
|
11
|
+
* @version 0.2.2
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Type definition for manyOf validation error messages
|
|
16
|
+
*
|
|
17
|
+
* @interface ManyOfMessages
|
|
18
|
+
* @property {string} [required] - Message when field is required but empty
|
|
19
|
+
* @property {string} [invalid] - Message when a value is not in the allowed list
|
|
20
|
+
* @property {string} [minSelect] - Message when fewer than minimum items are selected
|
|
21
|
+
* @property {string} [maxSelect] - Message when more than maximum items are selected
|
|
22
|
+
* @property {string} [duplicate] - Message when duplicate values are found
|
|
23
|
+
*/
|
|
24
|
+
type ManyOfMessages = {
|
|
25
|
+
required?: string;
|
|
26
|
+
invalid?: string;
|
|
27
|
+
minSelect?: string;
|
|
28
|
+
maxSelect?: string;
|
|
29
|
+
duplicate?: string;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Configuration options for manyOf validation
|
|
33
|
+
*
|
|
34
|
+
* @template IsRequired - Whether the field is required (affects return type)
|
|
35
|
+
* @template T - The type of allowed values
|
|
36
|
+
*
|
|
37
|
+
* @interface ManyOfOptions
|
|
38
|
+
* @property {T[]} values - Array of allowed values
|
|
39
|
+
* @property {T[] | null} [defaultValue] - Default value when input is empty
|
|
40
|
+
* @property {number} [min] - Minimum number of selections
|
|
41
|
+
* @property {number} [max] - Maximum number of selections
|
|
42
|
+
* @property {boolean} [allowDuplicates=false] - Whether to allow duplicate selections
|
|
43
|
+
* @property {boolean} [caseSensitive=true] - Whether string matching is case-sensitive
|
|
44
|
+
* @property {Function} [transform] - Custom transformation function applied to each value
|
|
45
|
+
* @property {Record<Locale, ManyOfMessages>} [i18n] - Custom error messages for different locales
|
|
46
|
+
*/
|
|
47
|
+
type ManyOfOptions<IsRequired extends boolean = true, T extends string | number = string | number> = {
|
|
48
|
+
values: T[];
|
|
49
|
+
defaultValue?: IsRequired extends true ? T[] : T[] | null;
|
|
50
|
+
min?: number;
|
|
51
|
+
max?: number;
|
|
52
|
+
allowDuplicates?: boolean;
|
|
53
|
+
caseSensitive?: boolean;
|
|
54
|
+
transform?: (value: T[]) => T[];
|
|
55
|
+
i18n?: Partial<Record<Locale, Partial<ManyOfMessages>>>;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Type alias for manyOf validation schema based on required flag
|
|
59
|
+
*
|
|
60
|
+
* @template IsRequired - Whether the field is required
|
|
61
|
+
* @template T - The type of allowed values
|
|
62
|
+
*/
|
|
63
|
+
type ManyOfSchema<IsRequired extends boolean, T> = IsRequired extends true ? ZodType<T[]> : ZodType<T[] | null>;
|
|
64
|
+
/**
|
|
65
|
+
* Creates a Zod schema for multi-select validation that restricts values to a predefined set
|
|
66
|
+
*
|
|
67
|
+
* @template IsRequired - Whether the field is required (affects return type)
|
|
68
|
+
* @template T - The type of allowed values (string | number)
|
|
69
|
+
* @param {IsRequired} [required=false] - Whether the field is required
|
|
70
|
+
* @param {ManyOfOptions<IsRequired, T>} options - Configuration options (values is required)
|
|
71
|
+
* @returns {ManyOfSchema<IsRequired, T>} Zod schema for manyOf validation
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* // Basic multi-select (optional by default)
|
|
76
|
+
* const tagsSchema = manyOf(false, { values: ["js", "ts", "rust", "go"] })
|
|
77
|
+
* tagsSchema.parse(["js", "ts"]) // ✓ ["js", "ts"]
|
|
78
|
+
* tagsSchema.parse(null) // ✓ null
|
|
79
|
+
*
|
|
80
|
+
* // Required with min/max
|
|
81
|
+
* const skillsSchema = manyOf(true, {
|
|
82
|
+
* values: ["react", "vue", "angular", "svelte"],
|
|
83
|
+
* min: 1,
|
|
84
|
+
* max: 3,
|
|
85
|
+
* })
|
|
86
|
+
* skillsSchema.parse(["react"]) // ✓
|
|
87
|
+
* skillsSchema.parse([]) // ✗ minSelect
|
|
88
|
+
* skillsSchema.parse(["react", "vue", "angular", "svelte"]) // ✗ maxSelect
|
|
89
|
+
*
|
|
90
|
+
* // Case-insensitive matching
|
|
91
|
+
* const colorsSchema = manyOf(true, {
|
|
92
|
+
* values: ["red", "green", "blue"],
|
|
93
|
+
* caseSensitive: false,
|
|
94
|
+
* })
|
|
95
|
+
* colorsSchema.parse(["RED", "Green"]) // ✓ ["red", "green"]
|
|
96
|
+
*
|
|
97
|
+
* // No duplicates (default)
|
|
98
|
+
* const rolesSchema = manyOf(true, { values: ["admin", "editor", "viewer"] })
|
|
99
|
+
* rolesSchema.parse(["admin", "admin"]) // ✗ duplicate
|
|
100
|
+
*
|
|
101
|
+
* // Allow duplicates
|
|
102
|
+
* const itemsSchema = manyOf(true, {
|
|
103
|
+
* values: [1, 2, 3],
|
|
104
|
+
* allowDuplicates: true,
|
|
105
|
+
* })
|
|
106
|
+
* itemsSchema.parse([1, 1, 2]) // ✓ [1, 1, 2]
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
declare function manyOf<IsRequired extends boolean = false, T extends string | number = string | number>(required?: IsRequired, options?: Omit<ManyOfOptions<IsRequired, T>, "required">): ManyOfSchema<IsRequired, T>;
|
|
110
|
+
|
|
111
|
+
export { type ManyOfMessages, type ManyOfOptions, type ManyOfSchema, manyOf };
|