@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,181 @@
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/email.ts
7
+ var _zod = require('zod');
8
+ function email(required, options) {
9
+ const {
10
+ domain,
11
+ domainBlacklist,
12
+ minLength,
13
+ maxLength,
14
+ includes,
15
+ excludes,
16
+ allowSubdomains = true,
17
+ businessOnly = false,
18
+ noDisposable = false,
19
+ lowercase = true,
20
+ transform,
21
+ defaultValue,
22
+ i18n
23
+ } = _nullishCoalesce(options, () => ( {}));
24
+ const isRequired = _nullishCoalesce(required, () => ( false));
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, `common.email.${key}`, params);
35
+ };
36
+ const disposableDomains = ["10minutemail.com", "tempmail.org", "guerrillamail.com", "mailinator.com", "yopmail.com", "temp-mail.org", "throwaway.email", "getnada.com", "maildrop.cc"];
37
+ const freeEmailDomains = ["gmail.com", "yahoo.com", "hotmail.com", "outlook.com", "icloud.com", "aol.com", "protonmail.com", "zoho.com"];
38
+ const actualDefaultValue = _nullishCoalesce(defaultValue, () => ( null));
39
+ const baseSchema = _zod.z.preprocess(
40
+ (val) => {
41
+ if (val === "" || val === null || val === void 0) {
42
+ return actualDefaultValue;
43
+ }
44
+ let processed = String(val).trim();
45
+ if (lowercase) {
46
+ processed = processed.toLowerCase();
47
+ }
48
+ if (transform) {
49
+ processed = transform(processed);
50
+ }
51
+ return processed;
52
+ },
53
+ _zod.z.union([_zod.z.string().email(), _zod.z.null()])
54
+ );
55
+ const schema = baseSchema.superRefine((val, ctx) => {
56
+ if (isRequired && val === null) {
57
+ ctx.addIssue({
58
+ code: "custom",
59
+ message: getMessage("required")
60
+ });
61
+ return;
62
+ }
63
+ if (val === null) return;
64
+ if (typeof val !== "string") {
65
+ ctx.addIssue({
66
+ code: "custom",
67
+ message: getMessage("invalid")
68
+ });
69
+ return;
70
+ }
71
+ if (minLength !== void 0 && val.length < minLength) {
72
+ ctx.addIssue({
73
+ code: "custom",
74
+ message: getMessage("minLength", { minLength })
75
+ });
76
+ return;
77
+ }
78
+ if (maxLength !== void 0 && val.length > maxLength) {
79
+ ctx.addIssue({
80
+ code: "custom",
81
+ message: getMessage("maxLength", { maxLength })
82
+ });
83
+ return;
84
+ }
85
+ if (includes !== void 0 && !val.includes(includes)) {
86
+ ctx.addIssue({
87
+ code: "custom",
88
+ message: getMessage("includes", { includes })
89
+ });
90
+ return;
91
+ }
92
+ if (excludes !== void 0) {
93
+ const excludeList = Array.isArray(excludes) ? excludes : [excludes];
94
+ for (const exclude of excludeList) {
95
+ if (val.includes(exclude)) {
96
+ ctx.addIssue({
97
+ code: "custom",
98
+ message: getMessage("includes", { includes: exclude })
99
+ });
100
+ return;
101
+ }
102
+ }
103
+ }
104
+ const emailDomain = _optionalChain([val, 'access', _3 => _3.split, 'call', _4 => _4("@"), 'access', _5 => _5[1], 'optionalAccess', _6 => _6.toLowerCase, 'call', _7 => _7()]);
105
+ if (!emailDomain) {
106
+ ctx.addIssue({
107
+ code: "custom",
108
+ message: getMessage("invalid")
109
+ });
110
+ return;
111
+ }
112
+ if (businessOnly) {
113
+ const isFreeProvider = freeEmailDomains.some((freeDomain) => {
114
+ if (allowSubdomains) {
115
+ return emailDomain === freeDomain || emailDomain.endsWith("." + freeDomain);
116
+ }
117
+ return emailDomain === freeDomain;
118
+ });
119
+ if (isFreeProvider) {
120
+ ctx.addIssue({
121
+ code: "custom",
122
+ message: getMessage("businessOnly")
123
+ });
124
+ return;
125
+ }
126
+ }
127
+ if (domainBlacklist && domainBlacklist.length > 0) {
128
+ const isBlacklisted = domainBlacklist.some((blacklistedDomain) => {
129
+ const lowerDomain = blacklistedDomain.toLowerCase();
130
+ if (allowSubdomains) {
131
+ return emailDomain === lowerDomain || emailDomain.endsWith("." + lowerDomain);
132
+ }
133
+ return emailDomain === lowerDomain;
134
+ });
135
+ if (isBlacklisted) {
136
+ ctx.addIssue({
137
+ code: "custom",
138
+ message: getMessage("domainBlacklist", { domain: emailDomain })
139
+ });
140
+ return;
141
+ }
142
+ }
143
+ if (domain !== void 0) {
144
+ const allowedDomains = Array.isArray(domain) ? domain : [domain];
145
+ const isAllowed = allowedDomains.some((allowedDomain) => {
146
+ const lowerDomain = allowedDomain.toLowerCase();
147
+ if (allowSubdomains) {
148
+ return emailDomain === lowerDomain || emailDomain.endsWith("." + lowerDomain);
149
+ }
150
+ return emailDomain === lowerDomain;
151
+ });
152
+ if (!isAllowed) {
153
+ ctx.addIssue({
154
+ code: "custom",
155
+ message: getMessage("domain", { domain: Array.isArray(domain) ? domain.join(", ") : domain })
156
+ });
157
+ return;
158
+ }
159
+ }
160
+ if (noDisposable) {
161
+ const isDisposable = disposableDomains.some((disposableDomain) => {
162
+ if (allowSubdomains) {
163
+ return emailDomain === disposableDomain || emailDomain.endsWith("." + disposableDomain);
164
+ }
165
+ return emailDomain === disposableDomain;
166
+ });
167
+ if (isDisposable) {
168
+ ctx.addIssue({
169
+ code: "custom",
170
+ message: getMessage("noDisposable")
171
+ });
172
+ return;
173
+ }
174
+ }
175
+ });
176
+ return schema;
177
+ }
178
+
179
+
180
+
181
+ exports.email = email;
@@ -0,0 +1,177 @@
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/file.ts
7
+ var _zod = require('zod');
8
+ function file(required, options) {
9
+ const {
10
+ maxSize,
11
+ minSize,
12
+ type,
13
+ typeBlacklist,
14
+ extension,
15
+ extensionBlacklist,
16
+ namePattern,
17
+ nameBlacklist,
18
+ imageOnly = false,
19
+ documentOnly = false,
20
+ videoOnly = false,
21
+ audioOnly = false,
22
+ archiveOnly = false,
23
+ caseSensitive = false,
24
+ transform,
25
+ defaultValue,
26
+ i18n
27
+ } = _nullishCoalesce(options, () => ( {}));
28
+ const isRequired = _nullishCoalesce(required, () => ( false));
29
+ const getMessage = (key, params) => {
30
+ if (i18n) {
31
+ const currentLocale = _chunkUCOXAZJFcjs.getLocale.call(void 0, );
32
+ const customMessages = i18n[currentLocale];
33
+ if (customMessages && customMessages[key]) {
34
+ const template = customMessages[key];
35
+ return template.replace(/\$\{(\w+)}/g, (_, k) => _nullishCoalesce(_optionalChain([params, 'optionalAccess', _2 => _2[k]]), () => ( "")));
36
+ }
37
+ }
38
+ return _chunkUCOXAZJFcjs.t.call(void 0, `common.file.${key}`, params);
39
+ };
40
+ const imageTypes = ["image/jpeg", "image/jpg", "image/png", "image/gif", "image/webp", "image/svg+xml", "image/bmp", "image/tiff"];
41
+ const documentTypes = [
42
+ "application/pdf",
43
+ "application/msword",
44
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
45
+ "application/vnd.ms-excel",
46
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
47
+ "application/vnd.ms-powerpoint",
48
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation",
49
+ "text/plain",
50
+ "text/csv"
51
+ ];
52
+ const videoTypes = ["video/mp4", "video/mpeg", "video/quicktime", "video/x-msvideo", "video/x-ms-wmv", "video/webm", "video/ogg"];
53
+ const audioTypes = ["audio/mpeg", "audio/wav", "audio/ogg", "audio/aac", "audio/webm", "audio/mp3", "audio/x-wav"];
54
+ const archiveTypes = ["application/zip", "application/x-rar-compressed", "application/x-7z-compressed", "application/x-tar", "application/gzip"];
55
+ const actualDefaultValue = _nullishCoalesce(defaultValue, () => ( null));
56
+ const fileOrNullSchema = _zod.z.union([_zod.z.instanceof(File), _zod.z.null()]);
57
+ const baseSchema = _zod.z.preprocess((val) => {
58
+ if (val === "" || val === null || val === void 0) {
59
+ return actualDefaultValue;
60
+ }
61
+ if (!(val instanceof File)) {
62
+ return val;
63
+ }
64
+ let processed = val;
65
+ if (transform) {
66
+ processed = transform(processed);
67
+ }
68
+ return processed;
69
+ }, fileOrNullSchema);
70
+ const schema = baseSchema.refine((val) => !isRequired || val !== null, {
71
+ message: getMessage("required")
72
+ }).refine((val) => val === null || val instanceof File, {
73
+ message: getMessage("invalid")
74
+ }).refine((val) => val === null || minSize === void 0 || val.size >= minSize, {
75
+ message: getMessage("minSize", { minSize: formatFileSize(minSize || 0) })
76
+ }).refine((val) => val === null || maxSize === void 0 || val.size <= maxSize, {
77
+ message: getMessage("maxSize", { maxSize: formatFileSize(maxSize || 0) })
78
+ }).refine((val) => val === null || !imageOnly || imageTypes.includes(val.type), {
79
+ message: getMessage("imageOnly")
80
+ }).refine((val) => val === null || !documentOnly || documentTypes.includes(val.type), {
81
+ message: getMessage("documentOnly")
82
+ }).refine((val) => val === null || !videoOnly || videoTypes.includes(val.type), {
83
+ message: getMessage("videoOnly")
84
+ }).refine((val) => val === null || !audioOnly || audioTypes.includes(val.type), {
85
+ message: getMessage("audioOnly")
86
+ }).refine((val) => val === null || !archiveOnly || archiveTypes.includes(val.type), {
87
+ message: getMessage("archiveOnly")
88
+ }).refine(
89
+ (val) => {
90
+ if (val === null || !typeBlacklist || typeBlacklist.length === 0) return true;
91
+ return !typeBlacklist.includes(val.type);
92
+ },
93
+ {
94
+ message: getMessage("type", { type: _optionalChain([typeBlacklist, 'optionalAccess', _3 => _3.join, 'call', _4 => _4(", ")]) || "" })
95
+ }
96
+ ).refine(
97
+ (val) => {
98
+ if (val === null || type === void 0) return true;
99
+ const allowedTypes = Array.isArray(type) ? type : [type];
100
+ return allowedTypes.includes(val.type);
101
+ },
102
+ {
103
+ message: getMessage("type", { type: Array.isArray(type) ? type.join(", ") : type || "" })
104
+ }
105
+ ).refine(
106
+ (val) => {
107
+ if (val === null || extensionBlacklist === void 0 || extensionBlacklist.length === 0) return true;
108
+ const fileExtension = getFileExtension(val.name, caseSensitive);
109
+ const normalizedBlacklist = extensionBlacklist.map((ext) => normalizeExtension(ext, caseSensitive));
110
+ return !normalizedBlacklist.includes(fileExtension);
111
+ },
112
+ {
113
+ message: getMessage("extensionBlacklist", { extension: _optionalChain([extensionBlacklist, 'optionalAccess', _5 => _5.join, 'call', _6 => _6(", ")]) || "" })
114
+ }
115
+ ).refine(
116
+ (val) => {
117
+ if (val === null || extension === void 0) return true;
118
+ const fileName = val.name;
119
+ const fileExtension = getFileExtension(fileName, caseSensitive);
120
+ const allowedExtensions = Array.isArray(extension) ? extension : [extension];
121
+ const normalizedExtensions = allowedExtensions.map((ext) => normalizeExtension(ext, caseSensitive));
122
+ return normalizedExtensions.includes(fileExtension);
123
+ },
124
+ {
125
+ message: getMessage("extension", { extension: Array.isArray(extension) ? extension.join(", ") : extension || "" })
126
+ }
127
+ ).refine(
128
+ (val) => {
129
+ if (val === null || namePattern === void 0) return true;
130
+ const pattern = typeof namePattern === "string" ? new RegExp(namePattern) : namePattern;
131
+ return pattern.test(val.name);
132
+ },
133
+ {
134
+ message: getMessage("name", { pattern: _optionalChain([namePattern, 'optionalAccess', _7 => _7.toString, 'call', _8 => _8()]) || "" })
135
+ }
136
+ ).refine(
137
+ (val) => {
138
+ if (val === null || nameBlacklist === void 0) return true;
139
+ const blacklistPatterns = Array.isArray(nameBlacklist) ? nameBlacklist : [nameBlacklist];
140
+ for (const blacklistPattern of blacklistPatterns) {
141
+ const pattern = typeof blacklistPattern === "string" ? new RegExp(blacklistPattern) : blacklistPattern;
142
+ if (pattern.test(val.name)) {
143
+ return false;
144
+ }
145
+ }
146
+ return true;
147
+ },
148
+ {
149
+ message: getMessage("nameBlacklist", { pattern: "" })
150
+ }
151
+ );
152
+ return schema;
153
+ }
154
+ function getFileExtension(fileName, caseSensitive) {
155
+ const lastDotIndex = fileName.lastIndexOf(".");
156
+ if (lastDotIndex === -1) return "";
157
+ const extension = fileName.substring(lastDotIndex);
158
+ return caseSensitive ? extension : extension.toLowerCase();
159
+ }
160
+ function normalizeExtension(extension, caseSensitive) {
161
+ const normalized = extension.startsWith(".") ? extension : `.${extension}`;
162
+ return caseSensitive ? normalized : normalized.toLowerCase();
163
+ }
164
+ function formatFileSize(bytes) {
165
+ const units = ["B", "KB", "MB", "GB", "TB"];
166
+ let size = bytes;
167
+ let unitIndex = 0;
168
+ while (size >= 1024 && unitIndex < units.length - 1) {
169
+ size /= 1024;
170
+ unitIndex++;
171
+ }
172
+ return `${Math.round(size * 100) / 100} ${units[unitIndex]}`;
173
+ }
174
+
175
+
176
+
177
+ exports.file = file;