@hy_ong/zod-kit 0.2.2 → 0.2.4
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-JXY7APBU.js → chunk-2JGRV3JO.js} +1 -1
- package/dist/{chunk-FM3EZ72O.js → chunk-3QLUXIY2.js} +1 -1
- package/dist/chunk-3ZF5JO3F.js +61 -0
- package/dist/{chunk-STNHTRG7.cjs → chunk-4AQB4RSU.cjs} +3 -3
- package/dist/{chunk-OPQJWHXN.cjs → chunk-53EEWALQ.cjs} +3 -3
- package/dist/{chunk-ZNJLWJX3.cjs → chunk-5ZMTAI4G.cjs} +3 -3
- package/dist/{chunk-RKUQREMW.js → chunk-6DFP7XY2.js} +1 -1
- package/dist/{chunk-5LEXCVLX.js → chunk-6IAPM7BP.js} +1 -1
- package/dist/{chunk-RO47DKQG.js → chunk-7SKH66CM.js} +1 -1
- package/dist/chunk-7X3XPK6A.js +92 -0
- package/dist/{chunk-UBK3VCVH.cjs → chunk-A2GAEU4O.cjs} +3 -3
- package/dist/{chunk-KFOHKTFD.js → chunk-AI4U42JV.js} +1 -1
- package/dist/{chunk-ERH4NIMU.cjs → chunk-AYCXAJRA.cjs} +3 -3
- package/dist/{chunk-YDH3L27K.cjs → chunk-BZSPJJYT.cjs} +3 -3
- package/dist/chunk-BZWQPSHO.cjs +92 -0
- package/dist/{chunk-H2XTEM4M.js → chunk-D55YFP5R.js} +1 -1
- package/dist/{chunk-LL4ZWLGO.js → chunk-E52GRXYY.js} +1 -1
- package/dist/{chunk-RRPXIRTQ.cjs → chunk-EDTNS2XL.cjs} +3 -3
- package/dist/{chunk-RYFG2GKM.cjs → chunk-FEL432I2.cjs} +3 -3
- package/dist/chunk-FMPHW7ID.cjs +61 -0
- package/dist/{chunk-JOLSGZGN.cjs → chunk-FP4O2ICM.cjs} +3 -3
- package/dist/{chunk-EGHL277K.cjs → chunk-G747FHUZ.cjs} +3 -3
- package/dist/{chunk-5JGTDL3Y.js → chunk-G7FLGJYD.js} +1 -1
- package/dist/{chunk-HMSM6FFA.cjs → chunk-H25N5GP6.cjs} +3 -3
- package/dist/{chunk-MHJFYYGV.js → chunk-H6STFX4I.js} +1 -1
- package/dist/{chunk-EDHT4LPO.js → chunk-HQ4RAMSD.js} +1 -1
- package/dist/{chunk-ORFHDJII.cjs → chunk-HZ2WESSL.cjs} +3 -3
- package/dist/{chunk-ORVV4MCF.cjs → chunk-IWR3H7IH.cjs} +3 -3
- package/dist/{chunk-B4EZYZOK.cjs → chunk-JZEF5Q3W.cjs} +3 -3
- package/dist/{chunk-HTEHINI7.cjs → chunk-KIUO2HIR.cjs} +3 -3
- package/dist/{chunk-QICQ6YEY.js → chunk-LBH5U2DZ.js} +1 -1
- package/dist/{chunk-42C5OHRK.js → chunk-LC4RNKBM.js} +1 -1
- package/dist/{chunk-TFGS34VD.cjs → chunk-LNWEJED7.cjs} +3 -3
- package/dist/{chunk-32JI34CV.cjs → chunk-LXFRQLH4.cjs} +3 -3
- package/dist/{chunk-46VAH2BJ.js → chunk-NWQSOSNF.js} +1 -1
- package/dist/{chunk-WDI4QJMQ.js → chunk-OGU7AIZF.js} +1 -1
- package/dist/{chunk-YIM3D2AD.js → chunk-OKO6WO6M.js} +1 -1
- package/dist/{chunk-MINMXGW3.js → chunk-OSUPJCBA.js} +1 -1
- package/dist/{chunk-6AAP4LPF.js → chunk-POIDES2L.js} +110 -0
- package/dist/{chunk-YPSEIDUR.cjs → chunk-Q24GYUTO.cjs} +3 -3
- package/dist/{chunk-UCOXAZJF.cjs → chunk-Q7TUNJD4.cjs} +110 -0
- package/dist/{chunk-L4HSIKTU.cjs → chunk-QQWX3ICK.cjs} +3 -3
- package/dist/{chunk-COYKBWTI.js → chunk-RFWCYULE.js} +1 -1
- package/dist/{chunk-ZXUMK2RR.js → chunk-RHKBT3M2.js} +1 -1
- package/dist/{chunk-LH7ZB4BK.js → chunk-RVGCMQ4J.js} +1 -1
- package/dist/{chunk-K2UOY6TB.js → chunk-T7PG4JDW.js} +1 -1
- package/dist/{chunk-DFJZ3NS2.cjs → chunk-TDEXEIHH.cjs} +3 -3
- package/dist/{chunk-GJIRDBZJ.cjs → chunk-TPXRQT2H.cjs} +3 -3
- package/dist/{chunk-UQZKFAFX.js → chunk-TRQMRHFM.js} +1 -1
- package/dist/{chunk-WABKPFPK.js → chunk-U2PB6XEO.js} +1 -1
- package/dist/{chunk-ZTFCJCPO.cjs → chunk-UCPKW43K.cjs} +3 -3
- package/dist/{chunk-TQXDUMML.cjs → chunk-V2KKGSKQ.cjs} +3 -3
- package/dist/{chunk-VB2KV2ZM.cjs → chunk-VKBNKPFO.cjs} +3 -3
- package/dist/{chunk-MM7IL2RG.js → chunk-XAN4CAVH.js} +1 -1
- package/dist/{chunk-M6MTP3NY.cjs → chunk-ZCX22PY4.cjs} +3 -3
- package/dist/{chunk-2SWEVDFZ.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.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 +11 -1
- package/src/i18n/locales/en-GB.json +11 -0
- package/src/i18n/locales/en-US.json +11 -0
- package/src/i18n/locales/id-ID.json +11 -0
- package/src/i18n/locales/ja-JP.json +11 -0
- package/src/i18n/locales/ko-KR.json +11 -0
- package/src/i18n/locales/ms-MY.json +11 -0
- package/src/i18n/locales/th-TH.json +11 -0
- package/src/i18n/locales/vi-VN.json +11 -0
- package/src/i18n/locales/zh-CN.json +11 -0
- package/src/i18n/locales/zh-TW.json +11 -0
- package/src/index.ts +2 -0
- package/src/validators/common/many-of.ts +219 -0
- package/src/validators/common/one-of.ts +172 -0
- package/tests/common/many-of.test.ts +198 -0
- package/tests/common/one-of.test.ts +136 -0
- package/tsup.config.ts +2 -0
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.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, V extends readonly (string | number)[] = readonly (string | number)[]> = {
|
|
48
|
+
values: V;
|
|
49
|
+
defaultValue?: IsRequired extends true ? V[number][] : V[number][] | null;
|
|
50
|
+
min?: number;
|
|
51
|
+
max?: number;
|
|
52
|
+
allowDuplicates?: boolean;
|
|
53
|
+
caseSensitive?: boolean;
|
|
54
|
+
transform?: (value: V[number][]) => V[number][];
|
|
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, V extends readonly (string | number)[]> = IsRequired extends true ? ZodType<V[number][]> : ZodType<V[number][] | 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, const V extends readonly (string | number)[] = readonly (string | number)[]>(required?: IsRequired, options?: Omit<ManyOfOptions<IsRequired, V>, "required">): ManyOfSchema<IsRequired, V>;
|
|
110
|
+
|
|
111
|
+
export { type ManyOfMessages, type ManyOfOptions, type ManyOfSchema, manyOf };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { ZodType } from 'zod';
|
|
2
|
+
import { L as Locale } from '../config-CABSSvAp.js';
|
|
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, V extends readonly (string | number)[] = readonly (string | number)[]> = {
|
|
48
|
+
values: V;
|
|
49
|
+
defaultValue?: IsRequired extends true ? V[number][] : V[number][] | null;
|
|
50
|
+
min?: number;
|
|
51
|
+
max?: number;
|
|
52
|
+
allowDuplicates?: boolean;
|
|
53
|
+
caseSensitive?: boolean;
|
|
54
|
+
transform?: (value: V[number][]) => V[number][];
|
|
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, V extends readonly (string | number)[]> = IsRequired extends true ? ZodType<V[number][]> : ZodType<V[number][] | 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, const V extends readonly (string | number)[] = readonly (string | number)[]>(required?: IsRequired, options?: Omit<ManyOfOptions<IsRequired, V>, "required">): ManyOfSchema<IsRequired, V>;
|
|
110
|
+
|
|
111
|
+
export { type ManyOfMessages, type ManyOfOptions, type ManyOfSchema, manyOf };
|
package/dist/common/number.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 _chunkG747FHUZcjs = require('../chunk-G747FHUZ.cjs');
|
|
4
|
+
require('../chunk-Q7TUNJD4.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
exports.number =
|
|
7
|
+
exports.number = _chunkG747FHUZcjs.number;
|
package/dist/common/number.js
CHANGED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { ZodType } from 'zod';
|
|
2
|
+
import { L as Locale } from '../config-CABSSvAp.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview OneOf validator for Zod Kit
|
|
6
|
+
*
|
|
7
|
+
* Provides single-select validation that restricts input to a predefined set of allowed values,
|
|
8
|
+
* with support for case-insensitive matching, default values, and transformation.
|
|
9
|
+
*
|
|
10
|
+
* @author Ong Hoe Yuan
|
|
11
|
+
* @version 0.2.2
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Type definition for oneOf validation error messages
|
|
16
|
+
*
|
|
17
|
+
* @interface OneOfMessages
|
|
18
|
+
* @property {string} [required] - Message when field is required but empty
|
|
19
|
+
* @property {string} [invalid] - Message when value is not in the allowed list
|
|
20
|
+
*/
|
|
21
|
+
type OneOfMessages = {
|
|
22
|
+
required?: string;
|
|
23
|
+
invalid?: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Configuration options for oneOf validation
|
|
27
|
+
*
|
|
28
|
+
* @template IsRequired - Whether the field is required (affects return type)
|
|
29
|
+
* @template T - The type of allowed values
|
|
30
|
+
*
|
|
31
|
+
* @interface OneOfOptions
|
|
32
|
+
* @property {T[]} values - Array of allowed values
|
|
33
|
+
* @property {T | null} [defaultValue] - Default value when input is empty
|
|
34
|
+
* @property {boolean} [caseSensitive=true] - Whether string matching is case-sensitive
|
|
35
|
+
* @property {Function} [transform] - Custom transformation function applied after validation
|
|
36
|
+
* @property {Record<Locale, OneOfMessages>} [i18n] - Custom error messages for different locales
|
|
37
|
+
*/
|
|
38
|
+
type OneOfOptions<IsRequired extends boolean = true, V extends readonly (string | number)[] = readonly (string | number)[]> = {
|
|
39
|
+
values: V;
|
|
40
|
+
defaultValue?: IsRequired extends true ? V[number] : V[number] | null;
|
|
41
|
+
caseSensitive?: boolean;
|
|
42
|
+
transform?: (value: V[number]) => V[number];
|
|
43
|
+
i18n?: Partial<Record<Locale, Partial<OneOfMessages>>>;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Type alias for oneOf validation schema based on required flag
|
|
47
|
+
*
|
|
48
|
+
* @template IsRequired - Whether the field is required
|
|
49
|
+
* @template T - The type of allowed values
|
|
50
|
+
*/
|
|
51
|
+
type OneOfSchema<IsRequired extends boolean, V extends readonly (string | number)[]> = IsRequired extends true ? ZodType<V[number]> : ZodType<V[number] | null>;
|
|
52
|
+
/**
|
|
53
|
+
* Creates a Zod schema for single-select validation that restricts values to a predefined set
|
|
54
|
+
*
|
|
55
|
+
* @template IsRequired - Whether the field is required (affects return type)
|
|
56
|
+
* @template T - The type of allowed values (string | number)
|
|
57
|
+
* @param {IsRequired} [required=false] - Whether the field is required
|
|
58
|
+
* @param {OneOfOptions<IsRequired, T>} options - Configuration options (values is required)
|
|
59
|
+
* @returns {OneOfSchema<IsRequired, T>} Zod schema for oneOf validation
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* // Basic single-select validation (optional by default)
|
|
64
|
+
* const roleSchema = oneOf(false, { values: ["admin", "editor", "viewer"] })
|
|
65
|
+
* roleSchema.parse("admin") // ✓ "admin"
|
|
66
|
+
* roleSchema.parse(null) // ✓ null
|
|
67
|
+
*
|
|
68
|
+
* // Required
|
|
69
|
+
* const statusSchema = oneOf(true, { values: ["active", "inactive", "pending"] })
|
|
70
|
+
* statusSchema.parse("active") // ✓ "active"
|
|
71
|
+
* statusSchema.parse(null) // ✗ Required
|
|
72
|
+
* statusSchema.parse("banned") // ✗ Invalid
|
|
73
|
+
*
|
|
74
|
+
* // Numeric values
|
|
75
|
+
* const prioritySchema = oneOf(true, { values: [1, 2, 3, 4, 5] })
|
|
76
|
+
* prioritySchema.parse(3) // ✓ 3
|
|
77
|
+
* prioritySchema.parse(10) // ✗ Invalid
|
|
78
|
+
*
|
|
79
|
+
* // Case-insensitive matching
|
|
80
|
+
* const colorSchema = oneOf(true, {
|
|
81
|
+
* values: ["red", "green", "blue"],
|
|
82
|
+
* caseSensitive: false
|
|
83
|
+
* })
|
|
84
|
+
* colorSchema.parse("RED") // ✓ "red" (normalized to match original)
|
|
85
|
+
* colorSchema.parse("Green") // ✓ "green"
|
|
86
|
+
*
|
|
87
|
+
* // With default value
|
|
88
|
+
* const tierSchema = oneOf(false, {
|
|
89
|
+
* values: ["free", "pro", "enterprise"],
|
|
90
|
+
* defaultValue: "free"
|
|
91
|
+
* })
|
|
92
|
+
* tierSchema.parse(null) // ✓ "free"
|
|
93
|
+
*
|
|
94
|
+
* // With transform
|
|
95
|
+
* const sizeSchema = oneOf(true, {
|
|
96
|
+
* values: ["s", "m", "l", "xl"],
|
|
97
|
+
* transform: (val) => val.toUpperCase() as any
|
|
98
|
+
* })
|
|
99
|
+
* sizeSchema.parse("m") // ✓ "M"
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
declare function oneOf<IsRequired extends boolean = false, const V extends readonly (string | number)[] = readonly (string | number)[]>(required?: IsRequired, options?: Omit<OneOfOptions<IsRequired, V>, "required">): OneOfSchema<IsRequired, V>;
|
|
103
|
+
|
|
104
|
+
export { type OneOfMessages, type OneOfOptions, type OneOfSchema, oneOf };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { ZodType } from 'zod';
|
|
2
|
+
import { L as Locale } from '../config-CABSSvAp.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview OneOf validator for Zod Kit
|
|
6
|
+
*
|
|
7
|
+
* Provides single-select validation that restricts input to a predefined set of allowed values,
|
|
8
|
+
* with support for case-insensitive matching, default values, and transformation.
|
|
9
|
+
*
|
|
10
|
+
* @author Ong Hoe Yuan
|
|
11
|
+
* @version 0.2.2
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Type definition for oneOf validation error messages
|
|
16
|
+
*
|
|
17
|
+
* @interface OneOfMessages
|
|
18
|
+
* @property {string} [required] - Message when field is required but empty
|
|
19
|
+
* @property {string} [invalid] - Message when value is not in the allowed list
|
|
20
|
+
*/
|
|
21
|
+
type OneOfMessages = {
|
|
22
|
+
required?: string;
|
|
23
|
+
invalid?: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Configuration options for oneOf validation
|
|
27
|
+
*
|
|
28
|
+
* @template IsRequired - Whether the field is required (affects return type)
|
|
29
|
+
* @template T - The type of allowed values
|
|
30
|
+
*
|
|
31
|
+
* @interface OneOfOptions
|
|
32
|
+
* @property {T[]} values - Array of allowed values
|
|
33
|
+
* @property {T | null} [defaultValue] - Default value when input is empty
|
|
34
|
+
* @property {boolean} [caseSensitive=true] - Whether string matching is case-sensitive
|
|
35
|
+
* @property {Function} [transform] - Custom transformation function applied after validation
|
|
36
|
+
* @property {Record<Locale, OneOfMessages>} [i18n] - Custom error messages for different locales
|
|
37
|
+
*/
|
|
38
|
+
type OneOfOptions<IsRequired extends boolean = true, V extends readonly (string | number)[] = readonly (string | number)[]> = {
|
|
39
|
+
values: V;
|
|
40
|
+
defaultValue?: IsRequired extends true ? V[number] : V[number] | null;
|
|
41
|
+
caseSensitive?: boolean;
|
|
42
|
+
transform?: (value: V[number]) => V[number];
|
|
43
|
+
i18n?: Partial<Record<Locale, Partial<OneOfMessages>>>;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Type alias for oneOf validation schema based on required flag
|
|
47
|
+
*
|
|
48
|
+
* @template IsRequired - Whether the field is required
|
|
49
|
+
* @template T - The type of allowed values
|
|
50
|
+
*/
|
|
51
|
+
type OneOfSchema<IsRequired extends boolean, V extends readonly (string | number)[]> = IsRequired extends true ? ZodType<V[number]> : ZodType<V[number] | null>;
|
|
52
|
+
/**
|
|
53
|
+
* Creates a Zod schema for single-select validation that restricts values to a predefined set
|
|
54
|
+
*
|
|
55
|
+
* @template IsRequired - Whether the field is required (affects return type)
|
|
56
|
+
* @template T - The type of allowed values (string | number)
|
|
57
|
+
* @param {IsRequired} [required=false] - Whether the field is required
|
|
58
|
+
* @param {OneOfOptions<IsRequired, T>} options - Configuration options (values is required)
|
|
59
|
+
* @returns {OneOfSchema<IsRequired, T>} Zod schema for oneOf validation
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* // Basic single-select validation (optional by default)
|
|
64
|
+
* const roleSchema = oneOf(false, { values: ["admin", "editor", "viewer"] })
|
|
65
|
+
* roleSchema.parse("admin") // ✓ "admin"
|
|
66
|
+
* roleSchema.parse(null) // ✓ null
|
|
67
|
+
*
|
|
68
|
+
* // Required
|
|
69
|
+
* const statusSchema = oneOf(true, { values: ["active", "inactive", "pending"] })
|
|
70
|
+
* statusSchema.parse("active") // ✓ "active"
|
|
71
|
+
* statusSchema.parse(null) // ✗ Required
|
|
72
|
+
* statusSchema.parse("banned") // ✗ Invalid
|
|
73
|
+
*
|
|
74
|
+
* // Numeric values
|
|
75
|
+
* const prioritySchema = oneOf(true, { values: [1, 2, 3, 4, 5] })
|
|
76
|
+
* prioritySchema.parse(3) // ✓ 3
|
|
77
|
+
* prioritySchema.parse(10) // ✗ Invalid
|
|
78
|
+
*
|
|
79
|
+
* // Case-insensitive matching
|
|
80
|
+
* const colorSchema = oneOf(true, {
|
|
81
|
+
* values: ["red", "green", "blue"],
|
|
82
|
+
* caseSensitive: false
|
|
83
|
+
* })
|
|
84
|
+
* colorSchema.parse("RED") // ✓ "red" (normalized to match original)
|
|
85
|
+
* colorSchema.parse("Green") // ✓ "green"
|
|
86
|
+
*
|
|
87
|
+
* // With default value
|
|
88
|
+
* const tierSchema = oneOf(false, {
|
|
89
|
+
* values: ["free", "pro", "enterprise"],
|
|
90
|
+
* defaultValue: "free"
|
|
91
|
+
* })
|
|
92
|
+
* tierSchema.parse(null) // ✓ "free"
|
|
93
|
+
*
|
|
94
|
+
* // With transform
|
|
95
|
+
* const sizeSchema = oneOf(true, {
|
|
96
|
+
* values: ["s", "m", "l", "xl"],
|
|
97
|
+
* transform: (val) => val.toUpperCase() as any
|
|
98
|
+
* })
|
|
99
|
+
* sizeSchema.parse("m") // ✓ "M"
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
declare function oneOf<IsRequired extends boolean = false, const V extends readonly (string | number)[] = readonly (string | number)[]>(required?: IsRequired, options?: Omit<OneOfOptions<IsRequired, V>, "required">): OneOfSchema<IsRequired, V>;
|
|
103
|
+
|
|
104
|
+
export { type OneOfMessages, type OneOfOptions, type OneOfSchema, oneOf };
|
package/dist/common/password.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 _chunkQ24GYUTOcjs = require('../chunk-Q24GYUTO.cjs');
|
|
4
|
+
require('../chunk-Q7TUNJD4.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
exports.password =
|
|
7
|
+
exports.password = _chunkQ24GYUTOcjs.password;
|
package/dist/common/password.js
CHANGED
package/dist/common/text.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 _chunkHZ2WESSLcjs = require('../chunk-HZ2WESSL.cjs');
|
|
4
|
+
require('../chunk-Q7TUNJD4.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
exports.text =
|
|
7
|
+
exports.text = _chunkHZ2WESSLcjs.text;
|