@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.
Files changed (191) hide show
  1. package/.github/workflows/ci.yml +24 -0
  2. package/CLAUDE.md +64 -22
  3. package/dist/chunk-2SWEVDFZ.js +134 -0
  4. package/dist/chunk-32JI34CV.cjs +146 -0
  5. package/dist/chunk-42C5OHRK.js +71 -0
  6. package/dist/chunk-46VAH2BJ.js +160 -0
  7. package/dist/chunk-5JGTDL3Y.js +87 -0
  8. package/dist/chunk-5LEXCVLX.js +257 -0
  9. package/dist/chunk-6AAP4LPF.js +2606 -0
  10. package/dist/chunk-B4EZYZOK.cjs +215 -0
  11. package/dist/chunk-COYKBWTI.js +161 -0
  12. package/dist/chunk-DFJZ3NS2.cjs +151 -0
  13. package/dist/chunk-EDHT4LPO.js +118 -0
  14. package/dist/chunk-EGHL277K.cjs +165 -0
  15. package/dist/chunk-ERH4NIMU.cjs +69 -0
  16. package/dist/chunk-FM3EZ72O.js +165 -0
  17. package/dist/chunk-GJIRDBZJ.cjs +90 -0
  18. package/dist/chunk-H2XTEM4M.js +696 -0
  19. package/dist/chunk-HMSM6FFA.cjs +181 -0
  20. package/dist/chunk-HTEHINI7.cjs +177 -0
  21. package/dist/chunk-JOLSGZGN.cjs +696 -0
  22. package/dist/chunk-JXY7APBU.js +69 -0
  23. package/dist/chunk-K2UOY6TB.js +136 -0
  24. package/dist/chunk-KFOHKTFD.js +61 -0
  25. package/dist/chunk-L4HSIKTU.cjs +135 -0
  26. package/dist/chunk-LH7ZB4BK.js +124 -0
  27. package/dist/chunk-LL4ZWLGO.js +90 -0
  28. package/dist/chunk-M6MTP3NY.cjs +99 -0
  29. package/dist/chunk-MHJFYYGV.js +215 -0
  30. package/dist/chunk-MINMXGW3.js +135 -0
  31. package/dist/chunk-MM7IL2RG.js +181 -0
  32. package/dist/chunk-OPQJWHXN.cjs +301 -0
  33. package/dist/chunk-ORFHDJII.cjs +136 -0
  34. package/dist/chunk-ORVV4MCF.cjs +87 -0
  35. package/dist/chunk-QICQ6YEY.js +75 -0
  36. package/dist/chunk-RKUQREMW.js +127 -0
  37. package/dist/chunk-RO47DKQG.js +146 -0
  38. package/dist/chunk-RRPXIRTQ.cjs +257 -0
  39. package/dist/chunk-RYFG2GKM.cjs +118 -0
  40. package/dist/chunk-STNHTRG7.cjs +124 -0
  41. package/dist/chunk-TFGS34VD.cjs +71 -0
  42. package/dist/chunk-TQXDUMML.cjs +61 -0
  43. package/dist/chunk-UBK3VCVH.cjs +134 -0
  44. package/dist/chunk-UCOXAZJF.cjs +2606 -0
  45. package/dist/chunk-UQZKFAFX.js +130 -0
  46. package/dist/chunk-VB2KV2ZM.cjs +130 -0
  47. package/dist/chunk-WABKPFPK.js +151 -0
  48. package/dist/chunk-WDI4QJMQ.js +177 -0
  49. package/dist/chunk-YDH3L27K.cjs +127 -0
  50. package/dist/chunk-YIM3D2AD.js +99 -0
  51. package/dist/chunk-YPSEIDUR.cjs +160 -0
  52. package/dist/chunk-ZNJLWJX3.cjs +75 -0
  53. package/dist/chunk-ZTFCJCPO.cjs +161 -0
  54. package/dist/chunk-ZXUMK2RR.js +301 -0
  55. package/dist/common/boolean.cjs +7 -0
  56. package/dist/common/boolean.d.cts +119 -0
  57. package/dist/common/boolean.d.ts +119 -0
  58. package/dist/common/boolean.js +7 -0
  59. package/dist/common/color.cjs +9 -0
  60. package/dist/common/color.d.cts +26 -0
  61. package/dist/common/color.d.ts +26 -0
  62. package/dist/common/color.js +9 -0
  63. package/dist/common/coordinate.cjs +11 -0
  64. package/dist/common/coordinate.d.cts +23 -0
  65. package/dist/common/coordinate.d.ts +23 -0
  66. package/dist/common/coordinate.js +11 -0
  67. package/dist/common/credit-card.cjs +11 -0
  68. package/dist/common/credit-card.d.cts +22 -0
  69. package/dist/common/credit-card.d.ts +22 -0
  70. package/dist/common/credit-card.js +11 -0
  71. package/dist/common/date.cjs +7 -0
  72. package/dist/common/date.d.cts +174 -0
  73. package/dist/common/date.d.ts +174 -0
  74. package/dist/common/date.js +7 -0
  75. package/dist/common/datetime.cjs +15 -0
  76. package/dist/common/datetime.d.cts +301 -0
  77. package/dist/common/datetime.d.ts +301 -0
  78. package/dist/common/datetime.js +15 -0
  79. package/dist/common/email.cjs +7 -0
  80. package/dist/common/email.d.cts +149 -0
  81. package/dist/common/email.d.ts +149 -0
  82. package/dist/common/email.js +7 -0
  83. package/dist/common/file.cjs +7 -0
  84. package/dist/common/file.d.cts +178 -0
  85. package/dist/common/file.d.ts +178 -0
  86. package/dist/common/file.js +7 -0
  87. package/dist/common/id.cjs +13 -0
  88. package/dist/common/id.d.cts +288 -0
  89. package/dist/common/id.d.ts +288 -0
  90. package/dist/common/id.js +13 -0
  91. package/dist/common/ip.cjs +11 -0
  92. package/dist/common/ip.d.cts +25 -0
  93. package/dist/common/ip.d.ts +25 -0
  94. package/dist/common/ip.js +11 -0
  95. package/dist/common/number.cjs +7 -0
  96. package/dist/common/number.d.cts +167 -0
  97. package/dist/common/number.d.ts +167 -0
  98. package/dist/common/number.js +7 -0
  99. package/dist/common/password.cjs +7 -0
  100. package/dist/common/password.d.cts +192 -0
  101. package/dist/common/password.d.ts +192 -0
  102. package/dist/common/password.js +7 -0
  103. package/dist/common/text.cjs +7 -0
  104. package/dist/common/text.d.cts +156 -0
  105. package/dist/common/text.d.ts +156 -0
  106. package/dist/common/text.js +7 -0
  107. package/dist/common/time.cjs +15 -0
  108. package/dist/common/time.d.cts +268 -0
  109. package/dist/common/time.d.ts +268 -0
  110. package/dist/common/time.js +15 -0
  111. package/dist/common/url.cjs +7 -0
  112. package/dist/common/url.d.cts +196 -0
  113. package/dist/common/url.d.ts +196 -0
  114. package/dist/common/url.js +7 -0
  115. package/dist/config-CABSSvAp.d.cts +5 -0
  116. package/dist/config-CABSSvAp.d.ts +5 -0
  117. package/dist/index.cjs +180 -5255
  118. package/dist/index.d.cts +28 -3150
  119. package/dist/index.d.ts +28 -3150
  120. package/dist/index.js +135 -5131
  121. package/dist/taiwan/bank-account.cjs +11 -0
  122. package/dist/taiwan/bank-account.d.cts +22 -0
  123. package/dist/taiwan/bank-account.d.ts +22 -0
  124. package/dist/taiwan/bank-account.js +11 -0
  125. package/dist/taiwan/business-id.cjs +9 -0
  126. package/dist/taiwan/business-id.d.cts +133 -0
  127. package/dist/taiwan/business-id.d.ts +133 -0
  128. package/dist/taiwan/business-id.js +9 -0
  129. package/dist/taiwan/fax.cjs +9 -0
  130. package/dist/taiwan/fax.d.cts +157 -0
  131. package/dist/taiwan/fax.d.ts +157 -0
  132. package/dist/taiwan/fax.js +9 -0
  133. package/dist/taiwan/invoice.cjs +9 -0
  134. package/dist/taiwan/invoice.d.cts +17 -0
  135. package/dist/taiwan/invoice.d.ts +17 -0
  136. package/dist/taiwan/invoice.js +9 -0
  137. package/dist/taiwan/license-plate.cjs +9 -0
  138. package/dist/taiwan/license-plate.d.cts +19 -0
  139. package/dist/taiwan/license-plate.d.ts +19 -0
  140. package/dist/taiwan/license-plate.js +9 -0
  141. package/dist/taiwan/mobile.cjs +9 -0
  142. package/dist/taiwan/mobile.d.cts +146 -0
  143. package/dist/taiwan/mobile.d.ts +146 -0
  144. package/dist/taiwan/mobile.js +9 -0
  145. package/dist/taiwan/national-id.cjs +15 -0
  146. package/dist/taiwan/national-id.d.cts +214 -0
  147. package/dist/taiwan/national-id.d.ts +214 -0
  148. package/dist/taiwan/national-id.js +15 -0
  149. package/dist/taiwan/passport.cjs +9 -0
  150. package/dist/taiwan/passport.d.cts +19 -0
  151. package/dist/taiwan/passport.d.ts +19 -0
  152. package/dist/taiwan/passport.js +9 -0
  153. package/dist/taiwan/postal-code.cjs +17 -0
  154. package/dist/taiwan/postal-code.d.cts +237 -0
  155. package/dist/taiwan/postal-code.d.ts +237 -0
  156. package/dist/taiwan/postal-code.js +17 -0
  157. package/dist/taiwan/tel.cjs +9 -0
  158. package/dist/taiwan/tel.d.cts +162 -0
  159. package/dist/taiwan/tel.d.ts +162 -0
  160. package/dist/taiwan/tel.js +9 -0
  161. package/package.json +132 -6
  162. package/src/i18n/locales/en-GB.json +51 -0
  163. package/src/i18n/locales/en-US.json +52 -1
  164. package/src/i18n/locales/id-ID.json +51 -0
  165. package/src/i18n/locales/ja-JP.json +51 -0
  166. package/src/i18n/locales/ko-KR.json +51 -0
  167. package/src/i18n/locales/ms-MY.json +51 -0
  168. package/src/i18n/locales/th-TH.json +51 -0
  169. package/src/i18n/locales/vi-VN.json +51 -0
  170. package/src/i18n/locales/zh-CN.json +51 -0
  171. package/src/i18n/locales/zh-TW.json +51 -0
  172. package/src/index.ts +10 -2
  173. package/src/validators/common/color.ts +192 -0
  174. package/src/validators/common/coordinate.ts +159 -0
  175. package/src/validators/common/credit-card.ts +134 -0
  176. package/src/validators/common/id.ts +45 -3
  177. package/src/validators/common/ip.ts +210 -0
  178. package/src/validators/taiwan/bank-account.ts +176 -0
  179. package/src/validators/taiwan/invoice.ts +84 -0
  180. package/src/validators/taiwan/license-plate.ts +110 -0
  181. package/src/validators/taiwan/passport.ts +103 -0
  182. package/tests/common/color.test.ts +587 -0
  183. package/tests/common/coordinate.test.ts +345 -0
  184. package/tests/common/credit-card.test.ts +378 -0
  185. package/tests/common/id.test.ts +68 -3
  186. package/tests/common/ip.test.ts +419 -0
  187. package/tests/taiwan/bank-account.test.ts +286 -0
  188. package/tests/taiwan/invoice.test.ts +227 -0
  189. package/tests/taiwan/license-plate.test.ts +280 -0
  190. package/tests/taiwan/passport.test.ts +277 -0
  191. package/tsup.config.ts +36 -0
