@hy_ong/zod-kit 0.2.0 → 0.2.2
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/.github/workflows/ci.yml +24 -0
- package/CLAUDE.md +64 -22
- package/dist/chunk-2SWEVDFZ.js +134 -0
- package/dist/chunk-32JI34CV.cjs +146 -0
- package/dist/chunk-42C5OHRK.js +71 -0
- package/dist/chunk-46VAH2BJ.js +160 -0
- package/dist/chunk-5JGTDL3Y.js +87 -0
- package/dist/chunk-5LEXCVLX.js +257 -0
- package/dist/chunk-6AAP4LPF.js +2606 -0
- package/dist/chunk-B4EZYZOK.cjs +215 -0
- package/dist/chunk-COYKBWTI.js +161 -0
- package/dist/chunk-DFJZ3NS2.cjs +151 -0
- package/dist/chunk-EDHT4LPO.js +118 -0
- package/dist/chunk-EGHL277K.cjs +165 -0
- package/dist/chunk-ERH4NIMU.cjs +69 -0
- package/dist/chunk-FM3EZ72O.js +165 -0
- package/dist/chunk-GJIRDBZJ.cjs +90 -0
- package/dist/chunk-H2XTEM4M.js +696 -0
- package/dist/chunk-HMSM6FFA.cjs +181 -0
- package/dist/chunk-HTEHINI7.cjs +177 -0
- package/dist/chunk-JOLSGZGN.cjs +696 -0
- package/dist/chunk-JXY7APBU.js +69 -0
- package/dist/chunk-K2UOY6TB.js +136 -0
- package/dist/chunk-KFOHKTFD.js +61 -0
- package/dist/chunk-L4HSIKTU.cjs +135 -0
- package/dist/chunk-LH7ZB4BK.js +124 -0
- package/dist/chunk-LL4ZWLGO.js +90 -0
- package/dist/chunk-M6MTP3NY.cjs +99 -0
- package/dist/chunk-MHJFYYGV.js +215 -0
- package/dist/chunk-MINMXGW3.js +135 -0
- package/dist/chunk-MM7IL2RG.js +181 -0
- package/dist/chunk-OPQJWHXN.cjs +301 -0
- package/dist/chunk-ORFHDJII.cjs +136 -0
- package/dist/chunk-ORVV4MCF.cjs +87 -0
- package/dist/chunk-QICQ6YEY.js +75 -0
- package/dist/chunk-RKUQREMW.js +127 -0
- package/dist/chunk-RO47DKQG.js +146 -0
- package/dist/chunk-RRPXIRTQ.cjs +257 -0
- package/dist/chunk-RYFG2GKM.cjs +118 -0
- package/dist/chunk-STNHTRG7.cjs +124 -0
- package/dist/chunk-TFGS34VD.cjs +71 -0
- package/dist/chunk-TQXDUMML.cjs +61 -0
- package/dist/chunk-UBK3VCVH.cjs +134 -0
- package/dist/chunk-UCOXAZJF.cjs +2606 -0
- package/dist/chunk-UQZKFAFX.js +130 -0
- package/dist/chunk-VB2KV2ZM.cjs +130 -0
- package/dist/chunk-WABKPFPK.js +151 -0
- package/dist/chunk-WDI4QJMQ.js +177 -0
- package/dist/chunk-YDH3L27K.cjs +127 -0
- package/dist/chunk-YIM3D2AD.js +99 -0
- package/dist/chunk-YPSEIDUR.cjs +160 -0
- package/dist/chunk-ZNJLWJX3.cjs +75 -0
- package/dist/chunk-ZTFCJCPO.cjs +161 -0
- package/dist/chunk-ZXUMK2RR.js +301 -0
- package/dist/common/boolean.cjs +7 -0
- package/dist/common/boolean.d.cts +119 -0
- package/dist/common/boolean.d.ts +119 -0
- package/dist/common/boolean.js +7 -0
- package/dist/common/color.cjs +9 -0
- package/dist/common/color.d.cts +26 -0
- package/dist/common/color.d.ts +26 -0
- package/dist/common/color.js +9 -0
- package/dist/common/coordinate.cjs +11 -0
- package/dist/common/coordinate.d.cts +23 -0
- package/dist/common/coordinate.d.ts +23 -0
- package/dist/common/coordinate.js +11 -0
- package/dist/common/credit-card.cjs +11 -0
- package/dist/common/credit-card.d.cts +22 -0
- package/dist/common/credit-card.d.ts +22 -0
- package/dist/common/credit-card.js +11 -0
- package/dist/common/date.cjs +7 -0
- package/dist/common/date.d.cts +174 -0
- package/dist/common/date.d.ts +174 -0
- package/dist/common/date.js +7 -0
- package/dist/common/datetime.cjs +15 -0
- package/dist/common/datetime.d.cts +301 -0
- package/dist/common/datetime.d.ts +301 -0
- package/dist/common/datetime.js +15 -0
- package/dist/common/email.cjs +7 -0
- package/dist/common/email.d.cts +149 -0
- package/dist/common/email.d.ts +149 -0
- package/dist/common/email.js +7 -0
- package/dist/common/file.cjs +7 -0
- package/dist/common/file.d.cts +178 -0
- package/dist/common/file.d.ts +178 -0
- package/dist/common/file.js +7 -0
- package/dist/common/id.cjs +13 -0
- package/dist/common/id.d.cts +288 -0
- package/dist/common/id.d.ts +288 -0
- package/dist/common/id.js +13 -0
- package/dist/common/ip.cjs +11 -0
- package/dist/common/ip.d.cts +25 -0
- package/dist/common/ip.d.ts +25 -0
- package/dist/common/ip.js +11 -0
- package/dist/common/number.cjs +7 -0
- package/dist/common/number.d.cts +167 -0
- package/dist/common/number.d.ts +167 -0
- package/dist/common/number.js +7 -0
- package/dist/common/password.cjs +7 -0
- package/dist/common/password.d.cts +192 -0
- package/dist/common/password.d.ts +192 -0
- package/dist/common/password.js +7 -0
- package/dist/common/text.cjs +7 -0
- package/dist/common/text.d.cts +156 -0
- package/dist/common/text.d.ts +156 -0
- package/dist/common/text.js +7 -0
- package/dist/common/time.cjs +15 -0
- package/dist/common/time.d.cts +268 -0
- package/dist/common/time.d.ts +268 -0
- package/dist/common/time.js +15 -0
- package/dist/common/url.cjs +7 -0
- package/dist/common/url.d.cts +196 -0
- package/dist/common/url.d.ts +196 -0
- package/dist/common/url.js +7 -0
- package/dist/config-CABSSvAp.d.cts +5 -0
- package/dist/config-CABSSvAp.d.ts +5 -0
- package/dist/index.cjs +180 -5255
- package/dist/index.d.cts +28 -3150
- package/dist/index.d.ts +28 -3150
- package/dist/index.js +135 -5131
- package/dist/taiwan/bank-account.cjs +11 -0
- package/dist/taiwan/bank-account.d.cts +22 -0
- package/dist/taiwan/bank-account.d.ts +22 -0
- package/dist/taiwan/bank-account.js +11 -0
- package/dist/taiwan/business-id.cjs +9 -0
- package/dist/taiwan/business-id.d.cts +133 -0
- package/dist/taiwan/business-id.d.ts +133 -0
- package/dist/taiwan/business-id.js +9 -0
- package/dist/taiwan/fax.cjs +9 -0
- package/dist/taiwan/fax.d.cts +157 -0
- package/dist/taiwan/fax.d.ts +157 -0
- package/dist/taiwan/fax.js +9 -0
- package/dist/taiwan/invoice.cjs +9 -0
- package/dist/taiwan/invoice.d.cts +17 -0
- package/dist/taiwan/invoice.d.ts +17 -0
- package/dist/taiwan/invoice.js +9 -0
- package/dist/taiwan/license-plate.cjs +9 -0
- package/dist/taiwan/license-plate.d.cts +19 -0
- package/dist/taiwan/license-plate.d.ts +19 -0
- package/dist/taiwan/license-plate.js +9 -0
- package/dist/taiwan/mobile.cjs +9 -0
- package/dist/taiwan/mobile.d.cts +146 -0
- package/dist/taiwan/mobile.d.ts +146 -0
- package/dist/taiwan/mobile.js +9 -0
- package/dist/taiwan/national-id.cjs +15 -0
- package/dist/taiwan/national-id.d.cts +214 -0
- package/dist/taiwan/national-id.d.ts +214 -0
- package/dist/taiwan/national-id.js +15 -0
- package/dist/taiwan/passport.cjs +9 -0
- package/dist/taiwan/passport.d.cts +19 -0
- package/dist/taiwan/passport.d.ts +19 -0
- package/dist/taiwan/passport.js +9 -0
- package/dist/taiwan/postal-code.cjs +17 -0
- package/dist/taiwan/postal-code.d.cts +237 -0
- package/dist/taiwan/postal-code.d.ts +237 -0
- package/dist/taiwan/postal-code.js +17 -0
- package/dist/taiwan/tel.cjs +9 -0
- package/dist/taiwan/tel.d.cts +162 -0
- package/dist/taiwan/tel.d.ts +162 -0
- package/dist/taiwan/tel.js +9 -0
- package/package.json +132 -6
- package/src/i18n/locales/en-GB.json +51 -0
- package/src/i18n/locales/en-US.json +52 -1
- package/src/i18n/locales/id-ID.json +51 -0
- package/src/i18n/locales/ja-JP.json +51 -0
- package/src/i18n/locales/ko-KR.json +51 -0
- package/src/i18n/locales/ms-MY.json +51 -0
- package/src/i18n/locales/th-TH.json +51 -0
- package/src/i18n/locales/vi-VN.json +51 -0
- package/src/i18n/locales/zh-CN.json +51 -0
- package/src/i18n/locales/zh-TW.json +51 -0
- package/src/index.ts +10 -2
- package/src/validators/common/color.ts +192 -0
- package/src/validators/common/coordinate.ts +159 -0
- package/src/validators/common/credit-card.ts +134 -0
- package/src/validators/common/id.ts +45 -3
- package/src/validators/common/ip.ts +210 -0
- package/src/validators/taiwan/bank-account.ts +176 -0
- package/src/validators/taiwan/invoice.ts +84 -0
- package/src/validators/taiwan/license-plate.ts +110 -0
- package/src/validators/taiwan/passport.ts +103 -0
- package/tests/common/color.test.ts +587 -0
- package/tests/common/coordinate.test.ts +345 -0
- package/tests/common/credit-card.test.ts +378 -0
- package/tests/common/id.test.ts +68 -3
- package/tests/common/ip.test.ts +419 -0
- package/tests/taiwan/bank-account.test.ts +286 -0
- package/tests/taiwan/invoice.test.ts +227 -0
- package/tests/taiwan/license-plate.test.ts +280 -0
- package/tests/taiwan/passport.test.ts +277 -0
- package/tsup.config.ts +36 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ZodString, ZodNullable } from 'zod';
|
|
2
|
+
import { L as Locale } from '../config-CABSSvAp.js';
|
|
3
|
+
|
|
4
|
+
type CoordinateType = "latitude" | "longitude" | "pair";
|
|
5
|
+
type CoordinateMessages = {
|
|
6
|
+
required?: string;
|
|
7
|
+
invalid?: string;
|
|
8
|
+
invalidLatitude?: string;
|
|
9
|
+
invalidLongitude?: string;
|
|
10
|
+
};
|
|
11
|
+
type CoordinateOptions<IsRequired extends boolean = true> = {
|
|
12
|
+
type?: CoordinateType;
|
|
13
|
+
precision?: number;
|
|
14
|
+
transform?: (value: string) => string;
|
|
15
|
+
defaultValue?: IsRequired extends true ? string : string | null;
|
|
16
|
+
i18n?: Partial<Record<Locale, Partial<CoordinateMessages>>>;
|
|
17
|
+
};
|
|
18
|
+
type CoordinateSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
19
|
+
declare function validateLatitude(value: number): boolean;
|
|
20
|
+
declare function validateLongitude(value: number): boolean;
|
|
21
|
+
declare function coordinate<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<CoordinateOptions<IsRequired>, "required">): CoordinateSchema<IsRequired>;
|
|
22
|
+
|
|
23
|
+
export { type CoordinateMessages, type CoordinateOptions, type CoordinateSchema, type CoordinateType, coordinate, validateLatitude, validateLongitude };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var _chunkM6MTP3NYcjs = require('../chunk-M6MTP3NY.cjs');
|
|
6
|
+
require('../chunk-UCOXAZJF.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
exports.creditCard = _chunkM6MTP3NYcjs.creditCard; exports.detectCardType = _chunkM6MTP3NYcjs.detectCardType; exports.validateCreditCard = _chunkM6MTP3NYcjs.validateCreditCard;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ZodString, ZodNullable } from 'zod';
|
|
2
|
+
import { L as Locale } from '../config-CABSSvAp.cjs';
|
|
3
|
+
|
|
4
|
+
type CreditCardType = "visa" | "mastercard" | "amex" | "jcb" | "discover" | "unionpay" | "any";
|
|
5
|
+
type CreditCardMessages = {
|
|
6
|
+
required?: string;
|
|
7
|
+
invalid?: string;
|
|
8
|
+
notInWhitelist?: string;
|
|
9
|
+
};
|
|
10
|
+
type CreditCardOptions<IsRequired extends boolean = true> = {
|
|
11
|
+
cardType?: CreditCardType | CreditCardType[];
|
|
12
|
+
whitelist?: string[];
|
|
13
|
+
transform?: (value: string) => string;
|
|
14
|
+
defaultValue?: IsRequired extends true ? string : string | null;
|
|
15
|
+
i18n?: Partial<Record<Locale, Partial<CreditCardMessages>>>;
|
|
16
|
+
};
|
|
17
|
+
type CreditCardSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
18
|
+
declare function detectCardType(value: string): CreditCardType;
|
|
19
|
+
declare function validateCreditCard(value: string): boolean;
|
|
20
|
+
declare function creditCard<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<CreditCardOptions<IsRequired>, "required">): CreditCardSchema<IsRequired>;
|
|
21
|
+
|
|
22
|
+
export { type CreditCardMessages, type CreditCardOptions, type CreditCardSchema, type CreditCardType, creditCard, detectCardType, validateCreditCard };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ZodString, ZodNullable } from 'zod';
|
|
2
|
+
import { L as Locale } from '../config-CABSSvAp.js';
|
|
3
|
+
|
|
4
|
+
type CreditCardType = "visa" | "mastercard" | "amex" | "jcb" | "discover" | "unionpay" | "any";
|
|
5
|
+
type CreditCardMessages = {
|
|
6
|
+
required?: string;
|
|
7
|
+
invalid?: string;
|
|
8
|
+
notInWhitelist?: string;
|
|
9
|
+
};
|
|
10
|
+
type CreditCardOptions<IsRequired extends boolean = true> = {
|
|
11
|
+
cardType?: CreditCardType | CreditCardType[];
|
|
12
|
+
whitelist?: string[];
|
|
13
|
+
transform?: (value: string) => string;
|
|
14
|
+
defaultValue?: IsRequired extends true ? string : string | null;
|
|
15
|
+
i18n?: Partial<Record<Locale, Partial<CreditCardMessages>>>;
|
|
16
|
+
};
|
|
17
|
+
type CreditCardSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
18
|
+
declare function detectCardType(value: string): CreditCardType;
|
|
19
|
+
declare function validateCreditCard(value: string): boolean;
|
|
20
|
+
declare function creditCard<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<CreditCardOptions<IsRequired>, "required">): CreditCardSchema<IsRequired>;
|
|
21
|
+
|
|
22
|
+
export { type CreditCardMessages, type CreditCardOptions, type CreditCardSchema, type CreditCardType, creditCard, detectCardType, validateCreditCard };
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { ZodString, ZodNullable } from 'zod';
|
|
2
|
+
import { L as Locale } from '../config-CABSSvAp.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview Date validator for Zod Kit
|
|
6
|
+
*
|
|
7
|
+
* Provides comprehensive date validation with format support, range validation,
|
|
8
|
+
* temporal constraints, and weekday/weekend filtering using dayjs library.
|
|
9
|
+
*
|
|
10
|
+
* @author Ong Hoe Yuan
|
|
11
|
+
* @version 0.0.5
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Type definition for date validation error messages
|
|
16
|
+
*
|
|
17
|
+
* @interface DateMessages
|
|
18
|
+
* @property {string} [required] - Message when field is required but empty
|
|
19
|
+
* @property {string} [invalid] - Message when date is invalid
|
|
20
|
+
* @property {string} [format] - Message when date doesn't match expected format
|
|
21
|
+
* @property {string} [min] - Message when date is before minimum allowed
|
|
22
|
+
* @property {string} [max] - Message when date is after maximum allowed
|
|
23
|
+
* @property {string} [includes] - Message when date string doesn't contain required text
|
|
24
|
+
* @property {string} [excludes] - Message when date string contains forbidden text
|
|
25
|
+
* @property {string} [past] - Message when date must be in the past
|
|
26
|
+
* @property {string} [future] - Message when date must be in the future
|
|
27
|
+
* @property {string} [today] - Message when date must be today
|
|
28
|
+
* @property {string} [notToday] - Message when date must not be today
|
|
29
|
+
* @property {string} [weekday] - Message when date must be a weekday
|
|
30
|
+
* @property {string} [notWeekday] - Message when date must not be a weekday
|
|
31
|
+
* @property {string} [weekend] - Message when date must be a weekend
|
|
32
|
+
* @property {string} [notWeekend] - Message when date must not be a weekend
|
|
33
|
+
*/
|
|
34
|
+
type DateMessages = {
|
|
35
|
+
required?: string;
|
|
36
|
+
invalid?: string;
|
|
37
|
+
format?: string;
|
|
38
|
+
min?: string;
|
|
39
|
+
max?: string;
|
|
40
|
+
includes?: string;
|
|
41
|
+
excludes?: string;
|
|
42
|
+
past?: string;
|
|
43
|
+
future?: string;
|
|
44
|
+
today?: string;
|
|
45
|
+
notToday?: string;
|
|
46
|
+
weekday?: string;
|
|
47
|
+
notWeekday?: string;
|
|
48
|
+
weekend?: string;
|
|
49
|
+
notWeekend?: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Configuration options for date validation
|
|
53
|
+
*
|
|
54
|
+
* @template IsRequired - Whether the field is required (affects return type)
|
|
55
|
+
*
|
|
56
|
+
* @interface DateOptions
|
|
57
|
+
* @property {IsRequired} [required=true] - Whether the field is required
|
|
58
|
+
* @property {string} [min] - Minimum allowed date (in same format as specified)
|
|
59
|
+
* @property {string} [max] - Maximum allowed date (in same format as specified)
|
|
60
|
+
* @property {string} [format="YYYY-MM-DD"] - Date format for parsing and validation
|
|
61
|
+
* @property {string} [includes] - String that must be included in the date
|
|
62
|
+
* @property {string | string[]} [excludes] - String(s) that must not be included
|
|
63
|
+
* @property {boolean} [mustBePast] - Whether date must be in the past
|
|
64
|
+
* @property {boolean} [mustBeFuture] - Whether date must be in the future
|
|
65
|
+
* @property {boolean} [mustBeToday] - Whether date must be today
|
|
66
|
+
* @property {boolean} [mustNotBeToday] - Whether date must not be today
|
|
67
|
+
* @property {boolean} [weekdaysOnly] - Whether date must be a weekday (Monday-Friday)
|
|
68
|
+
* @property {boolean} [weekendsOnly] - Whether date must be a weekend (Saturday-Sunday)
|
|
69
|
+
* @property {Function} [transform] - Custom transformation function for date strings
|
|
70
|
+
* @property {string | null} [defaultValue] - Default value when input is empty
|
|
71
|
+
* @property {Record<Locale, DateMessages>} [i18n] - Custom error messages for different locales
|
|
72
|
+
*/
|
|
73
|
+
type DateOptions<IsRequired extends boolean = true> = {
|
|
74
|
+
min?: string;
|
|
75
|
+
max?: string;
|
|
76
|
+
format?: string;
|
|
77
|
+
includes?: string;
|
|
78
|
+
excludes?: string | string[];
|
|
79
|
+
mustBePast?: boolean;
|
|
80
|
+
mustBeFuture?: boolean;
|
|
81
|
+
mustBeToday?: boolean;
|
|
82
|
+
mustNotBeToday?: boolean;
|
|
83
|
+
weekdaysOnly?: boolean;
|
|
84
|
+
weekendsOnly?: boolean;
|
|
85
|
+
transform?: (value: string) => string;
|
|
86
|
+
defaultValue?: IsRequired extends true ? string : string | null;
|
|
87
|
+
i18n?: Partial<Record<Locale, Partial<DateMessages>>>;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Type alias for date validation schema based on required flag
|
|
91
|
+
*
|
|
92
|
+
* @template IsRequired - Whether the field is required
|
|
93
|
+
* @typedef DateSchema
|
|
94
|
+
* @description Returns ZodString if required, ZodNullable<ZodString> if optional
|
|
95
|
+
*/
|
|
96
|
+
type DateSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
97
|
+
/**
|
|
98
|
+
* Creates a Zod schema for date validation with temporal constraints
|
|
99
|
+
*
|
|
100
|
+
* @template IsRequired - Whether the field is required (affects return type)
|
|
101
|
+
* @param {IsRequired} [required=false] - Whether the field is required
|
|
102
|
+
* @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
|
|
103
|
+
* @returns {DateSchema<IsRequired>} Zod schema for date validation
|
|
104
|
+
*
|
|
105
|
+
* @description
|
|
106
|
+
* Creates a comprehensive date validator with format support, range validation,
|
|
107
|
+
* temporal constraints, and weekday/weekend filtering using dayjs library.
|
|
108
|
+
*
|
|
109
|
+
* Features:
|
|
110
|
+
* - Flexible date format parsing (default: YYYY-MM-DD)
|
|
111
|
+
* - Range validation (min/max dates)
|
|
112
|
+
* - Temporal validation (past/future/today)
|
|
113
|
+
* - Weekday/weekend filtering
|
|
114
|
+
* - Content inclusion/exclusion
|
|
115
|
+
* - Custom transformation functions
|
|
116
|
+
* - Comprehensive internationalization
|
|
117
|
+
* - Strict date parsing with format validation
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* // Basic date validation (YYYY-MM-DD)
|
|
122
|
+
* const basicSchema = date()
|
|
123
|
+
* basicSchema.parse("2024-03-15") // ✓ Valid
|
|
124
|
+
* basicSchema.parse(null) // ✓ Valid (optional)
|
|
125
|
+
*
|
|
126
|
+
* // Required validation
|
|
127
|
+
* const requiredSchema = parse("2024-03-15") // ✓ Valid
|
|
128
|
+
(true)
|
|
129
|
+
* requiredSchema.parse(null) // ✗ Invalid (required)
|
|
130
|
+
*
|
|
131
|
+
* basicSchema.parse("2024-13-01") // ✗ Invalid (month 13)
|
|
132
|
+
*
|
|
133
|
+
* // Custom format
|
|
134
|
+
* const customFormatSchema = date(false, { format: "DD/MM/YYYY" })
|
|
135
|
+
* customFormatSchema.parse("15/03/2024") // ✓ Valid
|
|
136
|
+
* customFormatSchema.parse("2024-03-15") // ✗ Invalid (wrong format)
|
|
137
|
+
*
|
|
138
|
+
* // Date range validation
|
|
139
|
+
* const rangeSchema = date(false, {
|
|
140
|
+
* min: "2024-01-01",
|
|
141
|
+
* max: "2024-12-31"
|
|
142
|
+
* })
|
|
143
|
+
* rangeSchema.parse("2024-06-15") // ✓ Valid
|
|
144
|
+
* rangeSchema.parse("2023-12-31") // ✗ Invalid (before min)
|
|
145
|
+
*
|
|
146
|
+
* // Future dates only
|
|
147
|
+
* const futureSchema = date(false, { mustBeFuture: true })
|
|
148
|
+
* futureSchema.parse("2030-01-01") // ✓ Valid (assuming current date < 2030)
|
|
149
|
+
* futureSchema.parse("2020-01-01") // ✗ Invalid (past date)
|
|
150
|
+
*
|
|
151
|
+
* // Weekdays only (Monday-Friday)
|
|
152
|
+
* const weekdaySchema = date(false, { weekdaysOnly: true })
|
|
153
|
+
* weekdaySchema.parse("2024-03-15") // ✓ Valid (if Friday)
|
|
154
|
+
* weekdaySchema.parse("2024-03-16") // ✗ Invalid (if Saturday)
|
|
155
|
+
*
|
|
156
|
+
* // Business date validation
|
|
157
|
+
* const businessSchema = date(false, {
|
|
158
|
+
* format: "YYYY-MM-DD",
|
|
159
|
+
* mustBeFuture: true,
|
|
160
|
+
* weekdaysOnly: true
|
|
161
|
+
* })
|
|
162
|
+
*
|
|
163
|
+
* // Optional with default
|
|
164
|
+
* const optionalSchema = date(false, {
|
|
165
|
+
* defaultValue: "2024-01-01"
|
|
166
|
+
* })
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* @throws {z.ZodError} When validation fails with specific error messages
|
|
170
|
+
* @see {@link DateOptions} for all available configuration options
|
|
171
|
+
*/
|
|
172
|
+
declare function date<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<DateOptions<IsRequired>, 'required'>): DateSchema<IsRequired>;
|
|
173
|
+
|
|
174
|
+
export { type DateMessages, type DateOptions, type DateSchema, date };
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { ZodString, ZodNullable } from 'zod';
|
|
2
|
+
import { L as Locale } from '../config-CABSSvAp.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview Date validator for Zod Kit
|
|
6
|
+
*
|
|
7
|
+
* Provides comprehensive date validation with format support, range validation,
|
|
8
|
+
* temporal constraints, and weekday/weekend filtering using dayjs library.
|
|
9
|
+
*
|
|
10
|
+
* @author Ong Hoe Yuan
|
|
11
|
+
* @version 0.0.5
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Type definition for date validation error messages
|
|
16
|
+
*
|
|
17
|
+
* @interface DateMessages
|
|
18
|
+
* @property {string} [required] - Message when field is required but empty
|
|
19
|
+
* @property {string} [invalid] - Message when date is invalid
|
|
20
|
+
* @property {string} [format] - Message when date doesn't match expected format
|
|
21
|
+
* @property {string} [min] - Message when date is before minimum allowed
|
|
22
|
+
* @property {string} [max] - Message when date is after maximum allowed
|
|
23
|
+
* @property {string} [includes] - Message when date string doesn't contain required text
|
|
24
|
+
* @property {string} [excludes] - Message when date string contains forbidden text
|
|
25
|
+
* @property {string} [past] - Message when date must be in the past
|
|
26
|
+
* @property {string} [future] - Message when date must be in the future
|
|
27
|
+
* @property {string} [today] - Message when date must be today
|
|
28
|
+
* @property {string} [notToday] - Message when date must not be today
|
|
29
|
+
* @property {string} [weekday] - Message when date must be a weekday
|
|
30
|
+
* @property {string} [notWeekday] - Message when date must not be a weekday
|
|
31
|
+
* @property {string} [weekend] - Message when date must be a weekend
|
|
32
|
+
* @property {string} [notWeekend] - Message when date must not be a weekend
|
|
33
|
+
*/
|
|
34
|
+
type DateMessages = {
|
|
35
|
+
required?: string;
|
|
36
|
+
invalid?: string;
|
|
37
|
+
format?: string;
|
|
38
|
+
min?: string;
|
|
39
|
+
max?: string;
|
|
40
|
+
includes?: string;
|
|
41
|
+
excludes?: string;
|
|
42
|
+
past?: string;
|
|
43
|
+
future?: string;
|
|
44
|
+
today?: string;
|
|
45
|
+
notToday?: string;
|
|
46
|
+
weekday?: string;
|
|
47
|
+
notWeekday?: string;
|
|
48
|
+
weekend?: string;
|
|
49
|
+
notWeekend?: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Configuration options for date validation
|
|
53
|
+
*
|
|
54
|
+
* @template IsRequired - Whether the field is required (affects return type)
|
|
55
|
+
*
|
|
56
|
+
* @interface DateOptions
|
|
57
|
+
* @property {IsRequired} [required=true] - Whether the field is required
|
|
58
|
+
* @property {string} [min] - Minimum allowed date (in same format as specified)
|
|
59
|
+
* @property {string} [max] - Maximum allowed date (in same format as specified)
|
|
60
|
+
* @property {string} [format="YYYY-MM-DD"] - Date format for parsing and validation
|
|
61
|
+
* @property {string} [includes] - String that must be included in the date
|
|
62
|
+
* @property {string | string[]} [excludes] - String(s) that must not be included
|
|
63
|
+
* @property {boolean} [mustBePast] - Whether date must be in the past
|
|
64
|
+
* @property {boolean} [mustBeFuture] - Whether date must be in the future
|
|
65
|
+
* @property {boolean} [mustBeToday] - Whether date must be today
|
|
66
|
+
* @property {boolean} [mustNotBeToday] - Whether date must not be today
|
|
67
|
+
* @property {boolean} [weekdaysOnly] - Whether date must be a weekday (Monday-Friday)
|
|
68
|
+
* @property {boolean} [weekendsOnly] - Whether date must be a weekend (Saturday-Sunday)
|
|
69
|
+
* @property {Function} [transform] - Custom transformation function for date strings
|
|
70
|
+
* @property {string | null} [defaultValue] - Default value when input is empty
|
|
71
|
+
* @property {Record<Locale, DateMessages>} [i18n] - Custom error messages for different locales
|
|
72
|
+
*/
|
|
73
|
+
type DateOptions<IsRequired extends boolean = true> = {
|
|
74
|
+
min?: string;
|
|
75
|
+
max?: string;
|
|
76
|
+
format?: string;
|
|
77
|
+
includes?: string;
|
|
78
|
+
excludes?: string | string[];
|
|
79
|
+
mustBePast?: boolean;
|
|
80
|
+
mustBeFuture?: boolean;
|
|
81
|
+
mustBeToday?: boolean;
|
|
82
|
+
mustNotBeToday?: boolean;
|
|
83
|
+
weekdaysOnly?: boolean;
|
|
84
|
+
weekendsOnly?: boolean;
|
|
85
|
+
transform?: (value: string) => string;
|
|
86
|
+
defaultValue?: IsRequired extends true ? string : string | null;
|
|
87
|
+
i18n?: Partial<Record<Locale, Partial<DateMessages>>>;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Type alias for date validation schema based on required flag
|
|
91
|
+
*
|
|
92
|
+
* @template IsRequired - Whether the field is required
|
|
93
|
+
* @typedef DateSchema
|
|
94
|
+
* @description Returns ZodString if required, ZodNullable<ZodString> if optional
|
|
95
|
+
*/
|
|
96
|
+
type DateSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
97
|
+
/**
|
|
98
|
+
* Creates a Zod schema for date validation with temporal constraints
|
|
99
|
+
*
|
|
100
|
+
* @template IsRequired - Whether the field is required (affects return type)
|
|
101
|
+
* @param {IsRequired} [required=false] - Whether the field is required
|
|
102
|
+
* @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
|
|
103
|
+
* @returns {DateSchema<IsRequired>} Zod schema for date validation
|
|
104
|
+
*
|
|
105
|
+
* @description
|
|
106
|
+
* Creates a comprehensive date validator with format support, range validation,
|
|
107
|
+
* temporal constraints, and weekday/weekend filtering using dayjs library.
|
|
108
|
+
*
|
|
109
|
+
* Features:
|
|
110
|
+
* - Flexible date format parsing (default: YYYY-MM-DD)
|
|
111
|
+
* - Range validation (min/max dates)
|
|
112
|
+
* - Temporal validation (past/future/today)
|
|
113
|
+
* - Weekday/weekend filtering
|
|
114
|
+
* - Content inclusion/exclusion
|
|
115
|
+
* - Custom transformation functions
|
|
116
|
+
* - Comprehensive internationalization
|
|
117
|
+
* - Strict date parsing with format validation
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* // Basic date validation (YYYY-MM-DD)
|
|
122
|
+
* const basicSchema = date()
|
|
123
|
+
* basicSchema.parse("2024-03-15") // ✓ Valid
|
|
124
|
+
* basicSchema.parse(null) // ✓ Valid (optional)
|
|
125
|
+
*
|
|
126
|
+
* // Required validation
|
|
127
|
+
* const requiredSchema = parse("2024-03-15") // ✓ Valid
|
|
128
|
+
(true)
|
|
129
|
+
* requiredSchema.parse(null) // ✗ Invalid (required)
|
|
130
|
+
*
|
|
131
|
+
* basicSchema.parse("2024-13-01") // ✗ Invalid (month 13)
|
|
132
|
+
*
|
|
133
|
+
* // Custom format
|
|
134
|
+
* const customFormatSchema = date(false, { format: "DD/MM/YYYY" })
|
|
135
|
+
* customFormatSchema.parse("15/03/2024") // ✓ Valid
|
|
136
|
+
* customFormatSchema.parse("2024-03-15") // ✗ Invalid (wrong format)
|
|
137
|
+
*
|
|
138
|
+
* // Date range validation
|
|
139
|
+
* const rangeSchema = date(false, {
|
|
140
|
+
* min: "2024-01-01",
|
|
141
|
+
* max: "2024-12-31"
|
|
142
|
+
* })
|
|
143
|
+
* rangeSchema.parse("2024-06-15") // ✓ Valid
|
|
144
|
+
* rangeSchema.parse("2023-12-31") // ✗ Invalid (before min)
|
|
145
|
+
*
|
|
146
|
+
* // Future dates only
|
|
147
|
+
* const futureSchema = date(false, { mustBeFuture: true })
|
|
148
|
+
* futureSchema.parse("2030-01-01") // ✓ Valid (assuming current date < 2030)
|
|
149
|
+
* futureSchema.parse("2020-01-01") // ✗ Invalid (past date)
|
|
150
|
+
*
|
|
151
|
+
* // Weekdays only (Monday-Friday)
|
|
152
|
+
* const weekdaySchema = date(false, { weekdaysOnly: true })
|
|
153
|
+
* weekdaySchema.parse("2024-03-15") // ✓ Valid (if Friday)
|
|
154
|
+
* weekdaySchema.parse("2024-03-16") // ✗ Invalid (if Saturday)
|
|
155
|
+
*
|
|
156
|
+
* // Business date validation
|
|
157
|
+
* const businessSchema = date(false, {
|
|
158
|
+
* format: "YYYY-MM-DD",
|
|
159
|
+
* mustBeFuture: true,
|
|
160
|
+
* weekdaysOnly: true
|
|
161
|
+
* })
|
|
162
|
+
*
|
|
163
|
+
* // Optional with default
|
|
164
|
+
* const optionalSchema = date(false, {
|
|
165
|
+
* defaultValue: "2024-01-01"
|
|
166
|
+
* })
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* @throws {z.ZodError} When validation fails with specific error messages
|
|
170
|
+
* @see {@link DateOptions} for all available configuration options
|
|
171
|
+
*/
|
|
172
|
+
declare function date<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<DateOptions<IsRequired>, 'required'>): DateSchema<IsRequired>;
|
|
173
|
+
|
|
174
|
+
export { type DateMessages, type DateOptions, type DateSchema, date };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _chunkOPQJWHXNcjs = require('../chunk-OPQJWHXN.cjs');
|
|
8
|
+
require('../chunk-UCOXAZJF.cjs');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
exports.DATETIME_PATTERNS = _chunkOPQJWHXNcjs.DATETIME_PATTERNS; exports.datetime = _chunkOPQJWHXNcjs.datetime; exports.normalizeDateTimeValue = _chunkOPQJWHXNcjs.normalizeDateTimeValue; exports.parseDateTimeValue = _chunkOPQJWHXNcjs.parseDateTimeValue; exports.validateDateTimeFormat = _chunkOPQJWHXNcjs.validateDateTimeFormat;
|