@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,9 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkTQXDUMMLcjs = require('../chunk-TQXDUMML.cjs');
|
|
5
|
+
require('../chunk-UCOXAZJF.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.twInvoice = _chunkTQXDUMMLcjs.twInvoice; exports.validateTaiwanInvoice = _chunkTQXDUMMLcjs.validateTaiwanInvoice;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ZodString, ZodNullable } from 'zod';
|
|
2
|
+
import { L as Locale } from '../config-CABSSvAp.cjs';
|
|
3
|
+
|
|
4
|
+
type TwInvoiceMessages = {
|
|
5
|
+
required?: string;
|
|
6
|
+
invalid?: string;
|
|
7
|
+
};
|
|
8
|
+
type TwInvoiceOptions<IsRequired extends boolean = true> = {
|
|
9
|
+
transform?: (value: string) => string;
|
|
10
|
+
defaultValue?: IsRequired extends true ? string : string | null;
|
|
11
|
+
i18n?: Partial<Record<Locale, Partial<TwInvoiceMessages>>>;
|
|
12
|
+
};
|
|
13
|
+
type TwInvoiceSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
14
|
+
declare const validateTaiwanInvoice: (value: string) => boolean;
|
|
15
|
+
declare function twInvoice<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwInvoiceOptions<IsRequired>, "required">): TwInvoiceSchema<IsRequired>;
|
|
16
|
+
|
|
17
|
+
export { type TwInvoiceMessages, type TwInvoiceOptions, type TwInvoiceSchema, twInvoice, validateTaiwanInvoice };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ZodString, ZodNullable } from 'zod';
|
|
2
|
+
import { L as Locale } from '../config-CABSSvAp.js';
|
|
3
|
+
|
|
4
|
+
type TwInvoiceMessages = {
|
|
5
|
+
required?: string;
|
|
6
|
+
invalid?: string;
|
|
7
|
+
};
|
|
8
|
+
type TwInvoiceOptions<IsRequired extends boolean = true> = {
|
|
9
|
+
transform?: (value: string) => string;
|
|
10
|
+
defaultValue?: IsRequired extends true ? string : string | null;
|
|
11
|
+
i18n?: Partial<Record<Locale, Partial<TwInvoiceMessages>>>;
|
|
12
|
+
};
|
|
13
|
+
type TwInvoiceSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
14
|
+
declare const validateTaiwanInvoice: (value: string) => boolean;
|
|
15
|
+
declare function twInvoice<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwInvoiceOptions<IsRequired>, "required">): TwInvoiceSchema<IsRequired>;
|
|
16
|
+
|
|
17
|
+
export { type TwInvoiceMessages, type TwInvoiceOptions, type TwInvoiceSchema, twInvoice, validateTaiwanInvoice };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkGJIRDBZJcjs = require('../chunk-GJIRDBZJ.cjs');
|
|
5
|
+
require('../chunk-UCOXAZJF.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.twLicensePlate = _chunkGJIRDBZJcjs.twLicensePlate; exports.validateTaiwanLicensePlate = _chunkGJIRDBZJcjs.validateTaiwanLicensePlate;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ZodString, ZodNullable } from 'zod';
|
|
2
|
+
import { L as Locale } from '../config-CABSSvAp.cjs';
|
|
3
|
+
|
|
4
|
+
type PlateType = "car" | "motorcycle" | "any";
|
|
5
|
+
type TwLicensePlateMessages = {
|
|
6
|
+
required?: string;
|
|
7
|
+
invalid?: string;
|
|
8
|
+
};
|
|
9
|
+
type TwLicensePlateOptions<IsRequired extends boolean = true> = {
|
|
10
|
+
plateType?: PlateType;
|
|
11
|
+
transform?: (value: string) => string;
|
|
12
|
+
defaultValue?: IsRequired extends true ? string : string | null;
|
|
13
|
+
i18n?: Partial<Record<Locale, Partial<TwLicensePlateMessages>>>;
|
|
14
|
+
};
|
|
15
|
+
type TwLicensePlateSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
16
|
+
declare const validateTaiwanLicensePlate: (value: string, plateType?: PlateType) => boolean;
|
|
17
|
+
declare function twLicensePlate<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwLicensePlateOptions<IsRequired>, "required">): TwLicensePlateSchema<IsRequired>;
|
|
18
|
+
|
|
19
|
+
export { type PlateType, type TwLicensePlateMessages, type TwLicensePlateOptions, type TwLicensePlateSchema, twLicensePlate, validateTaiwanLicensePlate };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ZodString, ZodNullable } from 'zod';
|
|
2
|
+
import { L as Locale } from '../config-CABSSvAp.js';
|
|
3
|
+
|
|
4
|
+
type PlateType = "car" | "motorcycle" | "any";
|
|
5
|
+
type TwLicensePlateMessages = {
|
|
6
|
+
required?: string;
|
|
7
|
+
invalid?: string;
|
|
8
|
+
};
|
|
9
|
+
type TwLicensePlateOptions<IsRequired extends boolean = true> = {
|
|
10
|
+
plateType?: PlateType;
|
|
11
|
+
transform?: (value: string) => string;
|
|
12
|
+
defaultValue?: IsRequired extends true ? string : string | null;
|
|
13
|
+
i18n?: Partial<Record<Locale, Partial<TwLicensePlateMessages>>>;
|
|
14
|
+
};
|
|
15
|
+
type TwLicensePlateSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
16
|
+
declare const validateTaiwanLicensePlate: (value: string, plateType?: PlateType) => boolean;
|
|
17
|
+
declare function twLicensePlate<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwLicensePlateOptions<IsRequired>, "required">): TwLicensePlateSchema<IsRequired>;
|
|
18
|
+
|
|
19
|
+
export { type PlateType, type TwLicensePlateMessages, type TwLicensePlateOptions, type TwLicensePlateSchema, twLicensePlate, validateTaiwanLicensePlate };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkERH4NIMUcjs = require('../chunk-ERH4NIMU.cjs');
|
|
5
|
+
require('../chunk-UCOXAZJF.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.twMobile = _chunkERH4NIMUcjs.twMobile; exports.validateTaiwanMobile = _chunkERH4NIMUcjs.validateTaiwanMobile;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { ZodString, ZodNullable } from 'zod';
|
|
2
|
+
import { L as Locale } from '../config-CABSSvAp.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview Taiwan Mobile Phone Number validator for Zod Kit
|
|
6
|
+
*
|
|
7
|
+
* Provides validation for Taiwan mobile phone numbers with support for
|
|
8
|
+
* all Taiwan mobile network operators and whitelist functionality.
|
|
9
|
+
*
|
|
10
|
+
* @author Ong Hoe Yuan
|
|
11
|
+
* @version 0.0.5
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Type definition for mobile phone validation error messages
|
|
16
|
+
*
|
|
17
|
+
* @interface TwMobileMessages
|
|
18
|
+
* @property {string} [required] - Message when field is required but empty
|
|
19
|
+
* @property {string} [invalid] - Message when mobile number format is invalid
|
|
20
|
+
* @property {string} [notInWhitelist] - Message when mobile number is not in whitelist
|
|
21
|
+
*/
|
|
22
|
+
type TwMobileMessages = {
|
|
23
|
+
required?: string;
|
|
24
|
+
invalid?: string;
|
|
25
|
+
notInWhitelist?: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Configuration options for Taiwan mobile phone validation
|
|
29
|
+
*
|
|
30
|
+
* @template IsRequired - Whether the field is required (affects return type)
|
|
31
|
+
*
|
|
32
|
+
* @interface TwMobileOptions
|
|
33
|
+
* @property {IsRequired} [required=true] - Whether the field is required
|
|
34
|
+
* @property {string[]} [whitelist] - Array of specific mobile numbers that are always allowed
|
|
35
|
+
* @property {Function} [transform] - Custom transformation function for mobile number
|
|
36
|
+
* @property {string | null} [defaultValue] - Default value when input is empty
|
|
37
|
+
* @property {Record<Locale, TwMobileMessages>} [i18n] - Custom error messages for different locales
|
|
38
|
+
*/
|
|
39
|
+
type TwMobileOptions<IsRequired extends boolean = true> = {
|
|
40
|
+
whitelist?: string[];
|
|
41
|
+
transform?: (value: string) => string;
|
|
42
|
+
defaultValue?: IsRequired extends true ? string : string | null;
|
|
43
|
+
i18n?: Partial<Record<Locale, Partial<TwMobileMessages>>>;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Type alias for mobile phone validation schema based on required flag
|
|
47
|
+
*
|
|
48
|
+
* @template IsRequired - Whether the field is required
|
|
49
|
+
* @typedef TwMobileSchema
|
|
50
|
+
* @description Returns ZodString if required, ZodNullable<ZodString> if optional
|
|
51
|
+
*/
|
|
52
|
+
type TwMobileSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
53
|
+
/**
|
|
54
|
+
* Validates Taiwan mobile phone number format
|
|
55
|
+
*
|
|
56
|
+
* @param {string} value - The mobile phone number to validate
|
|
57
|
+
* @returns {boolean} True if the mobile number is valid
|
|
58
|
+
*
|
|
59
|
+
* @description
|
|
60
|
+
* Validates Taiwan mobile phone numbers according to the official numbering plan.
|
|
61
|
+
* Taiwan mobile numbers use the format: 09X-XXXX-XXXX (10 digits total).
|
|
62
|
+
*
|
|
63
|
+
* Valid prefixes: 090, 091, 092, 093, 094, 095, 096, 097, 098, 099
|
|
64
|
+
* - All major Taiwan mobile operators are covered
|
|
65
|
+
* - Format: 09[0-9] followed by 7 additional digits
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* validateTaiwanMobile("0912345678") // true
|
|
70
|
+
* validateTaiwanMobile("0987654321") // true
|
|
71
|
+
* validateTaiwanMobile("0812345678") // false (invalid prefix)
|
|
72
|
+
* validateTaiwanMobile("091234567") // false (too short)
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
declare const validateTaiwanMobile: (value: string) => boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Creates a Zod schema for Taiwan mobile phone number validation
|
|
78
|
+
*
|
|
79
|
+
* @template IsRequired - Whether the field is required (affects return type)
|
|
80
|
+
* @param {IsRequired} [required=false] - Whether the field is required
|
|
81
|
+
* @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
|
|
82
|
+
* @returns {TwMobileSchema<IsRequired>} Zod schema for mobile phone validation
|
|
83
|
+
*
|
|
84
|
+
* @description
|
|
85
|
+
* Creates a comprehensive Taiwan mobile phone number validator with support for
|
|
86
|
+
* all Taiwan mobile network operators and optional whitelist functionality.
|
|
87
|
+
*
|
|
88
|
+
* Features:
|
|
89
|
+
* - Taiwan mobile number format validation (09X-XXXX-XXXX)
|
|
90
|
+
* - Support for all Taiwan mobile operators (090-099 prefixes)
|
|
91
|
+
* - Whitelist functionality for specific allowed numbers
|
|
92
|
+
* - Automatic trimming and preprocessing
|
|
93
|
+
* - Custom transformation functions
|
|
94
|
+
* - Comprehensive internationalization
|
|
95
|
+
* - Optional field support
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* // Basic mobile number validation
|
|
100
|
+
* const basicSchema = twMobile() // optional by default
|
|
101
|
+
* basicSchema.parse("0912345678") // ✓ Valid
|
|
102
|
+
* basicSchema.parse(null) // ✓ Valid (optional)
|
|
103
|
+
*
|
|
104
|
+
* // Required validation
|
|
105
|
+
* const requiredSchema = parse("0912345678") // ✓ Valid
|
|
106
|
+
(true)
|
|
107
|
+
* requiredSchema.parse(null) // ✗ Invalid (required)
|
|
108
|
+
*
|
|
109
|
+
* basicSchema.parse("0987654321") // ✓ Valid
|
|
110
|
+
* basicSchema.parse("0812345678") // ✗ Invalid (wrong prefix)
|
|
111
|
+
*
|
|
112
|
+
* // With whitelist (only specific numbers allowed)
|
|
113
|
+
* const whitelistSchema = twMobile(false, {
|
|
114
|
+
* whitelist: ["0912345678", "0987654321"]
|
|
115
|
+
* })
|
|
116
|
+
* whitelistSchema.parse("0912345678") // ✓ Valid (in whitelist)
|
|
117
|
+
* whitelistSchema.parse("0911111111") // ✗ Invalid (not in whitelist)
|
|
118
|
+
*
|
|
119
|
+
* // Optional mobile number
|
|
120
|
+
* const optionalSchema = twMobile(false)
|
|
121
|
+
* optionalSchema.parse("") // ✓ Valid (returns null)
|
|
122
|
+
* optionalSchema.parse("0912345678") // ✓ Valid
|
|
123
|
+
*
|
|
124
|
+
* // With custom transformation
|
|
125
|
+
* const transformSchema = twMobile(false, {
|
|
126
|
+
* transform: (value) => value.replace(/[^0-9]/g, '') // Remove non-digits
|
|
127
|
+
* })
|
|
128
|
+
* transformSchema.parse("091-234-5678") // ✓ Valid (formatted input)
|
|
129
|
+
* transformSchema.parse("091 234 5678") // ✓ Valid (spaced input)
|
|
130
|
+
*
|
|
131
|
+
* // With custom error messages
|
|
132
|
+
* const customSchema = twMobile(false, {
|
|
133
|
+
* i18n: {
|
|
134
|
+
* en: { invalid: "Please enter a valid Taiwan mobile number" },
|
|
135
|
+
* 'zh-TW': { invalid: "請輸入有效的台灣手機號碼" }
|
|
136
|
+
* }
|
|
137
|
+
* })
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @throws {z.ZodError} When validation fails with specific error messages
|
|
141
|
+
* @see {@link TwMobileOptions} for all available configuration options
|
|
142
|
+
* @see {@link validateTaiwanMobile} for validation logic details
|
|
143
|
+
*/
|
|
144
|
+
declare function twMobile<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwMobileOptions<IsRequired>, 'required'>): TwMobileSchema<IsRequired>;
|
|
145
|
+
|
|
146
|
+
export { type TwMobileMessages, type TwMobileOptions, type TwMobileSchema, twMobile, validateTaiwanMobile };
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { ZodString, ZodNullable } from 'zod';
|
|
2
|
+
import { L as Locale } from '../config-CABSSvAp.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview Taiwan Mobile Phone Number validator for Zod Kit
|
|
6
|
+
*
|
|
7
|
+
* Provides validation for Taiwan mobile phone numbers with support for
|
|
8
|
+
* all Taiwan mobile network operators and whitelist functionality.
|
|
9
|
+
*
|
|
10
|
+
* @author Ong Hoe Yuan
|
|
11
|
+
* @version 0.0.5
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Type definition for mobile phone validation error messages
|
|
16
|
+
*
|
|
17
|
+
* @interface TwMobileMessages
|
|
18
|
+
* @property {string} [required] - Message when field is required but empty
|
|
19
|
+
* @property {string} [invalid] - Message when mobile number format is invalid
|
|
20
|
+
* @property {string} [notInWhitelist] - Message when mobile number is not in whitelist
|
|
21
|
+
*/
|
|
22
|
+
type TwMobileMessages = {
|
|
23
|
+
required?: string;
|
|
24
|
+
invalid?: string;
|
|
25
|
+
notInWhitelist?: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Configuration options for Taiwan mobile phone validation
|
|
29
|
+
*
|
|
30
|
+
* @template IsRequired - Whether the field is required (affects return type)
|
|
31
|
+
*
|
|
32
|
+
* @interface TwMobileOptions
|
|
33
|
+
* @property {IsRequired} [required=true] - Whether the field is required
|
|
34
|
+
* @property {string[]} [whitelist] - Array of specific mobile numbers that are always allowed
|
|
35
|
+
* @property {Function} [transform] - Custom transformation function for mobile number
|
|
36
|
+
* @property {string | null} [defaultValue] - Default value when input is empty
|
|
37
|
+
* @property {Record<Locale, TwMobileMessages>} [i18n] - Custom error messages for different locales
|
|
38
|
+
*/
|
|
39
|
+
type TwMobileOptions<IsRequired extends boolean = true> = {
|
|
40
|
+
whitelist?: string[];
|
|
41
|
+
transform?: (value: string) => string;
|
|
42
|
+
defaultValue?: IsRequired extends true ? string : string | null;
|
|
43
|
+
i18n?: Partial<Record<Locale, Partial<TwMobileMessages>>>;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Type alias for mobile phone validation schema based on required flag
|
|
47
|
+
*
|
|
48
|
+
* @template IsRequired - Whether the field is required
|
|
49
|
+
* @typedef TwMobileSchema
|
|
50
|
+
* @description Returns ZodString if required, ZodNullable<ZodString> if optional
|
|
51
|
+
*/
|
|
52
|
+
type TwMobileSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
53
|
+
/**
|
|
54
|
+
* Validates Taiwan mobile phone number format
|
|
55
|
+
*
|
|
56
|
+
* @param {string} value - The mobile phone number to validate
|
|
57
|
+
* @returns {boolean} True if the mobile number is valid
|
|
58
|
+
*
|
|
59
|
+
* @description
|
|
60
|
+
* Validates Taiwan mobile phone numbers according to the official numbering plan.
|
|
61
|
+
* Taiwan mobile numbers use the format: 09X-XXXX-XXXX (10 digits total).
|
|
62
|
+
*
|
|
63
|
+
* Valid prefixes: 090, 091, 092, 093, 094, 095, 096, 097, 098, 099
|
|
64
|
+
* - All major Taiwan mobile operators are covered
|
|
65
|
+
* - Format: 09[0-9] followed by 7 additional digits
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* validateTaiwanMobile("0912345678") // true
|
|
70
|
+
* validateTaiwanMobile("0987654321") // true
|
|
71
|
+
* validateTaiwanMobile("0812345678") // false (invalid prefix)
|
|
72
|
+
* validateTaiwanMobile("091234567") // false (too short)
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
declare const validateTaiwanMobile: (value: string) => boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Creates a Zod schema for Taiwan mobile phone number validation
|
|
78
|
+
*
|
|
79
|
+
* @template IsRequired - Whether the field is required (affects return type)
|
|
80
|
+
* @param {IsRequired} [required=false] - Whether the field is required
|
|
81
|
+
* @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
|
|
82
|
+
* @returns {TwMobileSchema<IsRequired>} Zod schema for mobile phone validation
|
|
83
|
+
*
|
|
84
|
+
* @description
|
|
85
|
+
* Creates a comprehensive Taiwan mobile phone number validator with support for
|
|
86
|
+
* all Taiwan mobile network operators and optional whitelist functionality.
|
|
87
|
+
*
|
|
88
|
+
* Features:
|
|
89
|
+
* - Taiwan mobile number format validation (09X-XXXX-XXXX)
|
|
90
|
+
* - Support for all Taiwan mobile operators (090-099 prefixes)
|
|
91
|
+
* - Whitelist functionality for specific allowed numbers
|
|
92
|
+
* - Automatic trimming and preprocessing
|
|
93
|
+
* - Custom transformation functions
|
|
94
|
+
* - Comprehensive internationalization
|
|
95
|
+
* - Optional field support
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* // Basic mobile number validation
|
|
100
|
+
* const basicSchema = twMobile() // optional by default
|
|
101
|
+
* basicSchema.parse("0912345678") // ✓ Valid
|
|
102
|
+
* basicSchema.parse(null) // ✓ Valid (optional)
|
|
103
|
+
*
|
|
104
|
+
* // Required validation
|
|
105
|
+
* const requiredSchema = parse("0912345678") // ✓ Valid
|
|
106
|
+
(true)
|
|
107
|
+
* requiredSchema.parse(null) // ✗ Invalid (required)
|
|
108
|
+
*
|
|
109
|
+
* basicSchema.parse("0987654321") // ✓ Valid
|
|
110
|
+
* basicSchema.parse("0812345678") // ✗ Invalid (wrong prefix)
|
|
111
|
+
*
|
|
112
|
+
* // With whitelist (only specific numbers allowed)
|
|
113
|
+
* const whitelistSchema = twMobile(false, {
|
|
114
|
+
* whitelist: ["0912345678", "0987654321"]
|
|
115
|
+
* })
|
|
116
|
+
* whitelistSchema.parse("0912345678") // ✓ Valid (in whitelist)
|
|
117
|
+
* whitelistSchema.parse("0911111111") // ✗ Invalid (not in whitelist)
|
|
118
|
+
*
|
|
119
|
+
* // Optional mobile number
|
|
120
|
+
* const optionalSchema = twMobile(false)
|
|
121
|
+
* optionalSchema.parse("") // ✓ Valid (returns null)
|
|
122
|
+
* optionalSchema.parse("0912345678") // ✓ Valid
|
|
123
|
+
*
|
|
124
|
+
* // With custom transformation
|
|
125
|
+
* const transformSchema = twMobile(false, {
|
|
126
|
+
* transform: (value) => value.replace(/[^0-9]/g, '') // Remove non-digits
|
|
127
|
+
* })
|
|
128
|
+
* transformSchema.parse("091-234-5678") // ✓ Valid (formatted input)
|
|
129
|
+
* transformSchema.parse("091 234 5678") // ✓ Valid (spaced input)
|
|
130
|
+
*
|
|
131
|
+
* // With custom error messages
|
|
132
|
+
* const customSchema = twMobile(false, {
|
|
133
|
+
* i18n: {
|
|
134
|
+
* en: { invalid: "Please enter a valid Taiwan mobile number" },
|
|
135
|
+
* 'zh-TW': { invalid: "請輸入有效的台灣手機號碼" }
|
|
136
|
+
* }
|
|
137
|
+
* })
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @throws {z.ZodError} When validation fails with specific error messages
|
|
141
|
+
* @see {@link TwMobileOptions} for all available configuration options
|
|
142
|
+
* @see {@link validateTaiwanMobile} for validation logic details
|
|
143
|
+
*/
|
|
144
|
+
declare function twMobile<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwMobileOptions<IsRequired>, 'required'>): TwMobileSchema<IsRequired>;
|
|
145
|
+
|
|
146
|
+
export { type TwMobileMessages, type TwMobileOptions, type TwMobileSchema, twMobile, validateTaiwanMobile };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _chunkZTFCJCPOcjs = require('../chunk-ZTFCJCPO.cjs');
|
|
8
|
+
require('../chunk-UCOXAZJF.cjs');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
exports.twNationalId = _chunkZTFCJCPOcjs.twNationalId; exports.validateCitizenId = _chunkZTFCJCPOcjs.validateCitizenId; exports.validateNewResidentId = _chunkZTFCJCPOcjs.validateNewResidentId; exports.validateOldResidentId = _chunkZTFCJCPOcjs.validateOldResidentId; exports.validateTaiwanNationalId = _chunkZTFCJCPOcjs.validateTaiwanNationalId;
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { ZodString, ZodNullable } from 'zod';
|
|
2
|
+
import { L as Locale } from '../config-CABSSvAp.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview Taiwan National ID (身分證/居留證) validator for Zod Kit
|
|
6
|
+
*
|
|
7
|
+
* Provides validation for Taiwan National ID cards (身分證) and
|
|
8
|
+
* Resident Certificates (居留證) with support for both old and new formats.
|
|
9
|
+
*
|
|
10
|
+
* @author Ong Hoe Yuan
|
|
11
|
+
* @version 0.0.5
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Type definition for national ID validation error messages
|
|
16
|
+
*
|
|
17
|
+
* @interface TwNationalIdMessages
|
|
18
|
+
* @property {string} [required] - Message when field is required but empty
|
|
19
|
+
* @property {string} [invalid] - Message when national ID format or checksum is invalid
|
|
20
|
+
*/
|
|
21
|
+
type TwNationalIdMessages = {
|
|
22
|
+
required?: string;
|
|
23
|
+
invalid?: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Types of Taiwan national identification documents
|
|
27
|
+
*
|
|
28
|
+
* @typedef {"citizen" | "resident" | "both"} NationalIdType
|
|
29
|
+
*
|
|
30
|
+
* Available types:
|
|
31
|
+
* - citizen: National ID card (身分證字號) for Taiwan citizens
|
|
32
|
+
* - resident: Resident certificate (居留證號) for foreign residents
|
|
33
|
+
* - both: Accept both citizen and resident IDs
|
|
34
|
+
*/
|
|
35
|
+
type NationalIdType = "citizen" | "resident" | "both";
|
|
36
|
+
/**
|
|
37
|
+
* Configuration options for Taiwan national ID validation
|
|
38
|
+
*
|
|
39
|
+
* @template IsRequired - Whether the field is required (affects return type)
|
|
40
|
+
*
|
|
41
|
+
* @interface TwNationalIdOptions
|
|
42
|
+
* @property {IsRequired} [required=true] - Whether the field is required
|
|
43
|
+
* @property {NationalIdType} [type="both"] - Type of ID to accept
|
|
44
|
+
* @property {boolean} [allowOldResident=true] - Whether to accept old-style resident certificates
|
|
45
|
+
* @property {Function} [transform] - Custom transformation function for ID
|
|
46
|
+
* @property {string | null} [defaultValue] - Default value when input is empty
|
|
47
|
+
* @property {Record<Locale, TwNationalIdMessages>} [i18n] - Custom error messages for different locales
|
|
48
|
+
*/
|
|
49
|
+
type TwNationalIdOptions<IsRequired extends boolean = true> = {
|
|
50
|
+
type?: NationalIdType;
|
|
51
|
+
allowOldResident?: boolean;
|
|
52
|
+
transform?: (value: string) => string;
|
|
53
|
+
defaultValue?: IsRequired extends true ? string : string | null;
|
|
54
|
+
i18n?: Partial<Record<Locale, Partial<TwNationalIdMessages>>>;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Type alias for national ID validation schema based on required flag
|
|
58
|
+
*
|
|
59
|
+
* @template IsRequired - Whether the field is required
|
|
60
|
+
* @typedef TwNationalIdSchema
|
|
61
|
+
* @description Returns ZodString if required, ZodNullable<ZodString> if optional
|
|
62
|
+
*/
|
|
63
|
+
type TwNationalIdSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
64
|
+
/**
|
|
65
|
+
* Validates Taiwan citizen national ID card (身分證字號)
|
|
66
|
+
*
|
|
67
|
+
* @param {string} value - The citizen ID to validate
|
|
68
|
+
* @returns {boolean} True if the citizen ID is valid
|
|
69
|
+
*
|
|
70
|
+
* @description
|
|
71
|
+
* Validates Taiwan citizen ID format: 1 letter + 1 gender digit (1-2) + 8 digits
|
|
72
|
+
* Uses checksum algorithm with city code conversion and weighted sum.
|
|
73
|
+
*
|
|
74
|
+
* Format: [A-Z][1-2]XXXXXXXX
|
|
75
|
+
* - First letter: City/county code
|
|
76
|
+
* - Second digit: Gender (1=male, 2=female)
|
|
77
|
+
* - Last 8 digits: Serial number + checksum
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* validateCitizenId("A123456789") // true/false based on checksum
|
|
82
|
+
* validateCitizenId("A323456789") // false (invalid gender digit)
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
declare const validateCitizenId: (value: string) => boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Validates old-style Taiwan resident certificate (舊式居留證號)
|
|
88
|
+
*
|
|
89
|
+
* @param {string} value - The old-style resident ID to validate
|
|
90
|
+
* @returns {boolean} True if the old-style resident ID is valid
|
|
91
|
+
*
|
|
92
|
+
* @description
|
|
93
|
+
* Validates old-style resident ID format: 1 letter + 1 gender letter + 8 digits
|
|
94
|
+
* Uses checksum algorithm with city code and gender code conversion.
|
|
95
|
+
*
|
|
96
|
+
* Format: [A-Z][ABCD]XXXXXXXX
|
|
97
|
+
* - First letter: City/county code
|
|
98
|
+
* - Second letter: Gender code (A/C=male, B/D=female)
|
|
99
|
+
* - Last 8 digits: Serial number + checksum
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* validateOldResidentId("AA12345678") // true/false based on checksum
|
|
104
|
+
* validateOldResidentId("AE12345678") // false (invalid gender letter)
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
declare const validateOldResidentId: (value: string) => boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Validates new-style Taiwan resident certificate (新式居留證號)
|
|
110
|
+
*
|
|
111
|
+
* @param {string} value - The new-style resident ID to validate
|
|
112
|
+
* @returns {boolean} True if the new-style resident ID is valid
|
|
113
|
+
*
|
|
114
|
+
* @description
|
|
115
|
+
* Validates new-style resident ID format: 1 letter + 1 type digit + 8 digits
|
|
116
|
+
* Uses the same checksum algorithm as citizen IDs.
|
|
117
|
+
*
|
|
118
|
+
* Format: [A-Z][89]XXXXXXXX
|
|
119
|
+
* - First letter: City/county code
|
|
120
|
+
* - Second digit: Type indicator (8 or 9)
|
|
121
|
+
* - Last 8 digits: Serial number + checksum
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* validateNewResidentId("A812345678") // true/false based on checksum
|
|
126
|
+
* validateNewResidentId("A712345678") // false (invalid type digit)
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
declare const validateNewResidentId: (value: string) => boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Main validation function for Taiwan national IDs
|
|
132
|
+
*
|
|
133
|
+
* @param {string} value - The national ID to validate
|
|
134
|
+
* @param {NationalIdType} [type="both"] - Type of ID to accept
|
|
135
|
+
* @param {boolean} [allowOldResident=true] - Whether to accept old-style resident certificates
|
|
136
|
+
* @returns {boolean} True if the national ID is valid
|
|
137
|
+
*
|
|
138
|
+
* @description
|
|
139
|
+
* Validates Taiwan national IDs based on the specified type and options.
|
|
140
|
+
* Supports citizen IDs, resident certificates (both old and new styles).
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* validateTaiwanNationalId("A123456789", "citizen") // Citizen ID only
|
|
145
|
+
* validateTaiwanNationalId("A812345678", "resident") // Resident ID only
|
|
146
|
+
* validateTaiwanNationalId("A123456789", "both") // Accept any valid format
|
|
147
|
+
* validateTaiwanNationalId("AA12345678", "both", false) // Reject old resident format
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
declare const validateTaiwanNationalId: (value: string, type?: NationalIdType, allowOldResident?: boolean) => boolean;
|
|
151
|
+
/**
|
|
152
|
+
* Creates a Zod schema for Taiwan National ID validation
|
|
153
|
+
*
|
|
154
|
+
* @template IsRequired - Whether the field is required (affects return type)
|
|
155
|
+
* @param {TwNationalIdOptions<IsRequired>} [options] - Configuration options for national ID validation
|
|
156
|
+
* @returns {TwNationalIdSchema<IsRequired>} Zod schema for national ID validation
|
|
157
|
+
*
|
|
158
|
+
* @description
|
|
159
|
+
* Creates a comprehensive Taiwan National ID validator that supports both
|
|
160
|
+
* citizen IDs and resident certificates with configurable validation rules.
|
|
161
|
+
*
|
|
162
|
+
* Features:
|
|
163
|
+
* - Citizen ID validation (身分證字號)
|
|
164
|
+
* - Resident certificate validation (居留證號, old and new formats)
|
|
165
|
+
* - Configurable ID type acceptance
|
|
166
|
+
* - Automatic case conversion to uppercase
|
|
167
|
+
* - Checksum verification
|
|
168
|
+
* - Custom transformation functions
|
|
169
|
+
* - Comprehensive internationalization
|
|
170
|
+
* - Optional field support
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* // Accept any valid Taiwan ID
|
|
175
|
+
* const anyIdSchema = twNationalId()
|
|
176
|
+
* anyIdSchema.parse("A123456789") // ✓ Valid citizen ID
|
|
177
|
+
* anyIdSchema.parse("A812345678") // ✓ Valid new resident ID
|
|
178
|
+
* anyIdSchema.parse("AA12345678") // ✓ Valid old resident ID
|
|
179
|
+
*
|
|
180
|
+
* // Citizen IDs only
|
|
181
|
+
* const citizenSchema = twNationalId(false, { type: "citizen" })
|
|
182
|
+
* citizenSchema.parse("A123456789") // ✓ Valid
|
|
183
|
+
* citizenSchema.parse("A812345678") // ✗ Invalid (resident ID)
|
|
184
|
+
*
|
|
185
|
+
* // Resident IDs only (new format only)
|
|
186
|
+
* const residentSchema = twNationalId(false, {
|
|
187
|
+
* type: "resident",
|
|
188
|
+
* allowOldResident: false
|
|
189
|
+
* })
|
|
190
|
+
* residentSchema.parse("A812345678") // ✓ Valid
|
|
191
|
+
* residentSchema.parse("AA12345678") // ✗ Invalid (old format)
|
|
192
|
+
*
|
|
193
|
+
* // Optional with custom transformation
|
|
194
|
+
* const optionalSchema = twNationalId(false, {
|
|
195
|
+
* transform: (value) => value.replace(/[^A-Z0-9]/g, '') // Remove special chars
|
|
196
|
+
* })
|
|
197
|
+
*
|
|
198
|
+
* // With custom error messages
|
|
199
|
+
* const customSchema = twNationalId(false, {
|
|
200
|
+
* i18n: {
|
|
201
|
+
* en: { invalid: "Please enter a valid Taiwan National ID" },
|
|
202
|
+
* 'zh-TW': { invalid: "請輸入有效的身分證或居留證號碼" }
|
|
203
|
+
* }
|
|
204
|
+
* })
|
|
205
|
+
* ```
|
|
206
|
+
*
|
|
207
|
+
* @throws {z.ZodError} When validation fails with specific error messages
|
|
208
|
+
* @see {@link TwNationalIdOptions} for all available configuration options
|
|
209
|
+
* @see {@link NationalIdType} for supported ID types
|
|
210
|
+
* @see {@link validateTaiwanNationalId} for validation logic details
|
|
211
|
+
*/
|
|
212
|
+
declare function twNationalId<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwNationalIdOptions<IsRequired>, 'required'>): TwNationalIdSchema<IsRequired>;
|
|
213
|
+
|
|
214
|
+
export { type NationalIdType, type TwNationalIdMessages, type TwNationalIdOptions, type TwNationalIdSchema, twNationalId, validateCitizenId, validateNewResidentId, validateOldResidentId, validateTaiwanNationalId };
|