@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,127 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkUCOXAZJFcjs = require('./chunk-UCOXAZJF.cjs');
|
|
5
|
+
|
|
6
|
+
// src/validators/taiwan/fax.ts
|
|
7
|
+
var _zod = require('zod');
|
|
8
|
+
var validateTaiwanFax = (value) => {
|
|
9
|
+
const cleanValue = value.replace(/[-\s]/g, "");
|
|
10
|
+
if (!/^0\d{7,10}$/.test(cleanValue)) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
const areaCode4 = cleanValue.substring(0, 4);
|
|
14
|
+
if (areaCode4 === "0836") {
|
|
15
|
+
return cleanValue.length === 9 && /^0836\d{5}$/.test(cleanValue);
|
|
16
|
+
}
|
|
17
|
+
const areaCode3 = cleanValue.substring(0, 3);
|
|
18
|
+
if (areaCode3 === "037") {
|
|
19
|
+
const firstDigit = cleanValue[3];
|
|
20
|
+
if (firstDigit === "0" || firstDigit === "1") {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^037[2-9]\d{5,6}$/.test(cleanValue);
|
|
24
|
+
}
|
|
25
|
+
if (areaCode3 === "049") {
|
|
26
|
+
return cleanValue.length === 10 && /^049\d{7}$/.test(cleanValue);
|
|
27
|
+
}
|
|
28
|
+
if (areaCode3 === "082") {
|
|
29
|
+
return cleanValue.length === 9 && /^082\d{6}$/.test(cleanValue);
|
|
30
|
+
}
|
|
31
|
+
if (areaCode3 === "089") {
|
|
32
|
+
return cleanValue.length === 9 && /^089\d{6}$/.test(cleanValue);
|
|
33
|
+
}
|
|
34
|
+
const areaCode2 = cleanValue.substring(0, 2);
|
|
35
|
+
if (areaCode2 === "02") {
|
|
36
|
+
const firstDigit = cleanValue[2];
|
|
37
|
+
if (firstDigit === "0" || firstDigit === "1") {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
return cleanValue.length === 10 && /^02[2-9]\d{7}$/.test(cleanValue);
|
|
41
|
+
}
|
|
42
|
+
if (areaCode2 === "03") {
|
|
43
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^03\d{7,8}$/.test(cleanValue);
|
|
44
|
+
}
|
|
45
|
+
if (areaCode2 === "04") {
|
|
46
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^04\d{7,8}$/.test(cleanValue);
|
|
47
|
+
}
|
|
48
|
+
if (areaCode2 === "05") {
|
|
49
|
+
return cleanValue.length === 9 && /^05\d{7}$/.test(cleanValue);
|
|
50
|
+
}
|
|
51
|
+
if (areaCode2 === "06") {
|
|
52
|
+
return cleanValue.length === 9 && /^06\d{7}$/.test(cleanValue);
|
|
53
|
+
}
|
|
54
|
+
if (areaCode2 === "07") {
|
|
55
|
+
const firstDigit = cleanValue[2];
|
|
56
|
+
if (firstDigit === "0" || firstDigit === "1") {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
return cleanValue.length === 9 && /^07[2-9]\d{6}$/.test(cleanValue);
|
|
60
|
+
}
|
|
61
|
+
if (areaCode2 === "08") {
|
|
62
|
+
const firstDigit = cleanValue[2];
|
|
63
|
+
if (firstDigit !== "4" && firstDigit !== "7" && firstDigit !== "8") {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
return cleanValue.length === 9 && /^08[478]\d{6}$/.test(cleanValue);
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
};
|
|
70
|
+
function twFax(required, options) {
|
|
71
|
+
const { whitelist, transform, defaultValue, i18n } = _nullishCoalesce(options, () => ( {}));
|
|
72
|
+
const isRequired = _nullishCoalesce(required, () => ( false));
|
|
73
|
+
const actualDefaultValue = _nullishCoalesce(defaultValue, () => ( (isRequired ? "" : null)));
|
|
74
|
+
const getMessage = (key, params) => {
|
|
75
|
+
if (i18n) {
|
|
76
|
+
const currentLocale = _chunkUCOXAZJFcjs.getLocale.call(void 0, );
|
|
77
|
+
const customMessages = i18n[currentLocale];
|
|
78
|
+
if (customMessages && customMessages[key]) {
|
|
79
|
+
const template = customMessages[key];
|
|
80
|
+
return template.replace(/\$\{(\w+)}/g, (_, k) => _nullishCoalesce(_optionalChain([params, 'optionalAccess', _2 => _2[k]]), () => ( "")));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return _chunkUCOXAZJFcjs.t.call(void 0, `taiwan.fax.${key}`, params);
|
|
84
|
+
};
|
|
85
|
+
const preprocessFn = (val) => {
|
|
86
|
+
if (val === null || val === void 0) {
|
|
87
|
+
return actualDefaultValue;
|
|
88
|
+
}
|
|
89
|
+
let processed = String(val).trim();
|
|
90
|
+
if (processed === "") {
|
|
91
|
+
if (whitelist && whitelist.includes("")) {
|
|
92
|
+
return "";
|
|
93
|
+
}
|
|
94
|
+
if (!isRequired) {
|
|
95
|
+
return actualDefaultValue;
|
|
96
|
+
}
|
|
97
|
+
return actualDefaultValue;
|
|
98
|
+
}
|
|
99
|
+
if (transform) {
|
|
100
|
+
processed = transform(processed);
|
|
101
|
+
}
|
|
102
|
+
return processed;
|
|
103
|
+
};
|
|
104
|
+
const baseSchema = isRequired ? _zod.z.preprocess(preprocessFn, _zod.z.string()) : _zod.z.preprocess(preprocessFn, _zod.z.string().nullable());
|
|
105
|
+
const schema = baseSchema.superRefine((val, ctx) => {
|
|
106
|
+
if (val === null) return;
|
|
107
|
+
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
108
|
+
ctx.addIssue({ code: "custom", message: getMessage("required") });
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (val === null) return;
|
|
112
|
+
if (!isRequired && val === "") return;
|
|
113
|
+
if (whitelist && whitelist.length > 0 && whitelist.includes(val)) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (!validateTaiwanFax(val)) {
|
|
117
|
+
ctx.addIssue({ code: "custom", message: getMessage("invalid") });
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
return schema;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
exports.validateTaiwanFax = validateTaiwanFax; exports.twFax = twFax;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getLocale,
|
|
3
|
+
t
|
|
4
|
+
} from "./chunk-6AAP4LPF.js";
|
|
5
|
+
|
|
6
|
+
// src/validators/common/credit-card.ts
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
function detectCardType(value) {
|
|
9
|
+
const digits = value.replace(/[\s-]/g, "");
|
|
10
|
+
if (/^4/.test(digits)) return "visa";
|
|
11
|
+
if (/^5[1-5]/.test(digits) || /^2[2-7]/.test(digits)) return "mastercard";
|
|
12
|
+
if (/^3[47]/.test(digits)) return "amex";
|
|
13
|
+
if (/^35/.test(digits)) return "jcb";
|
|
14
|
+
if (/^6011/.test(digits) || /^65/.test(digits) || /^64[4-9]/.test(digits)) return "discover";
|
|
15
|
+
if (/^62/.test(digits)) return "unionpay";
|
|
16
|
+
return "any";
|
|
17
|
+
}
|
|
18
|
+
function validateCreditCard(value) {
|
|
19
|
+
const digits = value.replace(/[\s-]/g, "");
|
|
20
|
+
if (!/^\d{13,19}$/.test(digits)) return false;
|
|
21
|
+
let sum = 0;
|
|
22
|
+
let alternate = false;
|
|
23
|
+
for (let i = digits.length - 1; i >= 0; i--) {
|
|
24
|
+
let n = parseInt(digits[i], 10);
|
|
25
|
+
if (alternate) {
|
|
26
|
+
n *= 2;
|
|
27
|
+
if (n > 9) n -= 9;
|
|
28
|
+
}
|
|
29
|
+
sum += n;
|
|
30
|
+
alternate = !alternate;
|
|
31
|
+
}
|
|
32
|
+
return sum % 10 === 0;
|
|
33
|
+
}
|
|
34
|
+
function creditCard(required, options) {
|
|
35
|
+
const { cardType, whitelist, transform, defaultValue, i18n } = options ?? {};
|
|
36
|
+
const isRequired = required ?? false;
|
|
37
|
+
const actualDefaultValue = defaultValue ?? (isRequired ? "" : null);
|
|
38
|
+
const getMessage = (key, params) => {
|
|
39
|
+
if (i18n) {
|
|
40
|
+
const currentLocale = getLocale();
|
|
41
|
+
const customMessages = i18n[currentLocale];
|
|
42
|
+
if (customMessages && customMessages[key]) {
|
|
43
|
+
const template = customMessages[key];
|
|
44
|
+
return template.replace(/\$\{(\w+)}/g, (_, k) => params?.[k] ?? "");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return t(`common.creditCard.${key}`, params);
|
|
48
|
+
};
|
|
49
|
+
const preprocessFn = (val) => {
|
|
50
|
+
if (val === "" || val === null || val === void 0) {
|
|
51
|
+
return actualDefaultValue;
|
|
52
|
+
}
|
|
53
|
+
let processed = String(val).trim().replace(/[\s-]/g, "");
|
|
54
|
+
if (processed === "" && !required) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
if (transform) {
|
|
58
|
+
processed = transform(processed);
|
|
59
|
+
}
|
|
60
|
+
return processed;
|
|
61
|
+
};
|
|
62
|
+
const baseSchema = isRequired ? z.preprocess(preprocessFn, z.string()) : z.preprocess(preprocessFn, z.string().nullable());
|
|
63
|
+
const schema = baseSchema.superRefine((val, ctx) => {
|
|
64
|
+
if (val === null) return;
|
|
65
|
+
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
66
|
+
ctx.addIssue({ code: "custom", message: getMessage("required") });
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (!isRequired && val === "") return;
|
|
70
|
+
if (!validateCreditCard(val)) {
|
|
71
|
+
ctx.addIssue({ code: "custom", message: getMessage("invalid") });
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (cardType) {
|
|
75
|
+
const allowedTypes = Array.isArray(cardType) ? cardType : [cardType];
|
|
76
|
+
if (!allowedTypes.includes("any")) {
|
|
77
|
+
const detected = detectCardType(val);
|
|
78
|
+
if (!allowedTypes.includes(detected)) {
|
|
79
|
+
ctx.addIssue({ code: "custom", message: getMessage("invalid") });
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (whitelist && whitelist.length > 0) {
|
|
85
|
+
const normalized = whitelist.map((w) => w.replace(/[\s-]/g, ""));
|
|
86
|
+
if (!normalized.includes(val)) {
|
|
87
|
+
ctx.addIssue({ code: "custom", message: getMessage("notInWhitelist") });
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
return schema;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export {
|
|
96
|
+
detectCardType,
|
|
97
|
+
validateCreditCard,
|
|
98
|
+
creditCard
|
|
99
|
+
};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkUCOXAZJFcjs = require('./chunk-UCOXAZJF.cjs');
|
|
5
|
+
|
|
6
|
+
// src/validators/common/password.ts
|
|
7
|
+
var _zod = require('zod');
|
|
8
|
+
var COMMON_PASSWORDS = [
|
|
9
|
+
"password",
|
|
10
|
+
"123456",
|
|
11
|
+
"123456789",
|
|
12
|
+
"12345678",
|
|
13
|
+
"12345",
|
|
14
|
+
"1234567",
|
|
15
|
+
"admin",
|
|
16
|
+
"qwerty",
|
|
17
|
+
"abc123",
|
|
18
|
+
"password123",
|
|
19
|
+
"letmein",
|
|
20
|
+
"welcome",
|
|
21
|
+
"monkey",
|
|
22
|
+
"dragon",
|
|
23
|
+
"sunshine",
|
|
24
|
+
"princess"
|
|
25
|
+
];
|
|
26
|
+
var calculatePasswordStrength = (password2) => {
|
|
27
|
+
let score = 0;
|
|
28
|
+
if (password2.length >= 8) score += 1;
|
|
29
|
+
if (password2.length >= 12) score += 1;
|
|
30
|
+
if (password2.length >= 16) score += 1;
|
|
31
|
+
if (/[a-z]/.test(password2)) score += 1;
|
|
32
|
+
if (/[A-Z]/.test(password2)) score += 1;
|
|
33
|
+
if (/[0-9]/.test(password2)) score += 1;
|
|
34
|
+
if (/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/.test(password2)) score += 1;
|
|
35
|
+
if (/(.)\1{2,}/.test(password2)) score -= 1;
|
|
36
|
+
if (/(?:abc|bcd|cde|def|efg|fgh|ghi|hij|ijk|jkl|klm|lmn|mno|nop|opq|pqr|qrs|rst|stu|tuv|uvw|vwx|wxy|xyz|012|123|234|345|456|567|678|789)/i.test(password2)) score -= 1;
|
|
37
|
+
if (score <= 2) return "weak";
|
|
38
|
+
if (score <= 4) return "medium";
|
|
39
|
+
if (score <= 6) return "strong";
|
|
40
|
+
return "very-strong";
|
|
41
|
+
};
|
|
42
|
+
function password(required, options) {
|
|
43
|
+
const {
|
|
44
|
+
min,
|
|
45
|
+
max,
|
|
46
|
+
uppercase,
|
|
47
|
+
lowercase,
|
|
48
|
+
digits,
|
|
49
|
+
special,
|
|
50
|
+
noRepeating,
|
|
51
|
+
noSequential,
|
|
52
|
+
noCommonWords,
|
|
53
|
+
minStrength,
|
|
54
|
+
excludes,
|
|
55
|
+
includes,
|
|
56
|
+
regex,
|
|
57
|
+
transform,
|
|
58
|
+
defaultValue,
|
|
59
|
+
i18n
|
|
60
|
+
} = _nullishCoalesce(options, () => ( {}));
|
|
61
|
+
const isRequired = _nullishCoalesce(required, () => ( false));
|
|
62
|
+
const actualDefaultValue = _nullishCoalesce(defaultValue, () => ( (isRequired ? "" : null)));
|
|
63
|
+
const getMessage = (key, params) => {
|
|
64
|
+
if (i18n) {
|
|
65
|
+
const currentLocale = _chunkUCOXAZJFcjs.getLocale.call(void 0, );
|
|
66
|
+
const customMessages = i18n[currentLocale];
|
|
67
|
+
if (customMessages && customMessages[key]) {
|
|
68
|
+
const template = customMessages[key];
|
|
69
|
+
return template.replace(/\$\{(\w+)}/g, (_, k) => _nullishCoalesce(_optionalChain([params, 'optionalAccess', _2 => _2[k]]), () => ( "")));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return _chunkUCOXAZJFcjs.t.call(void 0, `common.password.${key}`, params);
|
|
73
|
+
};
|
|
74
|
+
const preprocessFn = (val) => {
|
|
75
|
+
if (val === "" || val === null || val === void 0) {
|
|
76
|
+
return actualDefaultValue;
|
|
77
|
+
}
|
|
78
|
+
let processed = String(val);
|
|
79
|
+
if (transform) {
|
|
80
|
+
processed = transform(processed);
|
|
81
|
+
}
|
|
82
|
+
return processed;
|
|
83
|
+
};
|
|
84
|
+
const baseSchema = isRequired ? _zod.z.preprocess(preprocessFn, _zod.z.string()) : _zod.z.preprocess(preprocessFn, _zod.z.string().nullable());
|
|
85
|
+
const schema = baseSchema.superRefine((val, ctx) => {
|
|
86
|
+
if (val === null) return;
|
|
87
|
+
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
88
|
+
ctx.addIssue({ code: "custom", message: getMessage("required") });
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (val !== null && min !== void 0 && val.length < min) {
|
|
92
|
+
ctx.addIssue({ code: "custom", message: getMessage("min", { min }) });
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (val !== null && max !== void 0 && val.length > max) {
|
|
96
|
+
ctx.addIssue({ code: "custom", message: getMessage("max", { max }) });
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (val !== null && uppercase && !/[A-Z]/.test(val)) {
|
|
100
|
+
ctx.addIssue({ code: "custom", message: getMessage("uppercase") });
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (val !== null && lowercase && !/[a-z]/.test(val)) {
|
|
104
|
+
ctx.addIssue({ code: "custom", message: getMessage("lowercase") });
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (val !== null && digits && !/[0-9]/.test(val)) {
|
|
108
|
+
ctx.addIssue({ code: "custom", message: getMessage("digits") });
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (val !== null && special && !/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/.test(val)) {
|
|
112
|
+
ctx.addIssue({ code: "custom", message: getMessage("special") });
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (val !== null && noRepeating && /(.)\1{2,}/.test(val)) {
|
|
116
|
+
ctx.addIssue({ code: "custom", message: getMessage("noRepeating") });
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (val !== null && noSequential && /(?:abc|bcd|cde|def|efg|fgh|ghi|hij|ijk|jkl|klm|lmn|mno|nop|opq|pqr|qrs|rst|stu|tuv|uvw|vwx|wxy|xyz|012|123|234|345|456|567|678|789)/i.test(val)) {
|
|
120
|
+
ctx.addIssue({ code: "custom", message: getMessage("noSequential") });
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (val !== null && noCommonWords && COMMON_PASSWORDS.some((common) => val.toLowerCase().includes(common.toLowerCase()))) {
|
|
124
|
+
ctx.addIssue({ code: "custom", message: getMessage("noCommonWords") });
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (val !== null && minStrength) {
|
|
128
|
+
const strength = calculatePasswordStrength(val);
|
|
129
|
+
const strengthLevels = ["weak", "medium", "strong", "very-strong"];
|
|
130
|
+
const currentLevel = strengthLevels.indexOf(strength);
|
|
131
|
+
const requiredLevel = strengthLevels.indexOf(minStrength);
|
|
132
|
+
if (currentLevel < requiredLevel) {
|
|
133
|
+
ctx.addIssue({ code: "custom", message: getMessage("minStrength", { minStrength }) });
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (val !== null && includes !== void 0 && !val.includes(includes)) {
|
|
138
|
+
ctx.addIssue({ code: "custom", message: getMessage("includes", { includes }) });
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (val !== null && excludes !== void 0) {
|
|
142
|
+
const excludeList = Array.isArray(excludes) ? excludes : [excludes];
|
|
143
|
+
for (const exclude of excludeList) {
|
|
144
|
+
if (val.includes(exclude)) {
|
|
145
|
+
ctx.addIssue({ code: "custom", message: getMessage("excludes", { excludes: exclude }) });
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (val !== null && regex !== void 0 && !regex.test(val)) {
|
|
151
|
+
ctx.addIssue({ code: "custom", message: getMessage("invalid", { regex }) });
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
return schema;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
exports.password = password;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkUCOXAZJFcjs = require('./chunk-UCOXAZJF.cjs');
|
|
5
|
+
|
|
6
|
+
// src/validators/taiwan/passport.ts
|
|
7
|
+
var _zod = require('zod');
|
|
8
|
+
var PASSPORT_TYPE_DIGIT = {
|
|
9
|
+
diplomatic: "0",
|
|
10
|
+
official: "1",
|
|
11
|
+
ordinary: "2",
|
|
12
|
+
travel: "3"
|
|
13
|
+
};
|
|
14
|
+
var validateTaiwanPassport = (value) => {
|
|
15
|
+
if (!/^\d{9}$/.test(value)) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
const firstDigit = parseInt(value[0], 10);
|
|
19
|
+
return firstDigit >= 0 && firstDigit <= 3;
|
|
20
|
+
};
|
|
21
|
+
function twPassport(required, options) {
|
|
22
|
+
const { passportType = "any", transform, defaultValue, i18n } = _nullishCoalesce(options, () => ( {}));
|
|
23
|
+
const isRequired = _nullishCoalesce(required, () => ( false));
|
|
24
|
+
const actualDefaultValue = _nullishCoalesce(defaultValue, () => ( (isRequired ? "" : null)));
|
|
25
|
+
const getMessage = (key, params) => {
|
|
26
|
+
if (i18n) {
|
|
27
|
+
const currentLocale = _chunkUCOXAZJFcjs.getLocale.call(void 0, );
|
|
28
|
+
const customMessages = i18n[currentLocale];
|
|
29
|
+
if (customMessages && customMessages[key]) {
|
|
30
|
+
const template = customMessages[key];
|
|
31
|
+
return template.replace(/\$\{(\w+)}/g, (_, k) => _nullishCoalesce(_optionalChain([params, 'optionalAccess', _2 => _2[k]]), () => ( "")));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return _chunkUCOXAZJFcjs.t.call(void 0, `taiwan.passport.${key}`, params);
|
|
35
|
+
};
|
|
36
|
+
const preprocessFn = (val) => {
|
|
37
|
+
if (val === "" || val === null || val === void 0) {
|
|
38
|
+
return actualDefaultValue;
|
|
39
|
+
}
|
|
40
|
+
let processed = String(val).trim();
|
|
41
|
+
if (processed === "" && !required) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
if (transform) {
|
|
45
|
+
processed = transform(processed);
|
|
46
|
+
}
|
|
47
|
+
return processed;
|
|
48
|
+
};
|
|
49
|
+
const baseSchema = isRequired ? _zod.z.preprocess(preprocessFn, _zod.z.string()) : _zod.z.preprocess(preprocessFn, _zod.z.string().nullable());
|
|
50
|
+
const schema = baseSchema.superRefine((val, ctx) => {
|
|
51
|
+
if (val === null) return;
|
|
52
|
+
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
53
|
+
ctx.addIssue({ code: "custom", message: getMessage("required") });
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (!isRequired && val === "") return;
|
|
57
|
+
if (!validateTaiwanPassport(val)) {
|
|
58
|
+
ctx.addIssue({ code: "custom", message: getMessage("invalid") });
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (passportType !== "any") {
|
|
62
|
+
const expectedDigit = PASSPORT_TYPE_DIGIT[passportType];
|
|
63
|
+
if (val[0] !== expectedDigit) {
|
|
64
|
+
ctx.addIssue({ code: "custom", message: getMessage("invalid") });
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return schema;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
exports.validateTaiwanPassport = validateTaiwanPassport; exports.twPassport = twPassport;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkUCOXAZJFcjs = require('./chunk-UCOXAZJF.cjs');
|
|
5
|
+
|
|
6
|
+
// src/validators/taiwan/national-id.ts
|
|
7
|
+
var _zod = require('zod');
|
|
8
|
+
var CITY_CODES = {
|
|
9
|
+
"A": 10,
|
|
10
|
+
"B": 11,
|
|
11
|
+
"C": 12,
|
|
12
|
+
"D": 13,
|
|
13
|
+
"E": 14,
|
|
14
|
+
"F": 15,
|
|
15
|
+
"G": 16,
|
|
16
|
+
"H": 17,
|
|
17
|
+
"I": 34,
|
|
18
|
+
"J": 18,
|
|
19
|
+
"K": 19,
|
|
20
|
+
"L": 20,
|
|
21
|
+
"M": 21,
|
|
22
|
+
"N": 22,
|
|
23
|
+
"O": 35,
|
|
24
|
+
"P": 23,
|
|
25
|
+
"Q": 24,
|
|
26
|
+
"R": 25,
|
|
27
|
+
"S": 26,
|
|
28
|
+
"T": 27,
|
|
29
|
+
"U": 28,
|
|
30
|
+
"V": 29,
|
|
31
|
+
"W": 32,
|
|
32
|
+
"X": 30,
|
|
33
|
+
"Y": 31,
|
|
34
|
+
"Z": 33
|
|
35
|
+
};
|
|
36
|
+
var validateCitizenId = (value) => {
|
|
37
|
+
if (!/^[A-Z][1-2]\d{8}$/.test(value)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const letter = value[0];
|
|
41
|
+
const digits = value.slice(1).split("").map(Number);
|
|
42
|
+
const cityCode = CITY_CODES[letter];
|
|
43
|
+
if (!cityCode) return false;
|
|
44
|
+
const cityDigits = [Math.floor(cityCode / 10), cityCode % 10];
|
|
45
|
+
const coefficients = [1, 9, 8, 7, 6, 5, 4, 3, 2, 1];
|
|
46
|
+
let sum = cityDigits[0] * coefficients[0] + cityDigits[1] * coefficients[1];
|
|
47
|
+
for (let i = 0; i < 8; i++) {
|
|
48
|
+
sum += digits[i] * coefficients[i + 2];
|
|
49
|
+
}
|
|
50
|
+
const checksum = (10 - sum % 10) % 10;
|
|
51
|
+
return checksum === digits[8];
|
|
52
|
+
};
|
|
53
|
+
var validateOldResidentId = (value) => {
|
|
54
|
+
if (!/^[A-Z][ABCD]\d{8}$/.test(value)) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
const letter = value[0];
|
|
58
|
+
const genderCode = value[1];
|
|
59
|
+
const digits = value.slice(2).split("").map(Number);
|
|
60
|
+
const cityCode = CITY_CODES[letter];
|
|
61
|
+
if (!cityCode) return false;
|
|
62
|
+
const genderValue = genderCode === "A" || genderCode === "C" ? 1 : 0;
|
|
63
|
+
const cityDigits = [Math.floor(cityCode / 10), cityCode % 10];
|
|
64
|
+
const coefficients = [1, 9, 8, 7, 6, 5, 4, 3, 2, 1];
|
|
65
|
+
let sum = cityDigits[0] * coefficients[0] + cityDigits[1] * coefficients[1] + genderValue * coefficients[2];
|
|
66
|
+
for (let i = 0; i < 7; i++) {
|
|
67
|
+
sum += digits[i] * coefficients[i + 3];
|
|
68
|
+
}
|
|
69
|
+
const checksum = (10 - sum % 10) % 10;
|
|
70
|
+
return checksum === digits[7];
|
|
71
|
+
};
|
|
72
|
+
var validateNewResidentId = (value) => {
|
|
73
|
+
if (!/^[A-Z][89]\d{8}$/.test(value)) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
const letter = value[0];
|
|
77
|
+
const digits = value.slice(1).split("").map(Number);
|
|
78
|
+
const cityCode = CITY_CODES[letter];
|
|
79
|
+
if (!cityCode) return false;
|
|
80
|
+
const cityDigits = [Math.floor(cityCode / 10), cityCode % 10];
|
|
81
|
+
const coefficients = [1, 9, 8, 7, 6, 5, 4, 3, 2, 1];
|
|
82
|
+
let sum = cityDigits[0] * coefficients[0] + cityDigits[1] * coefficients[1];
|
|
83
|
+
for (let i = 0; i < 8; i++) {
|
|
84
|
+
sum += digits[i] * coefficients[i + 2];
|
|
85
|
+
}
|
|
86
|
+
const checksum = (10 - sum % 10) % 10;
|
|
87
|
+
return checksum === digits[8];
|
|
88
|
+
};
|
|
89
|
+
var validateTaiwanNationalId = (value, type = "both", allowOldResident = true) => {
|
|
90
|
+
if (!/^[A-Z].{9}$/.test(value)) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
switch (type) {
|
|
94
|
+
case "citizen":
|
|
95
|
+
return validateCitizenId(value);
|
|
96
|
+
case "resident":
|
|
97
|
+
return (allowOldResident ? validateOldResidentId(value) : false) || validateNewResidentId(value);
|
|
98
|
+
case "both":
|
|
99
|
+
return validateCitizenId(value) || (allowOldResident ? validateOldResidentId(value) : false) || validateNewResidentId(value);
|
|
100
|
+
default:
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
function twNationalId(required, options) {
|
|
105
|
+
const {
|
|
106
|
+
type = "both",
|
|
107
|
+
allowOldResident = true,
|
|
108
|
+
transform,
|
|
109
|
+
defaultValue,
|
|
110
|
+
i18n
|
|
111
|
+
} = _nullishCoalesce(options, () => ( {}));
|
|
112
|
+
const isRequired = _nullishCoalesce(required, () => ( false));
|
|
113
|
+
const actualDefaultValue = _nullishCoalesce(defaultValue, () => ( (isRequired ? "" : null)));
|
|
114
|
+
const getMessage = (key, params) => {
|
|
115
|
+
if (i18n) {
|
|
116
|
+
const currentLocale = _chunkUCOXAZJFcjs.getLocale.call(void 0, );
|
|
117
|
+
const customMessages = i18n[currentLocale];
|
|
118
|
+
if (customMessages && customMessages[key]) {
|
|
119
|
+
const template = customMessages[key];
|
|
120
|
+
return template.replace(/\$\{(\w+)}/g, (_, k) => _nullishCoalesce(_optionalChain([params, 'optionalAccess', _2 => _2[k]]), () => ( "")));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return _chunkUCOXAZJFcjs.t.call(void 0, `taiwan.nationalId.${key}`, params);
|
|
124
|
+
};
|
|
125
|
+
const preprocessFn = (val) => {
|
|
126
|
+
if (val === "" || val === null || val === void 0) {
|
|
127
|
+
return actualDefaultValue;
|
|
128
|
+
}
|
|
129
|
+
let processed = String(val).trim().toUpperCase();
|
|
130
|
+
if (processed === "" && !required) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
if (transform) {
|
|
134
|
+
processed = transform(processed);
|
|
135
|
+
}
|
|
136
|
+
return processed;
|
|
137
|
+
};
|
|
138
|
+
const baseSchema = isRequired ? _zod.z.preprocess(preprocessFn, _zod.z.string()) : _zod.z.preprocess(preprocessFn, _zod.z.string().nullable());
|
|
139
|
+
const schema = baseSchema.superRefine((val, ctx) => {
|
|
140
|
+
if (val === null) return;
|
|
141
|
+
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
142
|
+
ctx.addIssue({ code: "custom", message: getMessage("required") });
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (val === null) return;
|
|
146
|
+
if (!isRequired && val === "") return;
|
|
147
|
+
if (!validateTaiwanNationalId(val, type, allowOldResident)) {
|
|
148
|
+
ctx.addIssue({ code: "custom", message: getMessage("invalid") });
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
return schema;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
exports.validateCitizenId = validateCitizenId; exports.validateOldResidentId = validateOldResidentId; exports.validateNewResidentId = validateNewResidentId; exports.validateTaiwanNationalId = validateTaiwanNationalId; exports.twNationalId = twNationalId;
|