@@ -0,0 +1,11 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+ var _chunkL4HSIKTUcjs = require('../chunk-L4HSIKTU.cjs');
6
+ require('../chunk-UCOXAZJF.cjs');
7
+
8
+
9
+
10
+
11
+ exports.TAIWAN_BANK_CODES = _chunkL4HSIKTUcjs.TAIWAN_BANK_CODES; exports.twBankAccount = _chunkL4HSIKTUcjs.twBankAccount; exports.validateTaiwanBankAccount = _chunkL4HSIKTUcjs.validateTaiwanBankAccount;
@@ -0,0 +1,22 @@
1
+ import { ZodString, ZodNullable } from 'zod';
2
+ import { L as Locale } from '../config-CABSSvAp.cjs';
3
+
4
+ declare const TAIWAN_BANK_CODES: Record<string, string>;
5
+ type TwBankAccountMessages = {
6
+ required?: string;
7
+ invalid?: string;
8
+ invalidBankCode?: string;
9
+ invalidAccountNumber?: string;
10
+ };
11
+ type TwBankAccountOptions<IsRequired extends boolean = true> = {
12
+ validateBankCode?: boolean;
13
+ bankCode?: string;
14
+ transform?: (value: string) => string;
15
+ defaultValue?: IsRequired extends true ? string : string | null;
16
+ i18n?: Partial<Record<Locale, Partial<TwBankAccountMessages>>>;
17
+ };
18
+ type TwBankAccountSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
19
+ declare const validateTaiwanBankAccount: (value: string, validateBankCode?: boolean) => boolean;
20
+ declare function twBankAccount<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwBankAccountOptions<IsRequired>, "required">): TwBankAccountSchema<IsRequired>;
21
+
22
+ export { TAIWAN_BANK_CODES, type TwBankAccountMessages, type TwBankAccountOptions, type TwBankAccountSchema, twBankAccount, validateTaiwanBankAccount };
@@ -0,0 +1,22 @@
1
+ import { ZodString, ZodNullable } from 'zod';
2
+ import { L as Locale } from '../config-CABSSvAp.js';
3
+
4
+ declare const TAIWAN_BANK_CODES: Record<string, string>;
5
+ type TwBankAccountMessages = {
6
+ required?: string;
7
+ invalid?: string;
8
+ invalidBankCode?: string;
9
+ invalidAccountNumber?: string;
10
+ };
11
+ type TwBankAccountOptions<IsRequired extends boolean = true> = {
12
+ validateBankCode?: boolean;
13
+ bankCode?: string;
14
+ transform?: (value: string) => string;
15
+ defaultValue?: IsRequired extends true ? string : string | null;
16
+ i18n?: Partial<Record<Locale, Partial<TwBankAccountMessages>>>;
17
+ };
18
+ type TwBankAccountSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
19
+ declare const validateTaiwanBankAccount: (value: string, validateBankCode?: boolean) => boolean;
20
+ declare function twBankAccount<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwBankAccountOptions<IsRequired>, "required">): TwBankAccountSchema<IsRequired>;
21
+
22
+ export { TAIWAN_BANK_CODES, type TwBankAccountMessages, type TwBankAccountOptions, type TwBankAccountSchema, twBankAccount, validateTaiwanBankAccount };
@@ -0,0 +1,11 @@
1
+ import {
2
+ TAIWAN_BANK_CODES,
3
+ twBankAccount,
4
+ validateTaiwanBankAccount
5
+ } from "../chunk-MINMXGW3.js";
6
+ import "../chunk-6AAP4LPF.js";
7
+ export {
8
+ TAIWAN_BANK_CODES,
9
+ twBankAccount,
10
+ validateTaiwanBankAccount
11
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+ var _chunkORVV4MCFcjs = require('../chunk-ORVV4MCF.cjs');
5
+ require('../chunk-UCOXAZJF.cjs');
6
+
7
+
8
+
9
+ exports.twBusinessId = _chunkORVV4MCFcjs.twBusinessId; exports.validateTaiwanBusinessId = _chunkORVV4MCFcjs.validateTaiwanBusinessId;
@@ -0,0 +1,133 @@
1
+ import { ZodString, ZodNullable } from 'zod';
2
+ import { L as Locale } from '../config-CABSSvAp.cjs';
3
+
4
+ /**
5
+ * @fileoverview Taiwan Business ID (統一編號) validator for Zod Kit
6
+ *
7
+ * Provides validation for Taiwan Business Identification Numbers (統一編號) with
8
+ * support for both new (2023+) and legacy validation rules.
9
+ *
10
+ * @author Ong Hoe Yuan
11
+ * @version 0.0.5
12
+ */
13
+
14
+ /**
15
+ * Type definition for business ID validation error messages
16
+ *
17
+ * @interface TwBusinessIdMessages
18
+ * @property {string} [required] - Message when field is required but empty
19
+ * @property {string} [invalid] - Message when business ID format or checksum is invalid
20
+ */
21
+ type TwBusinessIdMessages = {
22
+ required?: string;
23
+ invalid?: string;
24
+ };
25
+ /**
26
+ * Configuration options for Taiwan business ID validation
27
+ *
28
+ * @template IsRequired - Whether the field is required (affects return type)
29
+ *
30
+ * @interface TwBusinessIdOptions
31
+ * @property {IsRequired} [required=true] - Whether the field is required
32
+ * @property {Function} [transform] - Custom transformation function for business ID
33
+ * @property {string | null} [defaultValue] - Default value when input is empty
34
+ * @property {Record<Locale, TwBusinessIdMessages>} [i18n] - Custom error messages for different locales
35
+ */
36
+ type TwBusinessIdOptions<IsRequired extends boolean = true> = {
37
+ transform?: (value: string) => string;
38
+ defaultValue?: IsRequired extends true ? string : string | null;
39
+ i18n?: Partial<Record<Locale, Partial<TwBusinessIdMessages>>>;
40
+ };
41
+ /**
42
+ * Type alias for business ID validation schema based on required flag
43
+ *
44
+ * @template IsRequired - Whether the field is required
45
+ * @typedef TwBusinessIdSchema
46
+ * @description Returns ZodString if required, ZodNullable<ZodString> if optional
47
+ */
48
+ type TwBusinessIdSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
49
+ /**
50
+ * Validates Taiwan Business Identification Number (統一編號)
51
+ *
52
+ * @param {string} value - The business ID to validate
53
+ * @returns {boolean} True if the business ID is valid
54
+ *
55
+ * @description
56
+ * Validates Taiwan Business ID using both new (2023+) and legacy validation rules.
57
+ * The validation includes format checking (8 digits) and checksum verification.
58
+ *
59
+ * Validation rules:
60
+ * 1. Must be exactly 8 digits
61
+ * 2. Weighted sum calculation using coefficients [1,2,1,2,1,2,4] for first 7 digits
62
+ * 3. New rules (2023+): Sum + 8th digit must be divisible by 5
63
+ * 4. Legacy rules: Sum + 8th digit must be divisible by 10
64
+ * 5. Special case: If 7th digit is 7, try alternative calculation with +1
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * validateTaiwanBusinessId("12345675") // true (if valid checksum)
69
+ * validateTaiwanBusinessId("1234567") // false (not 8 digits)
70
+ * validateTaiwanBusinessId("abcd1234") // false (not all digits)
71
+ * ```
72
+ */
73
+ declare const validateTaiwanBusinessId: (value: string) => boolean;
74
+ /**
75
+ * Creates a Zod schema for Taiwan Business ID validation
76
+ *
77
+ * @template IsRequired - Whether the field is required (affects return type)
78
+ * @param {BusinessIdOptions<IsRequired>} [options] - Configuration options for business ID validation
79
+ * @returns {BusinessIdSchema<IsRequired>} Zod schema for business ID validation
80
+ *
81
+ * @description
82
+ * Creates a comprehensive Taiwan Business ID validator that validates the format
83
+ * and checksum according to Taiwan government specifications.
84
+ *
85
+ * Features:
86
+ * - 8-digit format validation
87
+ * - Checksum verification (supports both new 2023+ and legacy rules)
88
+ * - Automatic trimming and preprocessing
89
+ * - Custom transformation functions
90
+ * - Comprehensive internationalization
91
+ * - Optional field support
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * // Basic business ID validation
96
+ * const basicSchema = businessId() // optional by default
97
+ * basicSchema.parse("12345675") // ✓ Valid (if checksum correct)
98
+ * basicSchema.parse(null) // ✓ Valid (optional)
99
+ *
100
+ * // Required validation
101
+ * const requiredSchema = parse("12345675") // ✓ Valid (if checksum correct)
102
+ (true)
103
+ * requiredSchema.parse(null) // ✗ Invalid (required)
104
+ *
105
+ * basicSchema.parse("1234567") // ✗ Invalid (not 8 digits)
106
+ *
107
+ * // Optional business ID
108
+ * const optionalSchema = businessId(false)
109
+ * optionalSchema.parse("") // ✓ Valid (returns null)
110
+ * optionalSchema.parse("12345675") // ✓ Valid (if checksum correct)
111
+ *
112
+ * // With custom transformation
113
+ * const transformSchema = businessId(false, {
114
+ * transform: (value) => value.replace(/[^0-9]/g, '') // Remove non-digits
115
+ * })
116
+ * transformSchema.parse("1234-5675") // ✓ Valid (if checksum correct after cleaning)
117
+ *
118
+ * // With custom error messages
119
+ * const customSchema = businessId(false, {
120
+ * i18n: {
121
+ * en: { invalid: "Please enter a valid Taiwan Business ID" },
122
+ * 'zh-TW': { invalid: "請輸入有效的統一編號" }
123
+ * }
124
+ * })
125
+ * ```
126
+ *
127
+ * @throws {z.ZodError} When validation fails with specific error messages
128
+ * @see {@link TwBusinessIdOptions} for all available configuration options
129
+ * @see {@link validateTaiwanBusinessId} for validation logic details
130
+ */
131
+ declare function twBusinessId<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwBusinessIdOptions<IsRequired>, "required">): TwBusinessIdSchema<IsRequired>;
132
+
133
+ export { type TwBusinessIdMessages, type TwBusinessIdOptions, type TwBusinessIdSchema, twBusinessId, validateTaiwanBusinessId };
@@ -0,0 +1,133 @@
1
+ import { ZodString, ZodNullable } from 'zod';
2
+ import { L as Locale } from '../config-CABSSvAp.js';
3
+
4
+ /**
5
+ * @fileoverview Taiwan Business ID (統一編號) validator for Zod Kit
6
+ *
7
+ * Provides validation for Taiwan Business Identification Numbers (統一編號) with
8
+ * support for both new (2023+) and legacy validation rules.
9
+ *
10
+ * @author Ong Hoe Yuan
11
+ * @version 0.0.5
12
+ */
13
+
14
+ /**
15
+ * Type definition for business ID validation error messages
16
+ *
17
+ * @interface TwBusinessIdMessages
18
+ * @property {string} [required] - Message when field is required but empty
19
+ * @property {string} [invalid] - Message when business ID format or checksum is invalid
20
+ */
21
+ type TwBusinessIdMessages = {
22
+ required?: string;
23
+ invalid?: string;
24
+ };
25
+ /**
26
+ * Configuration options for Taiwan business ID validation
27
+ *
28
+ * @template IsRequired - Whether the field is required (affects return type)
29
+ *
30
+ * @interface TwBusinessIdOptions
31
+ * @property {IsRequired} [required=true] - Whether the field is required
32
+ * @property {Function} [transform] - Custom transformation function for business ID
33
+ * @property {string | null} [defaultValue] - Default value when input is empty
34
+ * @property {Record<Locale, TwBusinessIdMessages>} [i18n] - Custom error messages for different locales
35
+ */
36
+ type TwBusinessIdOptions<IsRequired extends boolean = true> = {
37
+ transform?: (value: string) => string;
38
+ defaultValue?: IsRequired extends true ? string : string | null;
39
+ i18n?: Partial<Record<Locale, Partial<TwBusinessIdMessages>>>;
40
+ };
41
+ /**
42
+ * Type alias for business ID validation schema based on required flag
43
+ *
44
+ * @template IsRequired - Whether the field is required
45
+ * @typedef TwBusinessIdSchema
46
+ * @description Returns ZodString if required, ZodNullable<ZodString> if optional
47
+ */
48
+ type TwBusinessIdSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
49
+ /**
50
+ * Validates Taiwan Business Identification Number (統一編號)
51
+ *
52
+ * @param {string} value - The business ID to validate
53
+ * @returns {boolean} True if the business ID is valid
54
+ *
55
+ * @description
56
+ * Validates Taiwan Business ID using both new (2023+) and legacy validation rules.
57
+ * The validation includes format checking (8 digits) and checksum verification.
58
+ *
59
+ * Validation rules:
60
+ * 1. Must be exactly 8 digits
61
+ * 2. Weighted sum calculation using coefficients [1,2,1,2,1,2,4] for first 7 digits
62
+ * 3. New rules (2023+): Sum + 8th digit must be divisible by 5
63
+ * 4. Legacy rules: Sum + 8th digit must be divisible by 10
64
+ * 5. Special case: If 7th digit is 7, try alternative calculation with +1
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * validateTaiwanBusinessId("12345675") // true (if valid checksum)
69
+ * validateTaiwanBusinessId("1234567") // false (not 8 digits)
70
+ * validateTaiwanBusinessId("abcd1234") // false (not all digits)
71
+ * ```
72
+ */
73
+ declare const validateTaiwanBusinessId: (value: string) => boolean;
74
+ /**
75
+ * Creates a Zod schema for Taiwan Business ID validation
76
+ *
77
+ * @template IsRequired - Whether the field is required (affects return type)
78
+ * @param {BusinessIdOptions<IsRequired>} [options] - Configuration options for business ID validation
79
+ * @returns {BusinessIdSchema<IsRequired>} Zod schema for business ID validation
80
+ *
81
+ * @description
82
+ * Creates a comprehensive Taiwan Business ID validator that validates the format
83
+ * and checksum according to Taiwan government specifications.
84
+ *
85
+ * Features:
86
+ * - 8-digit format validation
87
+ * - Checksum verification (supports both new 2023+ and legacy rules)
88
+ * - Automatic trimming and preprocessing
89
+ * - Custom transformation functions
90
+ * - Comprehensive internationalization
91
+ * - Optional field support
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * // Basic business ID validation
96
+ * const basicSchema = businessId() // optional by default
97
+ * basicSchema.parse("12345675") // ✓ Valid (if checksum correct)
98
+ * basicSchema.parse(null) // ✓ Valid (optional)
99
+ *
100
+ * // Required validation
101
+ * const requiredSchema = parse("12345675") // ✓ Valid (if checksum correct)
102
+ (true)
103
+ * requiredSchema.parse(null) // ✗ Invalid (required)
104
+ *
105
+ * basicSchema.parse("1234567") // ✗ Invalid (not 8 digits)
106
+ *
107
+ * // Optional business ID
108
+ * const optionalSchema = businessId(false)
109
+ * optionalSchema.parse("") // ✓ Valid (returns null)
110
+ * optionalSchema.parse("12345675") // ✓ Valid (if checksum correct)
111
+ *
112
+ * // With custom transformation
113
+ * const transformSchema = businessId(false, {
114
+ * transform: (value) => value.replace(/[^0-9]/g, '') // Remove non-digits
115
+ * })
116
+ * transformSchema.parse("1234-5675") // ✓ Valid (if checksum correct after cleaning)
117
+ *
118
+ * // With custom error messages
119
+ * const customSchema = businessId(false, {
120
+ * i18n: {
121
+ * en: { invalid: "Please enter a valid Taiwan Business ID" },
122
+ * 'zh-TW': { invalid: "請輸入有效的統一編號" }
123
+ * }
124
+ * })
125
+ * ```
126
+ *
127
+ * @throws {z.ZodError} When validation fails with specific error messages
128
+ * @see {@link TwBusinessIdOptions} for all available configuration options
129
+ * @see {@link validateTaiwanBusinessId} for validation logic details
130
+ */
131
+ declare function twBusinessId<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwBusinessIdOptions<IsRequired>, "required">): TwBusinessIdSchema<IsRequired>;
132
+
133
+ export { type TwBusinessIdMessages, type TwBusinessIdOptions, type TwBusinessIdSchema, twBusinessId, validateTaiwanBusinessId };
@@ -0,0 +1,9 @@
1
+ import {
2
+ twBusinessId,
3
+ validateTaiwanBusinessId
4
+ } from "../chunk-5JGTDL3Y.js";
5
+ import "../chunk-6AAP4LPF.js";
6
+ export {
7
+ twBusinessId,
8
+ validateTaiwanBusinessId
9
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+ var _chunkYDH3L27Kcjs = require('../chunk-YDH3L27K.cjs');
5
+ require('../chunk-UCOXAZJF.cjs');
6
+
7
+
8
+
9
+ exports.twFax = _chunkYDH3L27Kcjs.twFax; exports.validateTaiwanFax = _chunkYDH3L27Kcjs.validateTaiwanFax;
@@ -0,0 +1,157 @@
1
+ import { ZodString, ZodNullable } from 'zod';
2
+ import { L as Locale } from '../config-CABSSvAp.cjs';
3
+
4
+ /**
5
+ * @fileoverview Taiwan Fax Number validator for Zod Kit
6
+ *
7
+ * Provides validation for Taiwan fax numbers according to the official 2024
8
+ * telecom numbering plan. Uses the same format as landline telephone numbers.
9
+ *
10
+ * @author Ong Hoe Yuan
11
+ * @version 0.0.5
12
+ */
13
+
14
+ /**
15
+ * Type definition for fax number validation error messages
16
+ *
17
+ * @interface TwFaxMessages
18
+ * @property {string} [required] - Message when field is required but empty
19
+ * @property {string} [invalid] - Message when fax number format is invalid
20
+ * @property {string} [notInWhitelist] - Message when fax number is not in whitelist
21
+ */
22
+ type TwFaxMessages = {
23
+ required?: string;
24
+ invalid?: string;
25
+ notInWhitelist?: string;
26
+ };
27
+ /**
28
+ * Configuration options for Taiwan fax number validation
29
+ *
30
+ * @template IsRequired - Whether the field is required (affects return type)
31
+ *
32
+ * @interface TwFaxOptions
33
+ * @property {IsRequired} [required=true] - Whether the field is required
34
+ * @property {string[]} [whitelist] - Array of specific fax numbers that are always allowed
35
+ * @property {Function} [transform] - Custom transformation function for fax number
36
+ * @property {string | null} [defaultValue] - Default value when input is empty
37
+ * @property {Record<Locale, TwFaxMessages>} [i18n] - Custom error messages for different locales
38
+ */
39
+ type TwFaxOptions<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<TwFaxMessages>>>;
44
+ };
45
+ /**
46
+ * Type alias for fax number validation schema based on required flag
47
+ *
48
+ * @template IsRequired - Whether the field is required
49
+ * @typedef TwFaxSchema
50
+ * @description Returns ZodString if required, ZodNullable<ZodString> if optional
51
+ */
52
+ type TwFaxSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
53
+ /**
54
+ * Validates Taiwan fax number format (Official 2024 rules - same as landline)
55
+ *
56
+ * @param {string} value - The fax number to validate
57
+ * @returns {boolean} True if the fax number is valid
58
+ *
59
+ * @description
60
+ * Validates Taiwan fax numbers according to the official 2024 telecom numbering plan.
61
+ * Fax numbers follow the same format as landline telephone numbers in Taiwan.
62
+ *
63
+ * Supported area codes and formats (same as landline):
64
+ * - 02: Taipei, New Taipei, Keelung - 8 digits
65
+ * - 03: Taoyuan, Hsinchu, Yilan, Hualien - 7-8 digits
66
+ * - 037: Miaoli - 6-7 digits
67
+ * - 04: Taichung, Changhua, Nantou - 7-8 digits
68
+ * - 049: Nantou - 7 digits
69
+ * - 05: Yunlin, Chiayi - 7 digits
70
+ * - 06: Tainan - 7 digits
71
+ * - 07: Kaohsiung - 7 digits
72
+ * - 08: Pingtung - 7 digits
73
+ * - 082: Kinmen - 6 digits
74
+ * - 0836: Matsu - 5 digits
75
+ * - 089: Taitung - 6 digits
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * validateTaiwanFax("0223456789") // true (Taipei area)
80
+ * validateTaiwanFax("0423288882") // true (Taichung area, 8 digits)
81
+ * validateTaiwanFax("037234567") // true (Miaoli area)
82
+ * validateTaiwanFax("02-2345-6789") // true (with separators)
83
+ * ```
84
+ */
85
+ declare const validateTaiwanFax: (value: string) => boolean;
86
+ /**
87
+ * Creates a Zod schema for Taiwan fax number validation
88
+ *
89
+ * @template IsRequired - Whether the field is required (affects return type)
90
+ * @param {IsRequired} [required=false] - Whether the field is required
91
+ * @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
92
+ * @returns {TwFaxSchema<IsRequired>} Zod schema for fax number validation
93
+ *
94
+ * @description
95
+ * Creates a comprehensive Taiwan fax number validator with support for all Taiwan
96
+ * area codes. Fax numbers follow the same format as landline telephone numbers.
97
+ *
98
+ * Features:
99
+ * - Complete Taiwan area code support (same as landline)
100
+ * - Automatic separator handling (hyphens and spaces)
101
+ * - Area-specific number length and pattern validation
102
+ * - Whitelist functionality for specific allowed numbers
103
+ * - Automatic trimming and preprocessing
104
+ * - Custom transformation functions
105
+ * - Comprehensive internationalization
106
+ * - Optional field support
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * // Basic fax number validation
111
+ * const basicSchema = twFax() // optional by default
112
+ * basicSchema.parse("0223456789") // ✓ Valid (Taipei)
113
+ * basicSchema.parse(null) // ✓ Valid (optional)
114
+ *
115
+ * // Required validation
116
+ * const requiredSchema = parse("0223456789") // ✓ Valid (Taipei)
117
+ (true)
118
+ * requiredSchema.parse(null) // ✗ Invalid (required)
119
+ *
120
+ * basicSchema.parse("0312345678") // ✓ Valid (Taoyuan)
121
+ * basicSchema.parse("02-2345-6789") // ✓ Valid (with separators)
122
+ * basicSchema.parse("0812345678") // ✗ Invalid (wrong format for 08)
123
+ *
124
+ * // With whitelist (only specific numbers allowed)
125
+ * const whitelistSchema = twFax(false, {
126
+ * whitelist: ["0223456789", "0312345678"]
127
+ * })
128
+ * whitelistSchema.parse("0223456789") // ✓ Valid (in whitelist)
129
+ * whitelistSchema.parse("0287654321") // ✗ Invalid (not in whitelist)
130
+ *
131
+ * // Optional fax number
132
+ * const optionalSchema = twFax(false)
133
+ * optionalSchema.parse("") // ✓ Valid (returns null)
134
+ * optionalSchema.parse("0223456789") // ✓ Valid
135
+ *
136
+ * // With custom transformation
137
+ * const transformSchema = twFax(false, {
138
+ * transform: (value) => value.replace(/[^0-9]/g, '') // Keep only digits
139
+ * })
140
+ * transformSchema.parse("02-2345-6789") // ✓ Valid (separators removed)
141
+ *
142
+ * // With custom error messages
143
+ * const customSchema = twFax(false, {
144
+ * i18n: {
145
+ * en: { invalid: "Please enter a valid Taiwan fax number" },
146
+ * 'zh-TW': { invalid: "請輸入有效的台灣傳真號碼" }
147
+ * }
148
+ * })
149
+ * ```
150
+ *
151
+ * @throws {z.ZodError} When validation fails with specific error messages
152
+ * @see {@link TwFaxOptions} for all available configuration options
153
+ * @see {@link validateTaiwanFax} for validation logic details
154
+ */
155
+ declare function twFax<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwFaxOptions<IsRequired>, 'required'>): TwFaxSchema<IsRequired>;
156
+
157
+ export { type TwFaxMessages, type TwFaxOptions, type TwFaxSchema, twFax, validateTaiwanFax };
@@ -0,0 +1,157 @@
1
+ import { ZodString, ZodNullable } from 'zod';
2
+ import { L as Locale } from '../config-CABSSvAp.js';
3
+
4
+ /**
5
+ * @fileoverview Taiwan Fax Number validator for Zod Kit
6
+ *
7
+ * Provides validation for Taiwan fax numbers according to the official 2024
8
+ * telecom numbering plan. Uses the same format as landline telephone numbers.
9
+ *
10
+ * @author Ong Hoe Yuan
11
+ * @version 0.0.5
12
+ */
13
+
14
+ /**
15
+ * Type definition for fax number validation error messages
16
+ *
17
+ * @interface TwFaxMessages
18
+ * @property {string} [required] - Message when field is required but empty
19
+ * @property {string} [invalid] - Message when fax number format is invalid
20
+ * @property {string} [notInWhitelist] - Message when fax number is not in whitelist
21
+ */
22
+ type TwFaxMessages = {
23
+ required?: string;
24
+ invalid?: string;
25
+ notInWhitelist?: string;
26
+ };
27
+ /**
28
+ * Configuration options for Taiwan fax number validation
29
+ *
30
+ * @template IsRequired - Whether the field is required (affects return type)
31
+ *
32
+ * @interface TwFaxOptions
33
+ * @property {IsRequired} [required=true] - Whether the field is required
34
+ * @property {string[]} [whitelist] - Array of specific fax numbers that are always allowed
35
+ * @property {Function} [transform] - Custom transformation function for fax number
36
+ * @property {string | null} [defaultValue] - Default value when input is empty
37
+ * @property {Record<Locale, TwFaxMessages>} [i18n] - Custom error messages for different locales
38
+ */
39
+ type TwFaxOptions<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<TwFaxMessages>>>;
44
+ };
45
+ /**
46
+ * Type alias for fax number validation schema based on required flag
47
+ *
48
+ * @template IsRequired - Whether the field is required
49
+ * @typedef TwFaxSchema
50
+ * @description Returns ZodString if required, ZodNullable<ZodString> if optional
51
+ */
52
+ type TwFaxSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
53
+ /**
54
+ * Validates Taiwan fax number format (Official 2024 rules - same as landline)
55
+ *
56
+ * @param {string} value - The fax number to validate
57
+ * @returns {boolean} True if the fax number is valid
58
+ *
59
+ * @description
60
+ * Validates Taiwan fax numbers according to the official 2024 telecom numbering plan.
61
+ * Fax numbers follow the same format as landline telephone numbers in Taiwan.
62
+ *
63
+ * Supported area codes and formats (same as landline):
64
+ * - 02: Taipei, New Taipei, Keelung - 8 digits
65
+ * - 03: Taoyuan, Hsinchu, Yilan, Hualien - 7-8 digits
66
+ * - 037: Miaoli - 6-7 digits
67
+ * - 04: Taichung, Changhua, Nantou - 7-8 digits
68
+ * - 049: Nantou - 7 digits
69
+ * - 05: Yunlin, Chiayi - 7 digits
70
+ * - 06: Tainan - 7 digits
71
+ * - 07: Kaohsiung - 7 digits
72
+ * - 08: Pingtung - 7 digits
73
+ * - 082: Kinmen - 6 digits
74
+ * - 0836: Matsu - 5 digits
75
+ * - 089: Taitung - 6 digits
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * validateTaiwanFax("0223456789") // true (Taipei area)
80
+ * validateTaiwanFax("0423288882") // true (Taichung area, 8 digits)
81
+ * validateTaiwanFax("037234567") // true (Miaoli area)
82
+ * validateTaiwanFax("02-2345-6789") // true (with separators)
83
+ * ```
84
+ */
85
+ declare const validateTaiwanFax: (value: string) => boolean;
86
+ /**
87
+ * Creates a Zod schema for Taiwan fax number validation
88
+ *
89
+ * @template IsRequired - Whether the field is required (affects return type)
90
+ * @param {IsRequired} [required=false] - Whether the field is required
91
+ * @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
92
+ * @returns {TwFaxSchema<IsRequired>} Zod schema for fax number validation
93
+ *
94
+ * @description
95
+ * Creates a comprehensive Taiwan fax number validator with support for all Taiwan
96
+ * area codes. Fax numbers follow the same format as landline telephone numbers.
97
+ *
98
+ * Features:
99
+ * - Complete Taiwan area code support (same as landline)
100
+ * - Automatic separator handling (hyphens and spaces)
101
+ * - Area-specific number length and pattern validation
102
+ * - Whitelist functionality for specific allowed numbers
103
+ * - Automatic trimming and preprocessing
104
+ * - Custom transformation functions
105
+ * - Comprehensive internationalization
106
+ * - Optional field support
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * // Basic fax number validation
111
+ * const basicSchema = twFax() // optional by default
112
+ * basicSchema.parse("0223456789") // ✓ Valid (Taipei)
113
+ * basicSchema.parse(null) // ✓ Valid (optional)
114
+ *
115
+ * // Required validation
116
+ * const requiredSchema = parse("0223456789") // ✓ Valid (Taipei)
117
+ (true)
118
+ * requiredSchema.parse(null) // ✗ Invalid (required)
119
+ *
120
+ * basicSchema.parse("0312345678") // ✓ Valid (Taoyuan)
121
+ * basicSchema.parse("02-2345-6789") // ✓ Valid (with separators)
122
+ * basicSchema.parse("0812345678") // ✗ Invalid (wrong format for 08)
123
+ *
124
+ * // With whitelist (only specific numbers allowed)
125
+ * const whitelistSchema = twFax(false, {
126
+ * whitelist: ["0223456789", "0312345678"]
127
+ * })
128
+ * whitelistSchema.parse("0223456789") // ✓ Valid (in whitelist)
129
+ * whitelistSchema.parse("0287654321") // ✗ Invalid (not in whitelist)
130
+ *
131
+ * // Optional fax number
132
+ * const optionalSchema = twFax(false)
133
+ * optionalSchema.parse("") // ✓ Valid (returns null)
134
+ * optionalSchema.parse("0223456789") // ✓ Valid
135
+ *
136
+ * // With custom transformation
137
+ * const transformSchema = twFax(false, {
138
+ * transform: (value) => value.replace(/[^0-9]/g, '') // Keep only digits
139
+ * })
140
+ * transformSchema.parse("02-2345-6789") // ✓ Valid (separators removed)
141
+ *
142
+ * // With custom error messages
143
+ * const customSchema = twFax(false, {
144
+ * i18n: {
145
+ * en: { invalid: "Please enter a valid Taiwan fax number" },
146
+ * 'zh-TW': { invalid: "請輸入有效的台灣傳真號碼" }
147
+ * }
148
+ * })
149
+ * ```
150
+ *
151
+ * @throws {z.ZodError} When validation fails with specific error messages
152
+ * @see {@link TwFaxOptions} for all available configuration options
153
+ * @see {@link validateTaiwanFax} for validation logic details
154
+ */
155
+ declare function twFax<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwFaxOptions<IsRequired>, 'required'>): TwFaxSchema<IsRequired>;
156
+
157
+ export { type TwFaxMessages, type TwFaxOptions, type TwFaxSchema, twFax, validateTaiwanFax };