@hy_ong/zod-kit 0.1.3 → 0.1.5
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/index.cjs +523 -293
- package/dist/index.d.cts +129 -132
- package/dist/index.d.ts +129 -132
- package/dist/index.js +517 -287
- package/package.json +1 -1
- package/src/validators/taiwan/business-id.ts +6 -10
- package/src/validators/taiwan/fax.ts +52 -48
- package/src/validators/taiwan/tel.ts +52 -48
package/dist/index.d.cts
CHANGED
|
@@ -1257,6 +1257,7 @@ type NumberSchema<IsRequired extends boolean> = IsRequired extends true ? ZodNum
|
|
|
1257
1257
|
* Creates a Zod schema for number validation with comprehensive constraints
|
|
1258
1258
|
*
|
|
1259
1259
|
* @template IsRequired - Whether the field is required (affects return type)
|
|
1260
|
+
* @param required
|
|
1260
1261
|
* @param {NumberOptions<IsRequired>} [options] - Configuration options for number validation
|
|
1261
1262
|
* @returns {NumberSchema<IsRequired>} Zod schema for number validation
|
|
1262
1263
|
*
|
|
@@ -1324,7 +1325,7 @@ type NumberSchema<IsRequired extends boolean> = IsRequired extends true ? ZodNum
|
|
|
1324
1325
|
* @throws {z.ZodError} When validation fails with specific error messages
|
|
1325
1326
|
* @see {@link NumberOptions} for all available configuration options
|
|
1326
1327
|
*/
|
|
1327
|
-
declare function number<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<NumberOptions<IsRequired>,
|
|
1328
|
+
declare function number<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<NumberOptions<IsRequired>, "required">): NumberSchema<IsRequired>;
|
|
1328
1329
|
|
|
1329
1330
|
/**
|
|
1330
1331
|
* @fileoverview Password validator for Zod Kit
|
|
@@ -2135,11 +2136,11 @@ declare function url<IsRequired extends boolean = false>(required?: IsRequired,
|
|
|
2135
2136
|
/**
|
|
2136
2137
|
* Type definition for business ID validation error messages
|
|
2137
2138
|
*
|
|
2138
|
-
* @interface
|
|
2139
|
+
* @interface TwBusinessIdMessages
|
|
2139
2140
|
* @property {string} [required] - Message when field is required but empty
|
|
2140
2141
|
* @property {string} [invalid] - Message when business ID format or checksum is invalid
|
|
2141
2142
|
*/
|
|
2142
|
-
type
|
|
2143
|
+
type TwBusinessIdMessages = {
|
|
2143
2144
|
required?: string;
|
|
2144
2145
|
invalid?: string;
|
|
2145
2146
|
};
|
|
@@ -2148,25 +2149,25 @@ type BusinessIdMessages = {
|
|
|
2148
2149
|
*
|
|
2149
2150
|
* @template IsRequired - Whether the field is required (affects return type)
|
|
2150
2151
|
*
|
|
2151
|
-
* @interface
|
|
2152
|
+
* @interface TwBusinessIdOptions
|
|
2152
2153
|
* @property {IsRequired} [required=true] - Whether the field is required
|
|
2153
2154
|
* @property {Function} [transform] - Custom transformation function for business ID
|
|
2154
2155
|
* @property {string | null} [defaultValue] - Default value when input is empty
|
|
2155
|
-
* @property {Record<Locale,
|
|
2156
|
+
* @property {Record<Locale, TwBusinessIdMessages>} [i18n] - Custom error messages for different locales
|
|
2156
2157
|
*/
|
|
2157
|
-
type
|
|
2158
|
+
type TwBusinessIdOptions<IsRequired extends boolean = true> = {
|
|
2158
2159
|
transform?: (value: string) => string;
|
|
2159
2160
|
defaultValue?: IsRequired extends true ? string : string | null;
|
|
2160
|
-
i18n?: Record<Locale,
|
|
2161
|
+
i18n?: Record<Locale, TwBusinessIdMessages>;
|
|
2161
2162
|
};
|
|
2162
2163
|
/**
|
|
2163
2164
|
* Type alias for business ID validation schema based on required flag
|
|
2164
2165
|
*
|
|
2165
2166
|
* @template IsRequired - Whether the field is required
|
|
2166
|
-
* @typedef
|
|
2167
|
+
* @typedef TwBusinessIdSchema
|
|
2167
2168
|
* @description Returns ZodString if required, ZodNullable<ZodString> if optional
|
|
2168
2169
|
*/
|
|
2169
|
-
type
|
|
2170
|
+
type TwBusinessIdSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
2170
2171
|
/**
|
|
2171
2172
|
* Validates Taiwan Business Identification Number (統一編號)
|
|
2172
2173
|
*
|
|
@@ -2246,10 +2247,10 @@ declare const validateTaiwanBusinessId: (value: string) => boolean;
|
|
|
2246
2247
|
* ```
|
|
2247
2248
|
*
|
|
2248
2249
|
* @throws {z.ZodError} When validation fails with specific error messages
|
|
2249
|
-
* @see {@link
|
|
2250
|
+
* @see {@link TwBusinessIdOptions} for all available configuration options
|
|
2250
2251
|
* @see {@link validateTaiwanBusinessId} for validation logic details
|
|
2251
2252
|
*/
|
|
2252
|
-
declare function
|
|
2253
|
+
declare function twBusinessId<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwBusinessIdOptions<IsRequired>, "required">): TwBusinessIdSchema<IsRequired>;
|
|
2253
2254
|
|
|
2254
2255
|
/**
|
|
2255
2256
|
* @fileoverview Taiwan National ID (身分證/居留證) validator for Zod Kit
|
|
@@ -2264,11 +2265,11 @@ declare function businessId<IsRequired extends boolean = false>(required?: IsReq
|
|
|
2264
2265
|
/**
|
|
2265
2266
|
* Type definition for national ID validation error messages
|
|
2266
2267
|
*
|
|
2267
|
-
* @interface
|
|
2268
|
+
* @interface TwNationalIdMessages
|
|
2268
2269
|
* @property {string} [required] - Message when field is required but empty
|
|
2269
2270
|
* @property {string} [invalid] - Message when national ID format or checksum is invalid
|
|
2270
2271
|
*/
|
|
2271
|
-
type
|
|
2272
|
+
type TwNationalIdMessages = {
|
|
2272
2273
|
required?: string;
|
|
2273
2274
|
invalid?: string;
|
|
2274
2275
|
};
|
|
@@ -2288,29 +2289,29 @@ type NationalIdType = "citizen" | "resident" | "both";
|
|
|
2288
2289
|
*
|
|
2289
2290
|
* @template IsRequired - Whether the field is required (affects return type)
|
|
2290
2291
|
*
|
|
2291
|
-
* @interface
|
|
2292
|
+
* @interface TwNationalIdOptions
|
|
2292
2293
|
* @property {IsRequired} [required=true] - Whether the field is required
|
|
2293
2294
|
* @property {NationalIdType} [type="both"] - Type of ID to accept
|
|
2294
2295
|
* @property {boolean} [allowOldResident=true] - Whether to accept old-style resident certificates
|
|
2295
2296
|
* @property {Function} [transform] - Custom transformation function for ID
|
|
2296
2297
|
* @property {string | null} [defaultValue] - Default value when input is empty
|
|
2297
|
-
* @property {Record<Locale,
|
|
2298
|
+
* @property {Record<Locale, TwNationalIdMessages>} [i18n] - Custom error messages for different locales
|
|
2298
2299
|
*/
|
|
2299
|
-
type
|
|
2300
|
+
type TwNationalIdOptions<IsRequired extends boolean = true> = {
|
|
2300
2301
|
type?: NationalIdType;
|
|
2301
2302
|
allowOldResident?: boolean;
|
|
2302
2303
|
transform?: (value: string) => string;
|
|
2303
2304
|
defaultValue?: IsRequired extends true ? string : string | null;
|
|
2304
|
-
i18n?: Record<Locale,
|
|
2305
|
+
i18n?: Record<Locale, TwNationalIdMessages>;
|
|
2305
2306
|
};
|
|
2306
2307
|
/**
|
|
2307
2308
|
* Type alias for national ID validation schema based on required flag
|
|
2308
2309
|
*
|
|
2309
2310
|
* @template IsRequired - Whether the field is required
|
|
2310
|
-
* @typedef
|
|
2311
|
+
* @typedef TwNationalIdSchema
|
|
2311
2312
|
* @description Returns ZodString if required, ZodNullable<ZodString> if optional
|
|
2312
2313
|
*/
|
|
2313
|
-
type
|
|
2314
|
+
type TwNationalIdSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
2314
2315
|
/**
|
|
2315
2316
|
* Validates Taiwan citizen national ID card (身分證字號)
|
|
2316
2317
|
*
|
|
@@ -2402,8 +2403,8 @@ declare const validateTaiwanNationalId: (value: string, type?: NationalIdType, a
|
|
|
2402
2403
|
* Creates a Zod schema for Taiwan National ID validation
|
|
2403
2404
|
*
|
|
2404
2405
|
* @template IsRequired - Whether the field is required (affects return type)
|
|
2405
|
-
* @param {
|
|
2406
|
-
* @returns {
|
|
2406
|
+
* @param {TwNationalIdOptions<IsRequired>} [options] - Configuration options for national ID validation
|
|
2407
|
+
* @returns {TwNationalIdSchema<IsRequired>} Zod schema for national ID validation
|
|
2407
2408
|
*
|
|
2408
2409
|
* @description
|
|
2409
2410
|
* Creates a comprehensive Taiwan National ID validator that supports both
|
|
@@ -2422,18 +2423,18 @@ declare const validateTaiwanNationalId: (value: string, type?: NationalIdType, a
|
|
|
2422
2423
|
* @example
|
|
2423
2424
|
* ```typescript
|
|
2424
2425
|
* // Accept any valid Taiwan ID
|
|
2425
|
-
* const anyIdSchema =
|
|
2426
|
+
* const anyIdSchema = twNationalId()
|
|
2426
2427
|
* anyIdSchema.parse("A123456789") // ✓ Valid citizen ID
|
|
2427
2428
|
* anyIdSchema.parse("A812345678") // ✓ Valid new resident ID
|
|
2428
2429
|
* anyIdSchema.parse("AA12345678") // ✓ Valid old resident ID
|
|
2429
2430
|
*
|
|
2430
2431
|
* // Citizen IDs only
|
|
2431
|
-
* const citizenSchema =
|
|
2432
|
+
* const citizenSchema = twNationalId(false, { type: "citizen" })
|
|
2432
2433
|
* citizenSchema.parse("A123456789") // ✓ Valid
|
|
2433
2434
|
* citizenSchema.parse("A812345678") // ✗ Invalid (resident ID)
|
|
2434
2435
|
*
|
|
2435
2436
|
* // Resident IDs only (new format only)
|
|
2436
|
-
* const residentSchema =
|
|
2437
|
+
* const residentSchema = twNationalId(false, {
|
|
2437
2438
|
* type: "resident",
|
|
2438
2439
|
* allowOldResident: false
|
|
2439
2440
|
* })
|
|
@@ -2441,12 +2442,12 @@ declare const validateTaiwanNationalId: (value: string, type?: NationalIdType, a
|
|
|
2441
2442
|
* residentSchema.parse("AA12345678") // ✗ Invalid (old format)
|
|
2442
2443
|
*
|
|
2443
2444
|
* // Optional with custom transformation
|
|
2444
|
-
* const optionalSchema =
|
|
2445
|
+
* const optionalSchema = twNationalId(false, {
|
|
2445
2446
|
* transform: (value) => value.replace(/[^A-Z0-9]/g, '') // Remove special chars
|
|
2446
2447
|
* })
|
|
2447
2448
|
*
|
|
2448
2449
|
* // With custom error messages
|
|
2449
|
-
* const customSchema =
|
|
2450
|
+
* const customSchema = twNationalId(false, {
|
|
2450
2451
|
* i18n: {
|
|
2451
2452
|
* en: { invalid: "Please enter a valid Taiwan National ID" },
|
|
2452
2453
|
* 'zh-TW': { invalid: "請輸入有效的身分證或居留證號碼" }
|
|
@@ -2455,11 +2456,11 @@ declare const validateTaiwanNationalId: (value: string, type?: NationalIdType, a
|
|
|
2455
2456
|
* ```
|
|
2456
2457
|
*
|
|
2457
2458
|
* @throws {z.ZodError} When validation fails with specific error messages
|
|
2458
|
-
* @see {@link
|
|
2459
|
+
* @see {@link TwNationalIdOptions} for all available configuration options
|
|
2459
2460
|
* @see {@link NationalIdType} for supported ID types
|
|
2460
2461
|
* @see {@link validateTaiwanNationalId} for validation logic details
|
|
2461
2462
|
*/
|
|
2462
|
-
declare function
|
|
2463
|
+
declare function twNationalId<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwNationalIdOptions<IsRequired>, 'required'>): TwNationalIdSchema<IsRequired>;
|
|
2463
2464
|
|
|
2464
2465
|
/**
|
|
2465
2466
|
* @fileoverview Taiwan Mobile Phone Number validator for Zod Kit
|
|
@@ -2474,12 +2475,12 @@ declare function nationalId<IsRequired extends boolean = false>(required?: IsReq
|
|
|
2474
2475
|
/**
|
|
2475
2476
|
* Type definition for mobile phone validation error messages
|
|
2476
2477
|
*
|
|
2477
|
-
* @interface
|
|
2478
|
+
* @interface TwMobileMessages
|
|
2478
2479
|
* @property {string} [required] - Message when field is required but empty
|
|
2479
2480
|
* @property {string} [invalid] - Message when mobile number format is invalid
|
|
2480
2481
|
* @property {string} [notInWhitelist] - Message when mobile number is not in whitelist
|
|
2481
2482
|
*/
|
|
2482
|
-
type
|
|
2483
|
+
type TwMobileMessages = {
|
|
2483
2484
|
required?: string;
|
|
2484
2485
|
invalid?: string;
|
|
2485
2486
|
notInWhitelist?: string;
|
|
@@ -2489,27 +2490,27 @@ type MobileMessages = {
|
|
|
2489
2490
|
*
|
|
2490
2491
|
* @template IsRequired - Whether the field is required (affects return type)
|
|
2491
2492
|
*
|
|
2492
|
-
* @interface
|
|
2493
|
+
* @interface TwMobileOptions
|
|
2493
2494
|
* @property {IsRequired} [required=true] - Whether the field is required
|
|
2494
2495
|
* @property {string[]} [whitelist] - Array of specific mobile numbers that are always allowed
|
|
2495
2496
|
* @property {Function} [transform] - Custom transformation function for mobile number
|
|
2496
2497
|
* @property {string | null} [defaultValue] - Default value when input is empty
|
|
2497
|
-
* @property {Record<Locale,
|
|
2498
|
+
* @property {Record<Locale, TwMobileMessages>} [i18n] - Custom error messages for different locales
|
|
2498
2499
|
*/
|
|
2499
|
-
type
|
|
2500
|
+
type TwMobileOptions<IsRequired extends boolean = true> = {
|
|
2500
2501
|
whitelist?: string[];
|
|
2501
2502
|
transform?: (value: string) => string;
|
|
2502
2503
|
defaultValue?: IsRequired extends true ? string : string | null;
|
|
2503
|
-
i18n?: Record<Locale,
|
|
2504
|
+
i18n?: Record<Locale, TwMobileMessages>;
|
|
2504
2505
|
};
|
|
2505
2506
|
/**
|
|
2506
2507
|
* Type alias for mobile phone validation schema based on required flag
|
|
2507
2508
|
*
|
|
2508
2509
|
* @template IsRequired - Whether the field is required
|
|
2509
|
-
* @typedef
|
|
2510
|
+
* @typedef TwMobileSchema
|
|
2510
2511
|
* @description Returns ZodString if required, ZodNullable<ZodString> if optional
|
|
2511
2512
|
*/
|
|
2512
|
-
type
|
|
2513
|
+
type TwMobileSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
2513
2514
|
/**
|
|
2514
2515
|
* Validates Taiwan mobile phone number format
|
|
2515
2516
|
*
|
|
@@ -2539,7 +2540,7 @@ declare const validateTaiwanMobile: (value: string) => boolean;
|
|
|
2539
2540
|
* @template IsRequired - Whether the field is required (affects return type)
|
|
2540
2541
|
* @param {IsRequired} [required=false] - Whether the field is required
|
|
2541
2542
|
* @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
|
|
2542
|
-
* @returns {
|
|
2543
|
+
* @returns {TwMobileSchema<IsRequired>} Zod schema for mobile phone validation
|
|
2543
2544
|
*
|
|
2544
2545
|
* @description
|
|
2545
2546
|
* Creates a comprehensive Taiwan mobile phone number validator with support for
|
|
@@ -2557,7 +2558,7 @@ declare const validateTaiwanMobile: (value: string) => boolean;
|
|
|
2557
2558
|
* @example
|
|
2558
2559
|
* ```typescript
|
|
2559
2560
|
* // Basic mobile number validation
|
|
2560
|
-
* const basicSchema =
|
|
2561
|
+
* const basicSchema = twMobile() // optional by default
|
|
2561
2562
|
* basicSchema.parse("0912345678") // ✓ Valid
|
|
2562
2563
|
* basicSchema.parse(null) // ✓ Valid (optional)
|
|
2563
2564
|
*
|
|
@@ -2570,26 +2571,26 @@ declare const validateTaiwanMobile: (value: string) => boolean;
|
|
|
2570
2571
|
* basicSchema.parse("0812345678") // ✗ Invalid (wrong prefix)
|
|
2571
2572
|
*
|
|
2572
2573
|
* // With whitelist (only specific numbers allowed)
|
|
2573
|
-
* const whitelistSchema =
|
|
2574
|
+
* const whitelistSchema = twMobile(false, {
|
|
2574
2575
|
* whitelist: ["0912345678", "0987654321"]
|
|
2575
2576
|
* })
|
|
2576
2577
|
* whitelistSchema.parse("0912345678") // ✓ Valid (in whitelist)
|
|
2577
2578
|
* whitelistSchema.parse("0911111111") // ✗ Invalid (not in whitelist)
|
|
2578
2579
|
*
|
|
2579
2580
|
* // Optional mobile number
|
|
2580
|
-
* const optionalSchema =
|
|
2581
|
+
* const optionalSchema = twMobile(false)
|
|
2581
2582
|
* optionalSchema.parse("") // ✓ Valid (returns null)
|
|
2582
2583
|
* optionalSchema.parse("0912345678") // ✓ Valid
|
|
2583
2584
|
*
|
|
2584
2585
|
* // With custom transformation
|
|
2585
|
-
* const transformSchema =
|
|
2586
|
+
* const transformSchema = twMobile(false, {
|
|
2586
2587
|
* transform: (value) => value.replace(/[^0-9]/g, '') // Remove non-digits
|
|
2587
2588
|
* })
|
|
2588
2589
|
* transformSchema.parse("091-234-5678") // ✓ Valid (formatted input)
|
|
2589
2590
|
* transformSchema.parse("091 234 5678") // ✓ Valid (spaced input)
|
|
2590
2591
|
*
|
|
2591
2592
|
* // With custom error messages
|
|
2592
|
-
* const customSchema =
|
|
2593
|
+
* const customSchema = twMobile(false, {
|
|
2593
2594
|
* i18n: {
|
|
2594
2595
|
* en: { invalid: "Please enter a valid Taiwan mobile number" },
|
|
2595
2596
|
* 'zh-TW': { invalid: "請輸入有效的台灣手機號碼" }
|
|
@@ -2598,10 +2599,10 @@ declare const validateTaiwanMobile: (value: string) => boolean;
|
|
|
2598
2599
|
* ```
|
|
2599
2600
|
*
|
|
2600
2601
|
* @throws {z.ZodError} When validation fails with specific error messages
|
|
2601
|
-
* @see {@link
|
|
2602
|
+
* @see {@link TwMobileOptions} for all available configuration options
|
|
2602
2603
|
* @see {@link validateTaiwanMobile} for validation logic details
|
|
2603
2604
|
*/
|
|
2604
|
-
declare function
|
|
2605
|
+
declare function twMobile<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwMobileOptions<IsRequired>, 'required'>): TwMobileSchema<IsRequired>;
|
|
2605
2606
|
|
|
2606
2607
|
/**
|
|
2607
2608
|
* @fileoverview Taiwan Postal Code validator for Zod Kit
|
|
@@ -2617,7 +2618,7 @@ declare function mobile<IsRequired extends boolean = false>(required?: IsRequire
|
|
|
2617
2618
|
/**
|
|
2618
2619
|
* Type definition for postal code validation error messages
|
|
2619
2620
|
*
|
|
2620
|
-
* @interface
|
|
2621
|
+
* @interface TwPostalCodeMessages
|
|
2621
2622
|
* @property {string} [required] - Message when field is required but empty
|
|
2622
2623
|
* @property {string} [invalid] - Message when postal code format is invalid
|
|
2623
2624
|
* @property {string} [invalidFormat] - Message when format doesn't match expected pattern
|
|
@@ -2627,7 +2628,7 @@ declare function mobile<IsRequired extends boolean = false>(required?: IsRequire
|
|
|
2627
2628
|
* @property {string} [format5Only] - Message when only 5-digit format is allowed
|
|
2628
2629
|
* @property {string} [format6Only] - Message when only 6-digit format is allowed
|
|
2629
2630
|
*/
|
|
2630
|
-
type
|
|
2631
|
+
type TwPostalCodeMessages = {
|
|
2631
2632
|
required?: string;
|
|
2632
2633
|
invalid?: string;
|
|
2633
2634
|
invalidFormat?: string;
|
|
@@ -2642,7 +2643,7 @@ type PostalCodeMessages = {
|
|
|
2642
2643
|
/**
|
|
2643
2644
|
* Postal code format types supported in Taiwan
|
|
2644
2645
|
*
|
|
2645
|
-
* @typedef {"3" | "5" | "6" | "3+5" | "3+6" | "5+6" | "all"}
|
|
2646
|
+
* @typedef {"3" | "5" | "6" | "3+5" | "3+6" | "5+6" | "all"} TwPostalCodeFormatType
|
|
2646
2647
|
*
|
|
2647
2648
|
* Available formats:
|
|
2648
2649
|
* - "3": 3-digit basic postal codes (100-982)
|
|
@@ -2653,15 +2654,15 @@ type PostalCodeMessages = {
|
|
|
2653
2654
|
* - "5+6": Accept both 5-digit and 6-digit formats
|
|
2654
2655
|
* - "all": Accept all formats (3, 5, and 6 digits)
|
|
2655
2656
|
*/
|
|
2656
|
-
type
|
|
2657
|
+
type TwPostalCodeFormatType = "3" | "5" | "6" | "3+5" | "3+6" | "5+6" | "all";
|
|
2657
2658
|
/**
|
|
2658
2659
|
* Configuration options for Taiwan postal code validation
|
|
2659
2660
|
*
|
|
2660
2661
|
* @template IsRequired - Whether the field is required (affects return type)
|
|
2661
2662
|
*
|
|
2662
|
-
* @interface
|
|
2663
|
+
* @interface TwPostalCodeOptions
|
|
2663
2664
|
* @property {IsRequired} [required=true] - Whether the field is required
|
|
2664
|
-
* @property {
|
|
2665
|
+
* @property {TwPostalCodeFormatType} [format="3+6"] - Which postal code formats to accept
|
|
2665
2666
|
* @property {boolean} [strictValidation=true] - Enable strict validation against known postal code ranges
|
|
2666
2667
|
* @property {boolean} [allowDashes=true] - Whether to allow dashes in postal codes (e.g., "100-01" or "100-001")
|
|
2667
2668
|
* @property {boolean} [warn5Digit=true] - Whether to show warning for 5-digit legacy format
|
|
@@ -2669,10 +2670,10 @@ type PostalCodeFormat = "3" | "5" | "6" | "3+5" | "3+6" | "5+6" | "all";
|
|
|
2669
2670
|
* @property {string[]} [blockedPrefixes] - Specific 3-digit prefixes to block
|
|
2670
2671
|
* @property {Function} [transform] - Custom transformation function for postal codes
|
|
2671
2672
|
* @property {string | null} [defaultValue] - Default value when input is empty
|
|
2672
|
-
* @property {Record<Locale,
|
|
2673
|
+
* @property {Record<Locale, TwPostalCodeMessages>} [i18n] - Custom error messages for different locales
|
|
2673
2674
|
*/
|
|
2674
|
-
type
|
|
2675
|
-
format?:
|
|
2675
|
+
type TwPostalCodeOptions<IsRequired extends boolean = true> = {
|
|
2676
|
+
format?: TwPostalCodeFormatType;
|
|
2676
2677
|
strictValidation?: boolean;
|
|
2677
2678
|
allowDashes?: boolean;
|
|
2678
2679
|
warn5Digit?: boolean;
|
|
@@ -2680,7 +2681,7 @@ type PostalCodeOptions<IsRequired extends boolean = true> = {
|
|
|
2680
2681
|
blockedPrefixes?: string[];
|
|
2681
2682
|
transform?: (value: string) => string;
|
|
2682
2683
|
defaultValue?: IsRequired extends true ? string : string | null;
|
|
2683
|
-
i18n?: Record<Locale,
|
|
2684
|
+
i18n?: Record<Locale, TwPostalCodeMessages>;
|
|
2684
2685
|
strictSuffixValidation?: boolean;
|
|
2685
2686
|
deprecate5Digit?: boolean;
|
|
2686
2687
|
};
|
|
@@ -2688,10 +2689,10 @@ type PostalCodeOptions<IsRequired extends boolean = true> = {
|
|
|
2688
2689
|
* Type alias for postal code validation schema based on required flag
|
|
2689
2690
|
*
|
|
2690
2691
|
* @template IsRequired - Whether the field is required
|
|
2691
|
-
* @typedef
|
|
2692
|
+
* @typedef TwPostalCodeSchema
|
|
2692
2693
|
* @description Returns ZodString if required, ZodNullable<ZodString> if optional
|
|
2693
2694
|
*/
|
|
2694
|
-
type
|
|
2695
|
+
type TwPostalCodeSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
2695
2696
|
/**
|
|
2696
2697
|
* Valid 3-digit postal code prefixes for Taiwan
|
|
2697
2698
|
* Based on official Chunghwa Post data (2024)
|
|
@@ -2733,7 +2734,7 @@ declare const validate6DigitPostalCode: (value: string, strictValidation?: boole
|
|
|
2733
2734
|
* Main validation function for Taiwan postal codes
|
|
2734
2735
|
*
|
|
2735
2736
|
* @param {string} value - The postal code to validate
|
|
2736
|
-
* @param {
|
|
2737
|
+
* @param {TwPostalCodeFormatType} format - Which formats to accept
|
|
2737
2738
|
* @param {boolean} strictValidation - Whether to validate against known postal codes
|
|
2738
2739
|
* @param {boolean} strictSuffixValidation - Whether to validate suffix ranges
|
|
2739
2740
|
* @param {boolean} allowDashes - Whether dashes/spaces are allowed and should be removed
|
|
@@ -2741,13 +2742,13 @@ declare const validate6DigitPostalCode: (value: string, strictValidation?: boole
|
|
|
2741
2742
|
* @param {string[]} blockedPrefixes - Specific prefixes to block
|
|
2742
2743
|
* @returns {boolean} True if the postal code is valid
|
|
2743
2744
|
*/
|
|
2744
|
-
declare const validateTaiwanPostalCode: (value: string, format?:
|
|
2745
|
+
declare const validateTaiwanPostalCode: (value: string, format?: TwPostalCodeFormatType, strictValidation?: boolean, strictSuffixValidation?: boolean, allowDashes?: boolean, allowedPrefixes?: string[], blockedPrefixes?: string[]) => boolean;
|
|
2745
2746
|
/**
|
|
2746
2747
|
* Creates a Zod schema for Taiwan postal code validation
|
|
2747
2748
|
*
|
|
2748
2749
|
* @template IsRequired - Whether the field is required (affects return type)
|
|
2749
|
-
* @param {
|
|
2750
|
-
* @returns {
|
|
2750
|
+
* @param {TwPostalCodeOptions<IsRequired>} [options] - Configuration options for postal code validation
|
|
2751
|
+
* @returns {TwPostalCodeSchema<IsRequired>} Zod schema for postal code validation
|
|
2751
2752
|
*
|
|
2752
2753
|
* @description
|
|
2753
2754
|
* Creates a comprehensive Taiwan postal code validator that supports multiple formats
|
|
@@ -2767,53 +2768,53 @@ declare const validateTaiwanPostalCode: (value: string, format?: PostalCodeForma
|
|
|
2767
2768
|
* @example
|
|
2768
2769
|
* ```typescript
|
|
2769
2770
|
* // Accept 3-digit or 6-digit formats (recommended)
|
|
2770
|
-
* const modernSchema =
|
|
2771
|
+
* const modernSchema = twPostalCode()
|
|
2771
2772
|
* modernSchema.parse("100") // ✓ Valid 3-digit
|
|
2772
2773
|
* modernSchema.parse("100001") // ✓ Valid 6-digit
|
|
2773
2774
|
* modernSchema.parse("10001") // ✗ Invalid (5-digit not allowed)
|
|
2774
2775
|
*
|
|
2775
2776
|
* // Accept all formats
|
|
2776
|
-
* const flexibleSchema =
|
|
2777
|
+
* const flexibleSchema = twPostalCode(false, { format: "all" })
|
|
2777
2778
|
* flexibleSchema.parse("100") // ✓ Valid
|
|
2778
2779
|
* flexibleSchema.parse("10001") // ✓ Valid
|
|
2779
2780
|
* flexibleSchema.parse("100001") // ✓ Valid
|
|
2780
2781
|
*
|
|
2781
2782
|
* // Only 6-digit format (current standard)
|
|
2782
|
-
* const modernOnlySchema =
|
|
2783
|
+
* const modernOnlySchema = twPostalCode(false, { format: "6" })
|
|
2783
2784
|
* modernOnlySchema.parse("100001") // ✓ Valid
|
|
2784
2785
|
* modernOnlySchema.parse("100") // ✗ Invalid
|
|
2785
2786
|
*
|
|
2786
2787
|
* // With dashes allowed
|
|
2787
|
-
* const dashSchema =
|
|
2788
|
+
* const dashSchema = twPostalCode(false, { allowDashes: true })
|
|
2788
2789
|
* dashSchema.parse("100-001") // ✓ Valid (normalized to "100001")
|
|
2789
2790
|
* dashSchema.parse("100-01") // ✓ Valid if 5-digit format allowed
|
|
2790
2791
|
*
|
|
2791
2792
|
* // Specific areas only
|
|
2792
|
-
* const taipeiSchema =
|
|
2793
|
+
* const taipeiSchema = twPostalCode(false, {
|
|
2793
2794
|
* allowedPrefixes: ["100", "103", "104", "105", "106"]
|
|
2794
2795
|
* })
|
|
2795
2796
|
* taipeiSchema.parse("100001") // ✓ Valid (Taipei area)
|
|
2796
2797
|
* taipeiSchema.parse("200001") // ✗ Invalid (not in allowlist)
|
|
2797
2798
|
*
|
|
2798
2799
|
* // Block specific areas
|
|
2799
|
-
* const blockedSchema =
|
|
2800
|
+
* const blockedSchema = twPostalCode(false, {
|
|
2800
2801
|
* blockedPrefixes: ["999"] // Block test codes
|
|
2801
2802
|
* })
|
|
2802
2803
|
*
|
|
2803
2804
|
* // With warning for legacy format
|
|
2804
|
-
* const warnSchema =
|
|
2805
|
+
* const warnSchema = twPostalCode(false, {
|
|
2805
2806
|
* format: "all",
|
|
2806
2807
|
* warn5Digit: true
|
|
2807
2808
|
* })
|
|
2808
2809
|
* // Will validate but may show warning for 5-digit codes
|
|
2809
2810
|
*
|
|
2810
2811
|
* // Optional with custom transformation
|
|
2811
|
-
* const optionalSchema =
|
|
2812
|
+
* const optionalSchema = twPostalCode(false, {
|
|
2812
2813
|
* transform: (value) => value.replace(/\D/g, '') // Remove non-digits
|
|
2813
2814
|
* })
|
|
2814
2815
|
*
|
|
2815
2816
|
* // Strict suffix validation for real postal codes
|
|
2816
|
-
* const strictSchema =
|
|
2817
|
+
* const strictSchema = twPostalCode(false, {
|
|
2817
2818
|
* format: "6",
|
|
2818
2819
|
* strictSuffixValidation: true // Validates suffix range 001-999
|
|
2819
2820
|
* })
|
|
@@ -2821,7 +2822,7 @@ declare const validateTaiwanPostalCode: (value: string, format?: PostalCodeForma
|
|
|
2821
2822
|
* strictSchema.parse("100000") // ✗ Invalid (suffix 000 not allowed)
|
|
2822
2823
|
*
|
|
2823
2824
|
* // Deprecate 5-digit codes entirely
|
|
2824
|
-
* const modern2024Schema =
|
|
2825
|
+
* const modern2024Schema = twPostalCode(false, {
|
|
2825
2826
|
* format: "all",
|
|
2826
2827
|
* deprecate5Digit: true // Throws error for any 5-digit code
|
|
2827
2828
|
* })
|
|
@@ -2830,11 +2831,11 @@ declare const validateTaiwanPostalCode: (value: string, format?: PostalCodeForma
|
|
|
2830
2831
|
* ```
|
|
2831
2832
|
*
|
|
2832
2833
|
* @throws {z.ZodError} When validation fails with specific error messages
|
|
2833
|
-
* @see {@link
|
|
2834
|
-
* @see {@link
|
|
2834
|
+
* @see {@link TwPostalCodeOptions} for all available configuration options
|
|
2835
|
+
* @see {@link TwPostalCodeFormatType} for supported formats
|
|
2835
2836
|
* @see {@link validateTaiwanPostalCode} for validation logic details
|
|
2836
2837
|
*/
|
|
2837
|
-
declare function
|
|
2838
|
+
declare function twPostalCode<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwPostalCodeOptions<IsRequired>, 'required'>): TwPostalCodeSchema<IsRequired>;
|
|
2838
2839
|
|
|
2839
2840
|
/**
|
|
2840
2841
|
* @fileoverview Taiwan Landline Telephone Number validator for Zod Kit
|
|
@@ -2849,12 +2850,12 @@ declare function postalCode<IsRequired extends boolean = false>(required?: IsReq
|
|
|
2849
2850
|
/**
|
|
2850
2851
|
* Type definition for telephone validation error messages
|
|
2851
2852
|
*
|
|
2852
|
-
* @interface
|
|
2853
|
+
* @interface TwTelMessages
|
|
2853
2854
|
* @property {string} [required] - Message when field is required but empty
|
|
2854
2855
|
* @property {string} [invalid] - Message when telephone number format is invalid
|
|
2855
2856
|
* @property {string} [notInWhitelist] - Message when telephone number is not in whitelist
|
|
2856
2857
|
*/
|
|
2857
|
-
type
|
|
2858
|
+
type TwTelMessages = {
|
|
2858
2859
|
required?: string;
|
|
2859
2860
|
invalid?: string;
|
|
2860
2861
|
notInWhitelist?: string;
|
|
@@ -2864,27 +2865,27 @@ type TelMessages = {
|
|
|
2864
2865
|
*
|
|
2865
2866
|
* @template IsRequired - Whether the field is required (affects return type)
|
|
2866
2867
|
*
|
|
2867
|
-
* @interface
|
|
2868
|
+
* @interface TwTelOptions
|
|
2868
2869
|
* @property {IsRequired} [required=true] - Whether the field is required
|
|
2869
2870
|
* @property {string[]} [whitelist] - Array of specific telephone numbers that are always allowed
|
|
2870
2871
|
* @property {Function} [transform] - Custom transformation function for telephone number
|
|
2871
2872
|
* @property {string | null} [defaultValue] - Default value when input is empty
|
|
2872
|
-
* @property {Record<Locale,
|
|
2873
|
+
* @property {Record<Locale, TwTelMessages>} [i18n] - Custom error messages for different locales
|
|
2873
2874
|
*/
|
|
2874
|
-
type
|
|
2875
|
+
type TwTelOptions<IsRequired extends boolean = true> = {
|
|
2875
2876
|
whitelist?: string[];
|
|
2876
2877
|
transform?: (value: string) => string;
|
|
2877
2878
|
defaultValue?: IsRequired extends true ? string : string | null;
|
|
2878
|
-
i18n?: Record<Locale,
|
|
2879
|
+
i18n?: Record<Locale, TwTelMessages>;
|
|
2879
2880
|
};
|
|
2880
2881
|
/**
|
|
2881
2882
|
* Type alias for telephone validation schema based on required flag
|
|
2882
2883
|
*
|
|
2883
2884
|
* @template IsRequired - Whether the field is required
|
|
2884
|
-
* @typedef
|
|
2885
|
+
* @typedef TwTelSchema
|
|
2885
2886
|
* @description Returns ZodString if required, ZodNullable<ZodString> if optional
|
|
2886
2887
|
*/
|
|
2887
|
-
type
|
|
2888
|
+
type TwTelSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
2888
2889
|
/**
|
|
2889
2890
|
* Validates Taiwan landline telephone number format (Official 2024 rules)
|
|
2890
2891
|
*
|
|
@@ -2897,28 +2898,26 @@ type TelSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString
|
|
|
2897
2898
|
* number patterns.
|
|
2898
2899
|
*
|
|
2899
2900
|
* Supported area codes and formats:
|
|
2900
|
-
* - 02: Taipei, New Taipei, Keelung - 8 digits
|
|
2901
|
-
* - 03: Taoyuan, Hsinchu, Yilan, Hualien - 7 digits
|
|
2902
|
-
* - 037: Miaoli - 6 digits
|
|
2903
|
-
* - 04: Taichung, Changhua - 7 digits
|
|
2904
|
-
* - 049: Nantou - 7 digits
|
|
2901
|
+
* - 02: Taipei, New Taipei, Keelung - 8 digits
|
|
2902
|
+
* - 03: Taoyuan, Hsinchu, Yilan, Hualien - 7-8 digits
|
|
2903
|
+
* - 037: Miaoli - 6-7 digits
|
|
2904
|
+
* - 04: Taichung, Changhua, Nantou - 7-8 digits
|
|
2905
|
+
* - 049: Nantou - 7 digits
|
|
2905
2906
|
* - 05: Yunlin, Chiayi - 7 digits
|
|
2906
2907
|
* - 06: Tainan - 7 digits
|
|
2907
|
-
* - 07: Kaohsiung - 7 digits
|
|
2908
|
-
* - 08: Pingtung - 7 digits
|
|
2909
|
-
* - 082: Kinmen - 6 digits
|
|
2910
|
-
* -
|
|
2911
|
-
* -
|
|
2912
|
-
* - 089: Taitung - 6 digits (2~9+5D)
|
|
2908
|
+
* - 07: Kaohsiung - 7 digits
|
|
2909
|
+
* - 08: Pingtung - 7 digits
|
|
2910
|
+
* - 082: Kinmen - 6 digits
|
|
2911
|
+
* - 0836: Matsu - 5 digits
|
|
2912
|
+
* - 089: Taitung - 6 digits
|
|
2913
2913
|
*
|
|
2914
2914
|
* @example
|
|
2915
2915
|
* ```typescript
|
|
2916
2916
|
* validateTaiwanTel("0223456789") // true (Taipei area)
|
|
2917
|
-
* validateTaiwanTel("
|
|
2917
|
+
* validateTaiwanTel("0423288882") // true (Taichung area, 8 digits)
|
|
2918
2918
|
* validateTaiwanTel("037234567") // true (Miaoli area)
|
|
2919
2919
|
* validateTaiwanTel("082234567") // true (Kinmen area)
|
|
2920
2920
|
* validateTaiwanTel("02-2345-6789") // true (with separators)
|
|
2921
|
-
* validateTaiwanTel("0812345678") // false (invalid for 08 area)
|
|
2922
2921
|
* ```
|
|
2923
2922
|
*/
|
|
2924
2923
|
declare const validateTaiwanTel: (value: string) => boolean;
|
|
@@ -2928,7 +2927,7 @@ declare const validateTaiwanTel: (value: string) => boolean;
|
|
|
2928
2927
|
* @template IsRequired - Whether the field is required (affects return type)
|
|
2929
2928
|
* @param {IsRequired} [required=false] - Whether the field is required
|
|
2930
2929
|
* @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
|
|
2931
|
-
* @returns {
|
|
2930
|
+
* @returns {TwTelSchema<IsRequired>} Zod schema for telephone number validation
|
|
2932
2931
|
*
|
|
2933
2932
|
* @description
|
|
2934
2933
|
* Creates a comprehensive Taiwan landline telephone number validator with support for
|
|
@@ -2947,7 +2946,7 @@ declare const validateTaiwanTel: (value: string) => boolean;
|
|
|
2947
2946
|
* @example
|
|
2948
2947
|
* ```typescript
|
|
2949
2948
|
* // Basic telephone number validation
|
|
2950
|
-
* const basicSchema =
|
|
2949
|
+
* const basicSchema = twTel() // optional by default
|
|
2951
2950
|
* basicSchema.parse("0223456789") // ✓ Valid (Taipei)
|
|
2952
2951
|
* basicSchema.parse(null) // ✓ Valid (optional)
|
|
2953
2952
|
*
|
|
@@ -2961,26 +2960,26 @@ declare const validateTaiwanTel: (value: string) => boolean;
|
|
|
2961
2960
|
* basicSchema.parse("0812345678") // ✗ Invalid (wrong format for 08)
|
|
2962
2961
|
*
|
|
2963
2962
|
* // With whitelist (only specific numbers allowed)
|
|
2964
|
-
* const whitelistSchema =
|
|
2963
|
+
* const whitelistSchema = twTel(false, {
|
|
2965
2964
|
* whitelist: ["0223456789", "0312345678"]
|
|
2966
2965
|
* })
|
|
2967
2966
|
* whitelistSchema.parse("0223456789") // ✓ Valid (in whitelist)
|
|
2968
2967
|
* whitelistSchema.parse("0287654321") // ✗ Invalid (not in whitelist)
|
|
2969
2968
|
*
|
|
2970
2969
|
* // Optional telephone number
|
|
2971
|
-
* const optionalSchema =
|
|
2970
|
+
* const optionalSchema = twTel(false)
|
|
2972
2971
|
* optionalSchema.parse("") // ✓ Valid (returns null)
|
|
2973
2972
|
* optionalSchema.parse("0223456789") // ✓ Valid
|
|
2974
2973
|
*
|
|
2975
2974
|
* // With custom transformation (remove separators)
|
|
2976
|
-
* const transformSchema =
|
|
2975
|
+
* const transformSchema = twTel(false, {
|
|
2977
2976
|
* transform: (value) => value.replace(/[^0-9]/g, '') // Keep only digits
|
|
2978
2977
|
* })
|
|
2979
2978
|
* transformSchema.parse("02-2345-6789") // ✓ Valid (separators removed)
|
|
2980
2979
|
* transformSchema.parse("02 2345 6789") // ✓ Valid (spaces removed)
|
|
2981
2980
|
*
|
|
2982
2981
|
* // With custom error messages
|
|
2983
|
-
* const customSchema =
|
|
2982
|
+
* const customSchema = twTel(false, {
|
|
2984
2983
|
* i18n: {
|
|
2985
2984
|
* en: { invalid: "Please enter a valid Taiwan landline number" },
|
|
2986
2985
|
* 'zh-TW': { invalid: "請輸入有效的台灣市話號碼" }
|
|
@@ -2989,10 +2988,10 @@ declare const validateTaiwanTel: (value: string) => boolean;
|
|
|
2989
2988
|
* ```
|
|
2990
2989
|
*
|
|
2991
2990
|
* @throws {z.ZodError} When validation fails with specific error messages
|
|
2992
|
-
* @see {@link
|
|
2991
|
+
* @see {@link TwTelOptions} for all available configuration options
|
|
2993
2992
|
* @see {@link validateTaiwanTel} for validation logic details
|
|
2994
2993
|
*/
|
|
2995
|
-
declare function
|
|
2994
|
+
declare function twTel<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwTelOptions<IsRequired>, 'required'>): TwTelSchema<IsRequired>;
|
|
2996
2995
|
|
|
2997
2996
|
/**
|
|
2998
2997
|
* @fileoverview Taiwan Fax Number validator for Zod Kit
|
|
@@ -3007,12 +3006,12 @@ declare function tel<IsRequired extends boolean = false>(required?: IsRequired,
|
|
|
3007
3006
|
/**
|
|
3008
3007
|
* Type definition for fax number validation error messages
|
|
3009
3008
|
*
|
|
3010
|
-
* @interface
|
|
3009
|
+
* @interface TwFaxMessages
|
|
3011
3010
|
* @property {string} [required] - Message when field is required but empty
|
|
3012
3011
|
* @property {string} [invalid] - Message when fax number format is invalid
|
|
3013
3012
|
* @property {string} [notInWhitelist] - Message when fax number is not in whitelist
|
|
3014
3013
|
*/
|
|
3015
|
-
type
|
|
3014
|
+
type TwFaxMessages = {
|
|
3016
3015
|
required?: string;
|
|
3017
3016
|
invalid?: string;
|
|
3018
3017
|
notInWhitelist?: string;
|
|
@@ -3022,27 +3021,27 @@ type FaxMessages = {
|
|
|
3022
3021
|
*
|
|
3023
3022
|
* @template IsRequired - Whether the field is required (affects return type)
|
|
3024
3023
|
*
|
|
3025
|
-
* @interface
|
|
3024
|
+
* @interface TwFaxOptions
|
|
3026
3025
|
* @property {IsRequired} [required=true] - Whether the field is required
|
|
3027
3026
|
* @property {string[]} [whitelist] - Array of specific fax numbers that are always allowed
|
|
3028
3027
|
* @property {Function} [transform] - Custom transformation function for fax number
|
|
3029
3028
|
* @property {string | null} [defaultValue] - Default value when input is empty
|
|
3030
|
-
* @property {Record<Locale,
|
|
3029
|
+
* @property {Record<Locale, TwFaxMessages>} [i18n] - Custom error messages for different locales
|
|
3031
3030
|
*/
|
|
3032
|
-
type
|
|
3031
|
+
type TwFaxOptions<IsRequired extends boolean = true> = {
|
|
3033
3032
|
whitelist?: string[];
|
|
3034
3033
|
transform?: (value: string) => string;
|
|
3035
3034
|
defaultValue?: IsRequired extends true ? string : string | null;
|
|
3036
|
-
i18n?: Record<Locale,
|
|
3035
|
+
i18n?: Record<Locale, TwFaxMessages>;
|
|
3037
3036
|
};
|
|
3038
3037
|
/**
|
|
3039
3038
|
* Type alias for fax number validation schema based on required flag
|
|
3040
3039
|
*
|
|
3041
3040
|
* @template IsRequired - Whether the field is required
|
|
3042
|
-
* @typedef
|
|
3041
|
+
* @typedef TwFaxSchema
|
|
3043
3042
|
* @description Returns ZodString if required, ZodNullable<ZodString> if optional
|
|
3044
3043
|
*/
|
|
3045
|
-
type
|
|
3044
|
+
type TwFaxSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
3046
3045
|
/**
|
|
3047
3046
|
* Validates Taiwan fax number format (Official 2024 rules - same as landline)
|
|
3048
3047
|
*
|
|
@@ -3054,27 +3053,25 @@ type FaxSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString
|
|
|
3054
3053
|
* Fax numbers follow the same format as landline telephone numbers in Taiwan.
|
|
3055
3054
|
*
|
|
3056
3055
|
* Supported area codes and formats (same as landline):
|
|
3057
|
-
* - 02: Taipei, New Taipei, Keelung - 8 digits
|
|
3058
|
-
* - 03: Taoyuan, Hsinchu, Yilan, Hualien - 7 digits
|
|
3059
|
-
* - 037: Miaoli - 6 digits
|
|
3060
|
-
* - 04: Taichung, Changhua - 7 digits
|
|
3061
|
-
* - 049: Nantou - 7 digits
|
|
3056
|
+
* - 02: Taipei, New Taipei, Keelung - 8 digits
|
|
3057
|
+
* - 03: Taoyuan, Hsinchu, Yilan, Hualien - 7-8 digits
|
|
3058
|
+
* - 037: Miaoli - 6-7 digits
|
|
3059
|
+
* - 04: Taichung, Changhua, Nantou - 7-8 digits
|
|
3060
|
+
* - 049: Nantou - 7 digits
|
|
3062
3061
|
* - 05: Yunlin, Chiayi - 7 digits
|
|
3063
3062
|
* - 06: Tainan - 7 digits
|
|
3064
|
-
* - 07: Kaohsiung - 7 digits
|
|
3065
|
-
* - 08: Pingtung - 7 digits
|
|
3066
|
-
* - 082: Kinmen - 6 digits
|
|
3067
|
-
* -
|
|
3068
|
-
* -
|
|
3069
|
-
* - 089: Taitung - 6 digits (2~9+5D)
|
|
3063
|
+
* - 07: Kaohsiung - 7 digits
|
|
3064
|
+
* - 08: Pingtung - 7 digits
|
|
3065
|
+
* - 082: Kinmen - 6 digits
|
|
3066
|
+
* - 0836: Matsu - 5 digits
|
|
3067
|
+
* - 089: Taitung - 6 digits
|
|
3070
3068
|
*
|
|
3071
3069
|
* @example
|
|
3072
3070
|
* ```typescript
|
|
3073
3071
|
* validateTaiwanFax("0223456789") // true (Taipei area)
|
|
3074
|
-
* validateTaiwanFax("
|
|
3072
|
+
* validateTaiwanFax("0423288882") // true (Taichung area, 8 digits)
|
|
3075
3073
|
* validateTaiwanFax("037234567") // true (Miaoli area)
|
|
3076
3074
|
* validateTaiwanFax("02-2345-6789") // true (with separators)
|
|
3077
|
-
* validateTaiwanFax("0812345678") // false (invalid for 08 area)
|
|
3078
3075
|
* ```
|
|
3079
3076
|
*/
|
|
3080
3077
|
declare const validateTaiwanFax: (value: string) => boolean;
|
|
@@ -3084,7 +3081,7 @@ declare const validateTaiwanFax: (value: string) => boolean;
|
|
|
3084
3081
|
* @template IsRequired - Whether the field is required (affects return type)
|
|
3085
3082
|
* @param {IsRequired} [required=false] - Whether the field is required
|
|
3086
3083
|
* @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
|
|
3087
|
-
* @returns {
|
|
3084
|
+
* @returns {TwFaxSchema<IsRequired>} Zod schema for fax number validation
|
|
3088
3085
|
*
|
|
3089
3086
|
* @description
|
|
3090
3087
|
* Creates a comprehensive Taiwan fax number validator with support for all Taiwan
|
|
@@ -3103,7 +3100,7 @@ declare const validateTaiwanFax: (value: string) => boolean;
|
|
|
3103
3100
|
* @example
|
|
3104
3101
|
* ```typescript
|
|
3105
3102
|
* // Basic fax number validation
|
|
3106
|
-
* const basicSchema =
|
|
3103
|
+
* const basicSchema = twFax() // optional by default
|
|
3107
3104
|
* basicSchema.parse("0223456789") // ✓ Valid (Taipei)
|
|
3108
3105
|
* basicSchema.parse(null) // ✓ Valid (optional)
|
|
3109
3106
|
*
|
|
@@ -3117,25 +3114,25 @@ declare const validateTaiwanFax: (value: string) => boolean;
|
|
|
3117
3114
|
* basicSchema.parse("0812345678") // ✗ Invalid (wrong format for 08)
|
|
3118
3115
|
*
|
|
3119
3116
|
* // With whitelist (only specific numbers allowed)
|
|
3120
|
-
* const whitelistSchema =
|
|
3117
|
+
* const whitelistSchema = twFax(false, {
|
|
3121
3118
|
* whitelist: ["0223456789", "0312345678"]
|
|
3122
3119
|
* })
|
|
3123
3120
|
* whitelistSchema.parse("0223456789") // ✓ Valid (in whitelist)
|
|
3124
3121
|
* whitelistSchema.parse("0287654321") // ✗ Invalid (not in whitelist)
|
|
3125
3122
|
*
|
|
3126
3123
|
* // Optional fax number
|
|
3127
|
-
* const optionalSchema =
|
|
3124
|
+
* const optionalSchema = twFax(false)
|
|
3128
3125
|
* optionalSchema.parse("") // ✓ Valid (returns null)
|
|
3129
3126
|
* optionalSchema.parse("0223456789") // ✓ Valid
|
|
3130
3127
|
*
|
|
3131
3128
|
* // With custom transformation
|
|
3132
|
-
* const transformSchema =
|
|
3129
|
+
* const transformSchema = twFax(false, {
|
|
3133
3130
|
* transform: (value) => value.replace(/[^0-9]/g, '') // Keep only digits
|
|
3134
3131
|
* })
|
|
3135
3132
|
* transformSchema.parse("02-2345-6789") // ✓ Valid (separators removed)
|
|
3136
3133
|
*
|
|
3137
3134
|
* // With custom error messages
|
|
3138
|
-
* const customSchema =
|
|
3135
|
+
* const customSchema = twFax(false, {
|
|
3139
3136
|
* i18n: {
|
|
3140
3137
|
* en: { invalid: "Please enter a valid Taiwan fax number" },
|
|
3141
3138
|
* 'zh-TW': { invalid: "請輸入有效的台灣傳真號碼" }
|
|
@@ -3144,9 +3141,9 @@ declare const validateTaiwanFax: (value: string) => boolean;
|
|
|
3144
3141
|
* ```
|
|
3145
3142
|
*
|
|
3146
3143
|
* @throws {z.ZodError} When validation fails with specific error messages
|
|
3147
|
-
* @see {@link
|
|
3144
|
+
* @see {@link TwFaxOptions} for all available configuration options
|
|
3148
3145
|
* @see {@link validateTaiwanFax} for validation logic details
|
|
3149
3146
|
*/
|
|
3150
|
-
declare function
|
|
3147
|
+
declare function twFax<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwFaxOptions<IsRequired>, 'required'>): TwFaxSchema<IsRequired>;
|
|
3151
3148
|
|
|
3152
|
-
export { type BooleanMessages, type BooleanOptions, type BooleanSchema,
|
|
3149
|
+
export { type BooleanMessages, type BooleanOptions, type BooleanSchema, DATETIME_PATTERNS, type DateMessages, type DateOptions, type DateSchema, type DateTimeFormat, type DateTimeMessages, type DateTimeOptions, type DateTimeSchema, type EmailMessages, type EmailOptions, type EmailSchema, type FileMessages, type FileOptions, type FileSchema, ID_PATTERNS, type IdMessages, type IdOptions, type IdSchema, type IdType, type Locale, type NationalIdType, type NumberMessages, type NumberOptions, type NumberSchema, type PasswordMessages, type PasswordOptions, type PasswordSchema, type PasswordStrength, TIME_PATTERNS, type TextMessages, type TextOptions, type TextSchema, type TimeFormat, type TimeMessages, type TimeOptions, type TimeSchema, type TwBusinessIdMessages, type TwBusinessIdOptions, type TwBusinessIdSchema, type TwFaxMessages, type TwFaxOptions, type TwFaxSchema, type TwMobileMessages, type TwMobileOptions, type TwMobileSchema, type TwNationalIdMessages, type TwNationalIdOptions, type TwNationalIdSchema, type TwPostalCodeFormatType, type TwPostalCodeMessages, type TwPostalCodeOptions, type TwPostalCodeSchema, type TwTelMessages, type TwTelOptions, type TwTelSchema, type UrlMessages, type UrlOptions, type UrlSchema, VALID_3_DIGIT_PREFIXES, boolean, date, datetime, detectIdType, email, file, getLocale, id, normalizeDateTimeValue, normalizeTime, number, parseDateTimeValue, parseTimeToMinutes, password, setLocale, text, time, twBusinessId, twFax, twMobile, twNationalId, twPostalCode, twTel, url, validate3DigitPostalCode, validate5DigitPostalCode, validate6DigitPostalCode, validateCitizenId, validateDateTimeFormat, validateIdType, validateNewResidentId, validateOldResidentId, validateTaiwanBusinessId, validateTaiwanFax, validateTaiwanMobile, validateTaiwanNationalId, validateTaiwanPostalCode, validateTaiwanTel, validateTimeFormat };
|