@oxog/vld 2.0.3 → 2.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (452) hide show
  1. package/CHANGELOG.md +120 -1
  2. package/README.md +1296 -1171
  3. package/dist/chunks/errors-core-Cqi4-9ew.js +1 -0
  4. package/dist/chunks/index-CkbfQQ4n.js +1 -0
  5. package/dist/chunks/index-yjpbvFgw.js +1 -0
  6. package/dist/chunks/ip-validation-g5LWgy9t.js +1 -0
  7. package/dist/chunks/security-Dy24T8N7.js +1 -0
  8. package/dist/cjs/chunks/errors-core-DKPohm9I.cjs +1 -0
  9. package/dist/cjs/chunks/index-BEV9nG0N.cjs +1 -0
  10. package/dist/cjs/chunks/index-ZjHAxYdA.cjs +1 -0
  11. package/dist/cjs/chunks/ip-validation-BZqPamPC.cjs +1 -0
  12. package/dist/cjs/chunks/security-aXZVI7qW.cjs +1 -0
  13. package/dist/cjs/cli/bin.cjs +2 -0
  14. package/dist/cjs/cli/index.cjs +1 -0
  15. package/dist/cjs/codecs/index.cjs +1 -0
  16. package/dist/cjs/coercion/index.cjs +1 -0
  17. package/dist/cjs/compat/emitter.cjs +1 -0
  18. package/dist/cjs/compat/result.cjs +1 -0
  19. package/dist/cjs/errors.cjs +1 -387
  20. package/dist/cjs/index.cjs +1 -10759
  21. package/dist/cjs/kernel.cjs +1 -0
  22. package/dist/cjs/locales/af.cjs +1 -0
  23. package/dist/cjs/locales/ar.cjs +1 -0
  24. package/dist/cjs/locales/bn.cjs +1 -0
  25. package/dist/cjs/locales/da.cjs +1 -0
  26. package/dist/cjs/locales/de.cjs +1 -0
  27. package/dist/cjs/locales/en.cjs +1 -0
  28. package/dist/cjs/locales/es-MX.cjs +1 -0
  29. package/dist/cjs/locales/es.cjs +1 -0
  30. package/dist/cjs/locales/fi.cjs +1 -0
  31. package/dist/cjs/locales/fr.cjs +1 -0
  32. package/dist/cjs/locales/hi.cjs +1 -0
  33. package/dist/cjs/locales/id.cjs +1 -0
  34. package/dist/cjs/locales/index.cjs +1 -2877
  35. package/dist/cjs/locales/it.cjs +1 -0
  36. package/dist/cjs/locales/ja.cjs +1 -0
  37. package/dist/cjs/locales/ko.cjs +1 -0
  38. package/dist/cjs/locales/lazy.cjs +1 -3169
  39. package/dist/cjs/locales/nl.cjs +1 -0
  40. package/dist/cjs/locales/no.cjs +1 -0
  41. package/dist/cjs/locales/pl.cjs +1 -0
  42. package/dist/cjs/locales/pt-BR.cjs +1 -0
  43. package/dist/cjs/locales/pt.cjs +1 -0
  44. package/dist/cjs/locales/ru.cjs +1 -0
  45. package/dist/cjs/locales/runtime.cjs +1 -0
  46. package/dist/cjs/locales/sv.cjs +1 -0
  47. package/dist/cjs/locales/sw.cjs +1 -0
  48. package/dist/cjs/locales/th.cjs +1 -0
  49. package/dist/cjs/locales/tr.cjs +1 -0
  50. package/dist/cjs/locales/vi.cjs +1 -0
  51. package/dist/cjs/locales/zh.cjs +1 -0
  52. package/dist/cjs/mini.cjs +1 -7474
  53. package/dist/cjs/pigment.cjs +1 -0
  54. package/dist/cjs/plugins/index.cjs +1 -0
  55. package/dist/cjs/registry.cjs +1 -0
  56. package/dist/cjs/v3/index.cjs +1 -0
  57. package/dist/cjs/v4/core/index.cjs +1 -0
  58. package/dist/cjs/v4/index.cjs +1 -0
  59. package/dist/cjs/v4/locales/index.cjs +1 -0
  60. package/dist/cjs/v4/mini/index.cjs +1 -0
  61. package/dist/cjs/v4-mini/index.cjs +1 -0
  62. package/dist/cjs/validators/any.cjs +1 -0
  63. package/dist/cjs/validators/array.cjs +1 -0
  64. package/dist/cjs/validators/base.cjs +1 -0
  65. package/dist/cjs/validators/base64.cjs +1 -0
  66. package/dist/cjs/validators/bigint.cjs +1 -0
  67. package/dist/cjs/validators/boolean.cjs +1 -0
  68. package/dist/cjs/validators/codec.cjs +1 -0
  69. package/dist/cjs/validators/custom.cjs +1 -0
  70. package/dist/cjs/validators/date.cjs +1 -0
  71. package/dist/cjs/validators/discriminated-union.cjs +1 -0
  72. package/dist/cjs/validators/enum.cjs +1 -0
  73. package/dist/cjs/validators/file.cjs +1 -0
  74. package/dist/cjs/validators/function.cjs +1 -0
  75. package/dist/cjs/validators/hex.cjs +1 -0
  76. package/dist/cjs/validators/index.cjs +1 -0
  77. package/dist/cjs/validators/intersection.cjs +1 -0
  78. package/dist/cjs/validators/json.cjs +1 -0
  79. package/dist/cjs/validators/lazy.cjs +1 -0
  80. package/dist/cjs/validators/literal.cjs +1 -0
  81. package/dist/cjs/validators/map.cjs +1 -0
  82. package/dist/cjs/validators/nan.cjs +1 -0
  83. package/dist/cjs/validators/never.cjs +1 -0
  84. package/dist/cjs/validators/null.cjs +1 -0
  85. package/dist/cjs/validators/number.cjs +1 -0
  86. package/dist/cjs/validators/object.cjs +1 -0
  87. package/dist/cjs/validators/promise.cjs +1 -0
  88. package/dist/cjs/validators/record.cjs +1 -0
  89. package/dist/cjs/validators/set.cjs +1 -0
  90. package/dist/cjs/validators/string-bool.cjs +1 -0
  91. package/dist/cjs/validators/string-formats.cjs +1 -0
  92. package/dist/cjs/validators/string.cjs +1 -0
  93. package/dist/cjs/validators/symbol.cjs +1 -0
  94. package/dist/cjs/validators/template-literal.cjs +1 -0
  95. package/dist/cjs/validators/tuple.cjs +1 -0
  96. package/dist/cjs/validators/uint8array.cjs +1 -0
  97. package/dist/cjs/validators/undefined.cjs +1 -0
  98. package/dist/cjs/validators/union.cjs +1 -0
  99. package/dist/cjs/validators/unknown.cjs +1 -0
  100. package/dist/cjs/validators/void.cjs +1 -0
  101. package/dist/cjs/validators/xor.cjs +1 -0
  102. package/dist/cli/bin.d.ts +0 -1
  103. package/dist/cli/bin.js +2 -0
  104. package/dist/cli/commands/benchmark.d.ts +1 -2
  105. package/dist/cli/commands/validate.d.ts +1 -2
  106. package/dist/cli/index.d.ts +0 -1
  107. package/dist/cli/index.js +1 -0
  108. package/dist/codecs/index.d.ts +21 -4
  109. package/dist/codecs/index.js +1 -4
  110. package/dist/coercion/bigint.d.ts +2 -3
  111. package/dist/coercion/boolean.d.ts +3 -3
  112. package/dist/coercion/date.d.ts +3 -3
  113. package/dist/coercion/index.d.ts +5 -6
  114. package/dist/coercion/index.js +1 -111
  115. package/dist/coercion/number.d.ts +2 -3
  116. package/dist/coercion/string.d.ts +2 -3
  117. package/dist/compat/emitter.d.ts +0 -1
  118. package/dist/compat/emitter.js +1 -181
  119. package/dist/compat/index.d.ts +4 -5
  120. package/dist/compat/result.d.ts +1 -2
  121. package/dist/compat/result.js +1 -171
  122. package/dist/errors-core.d.ts +58 -0
  123. package/dist/errors.d.ts +4 -54
  124. package/dist/errors.js +1 -235
  125. package/dist/events.d.ts +3 -4
  126. package/dist/index.d.ts +1093 -851
  127. package/dist/index.js +1 -855
  128. package/dist/kernel.d.ts +2 -3
  129. package/dist/kernel.js +1 -405
  130. package/dist/locales/af.d.ts +1 -2
  131. package/dist/locales/af.js +1 -107
  132. package/dist/locales/ar.d.ts +1 -2
  133. package/dist/locales/ar.js +1 -107
  134. package/dist/locales/bn.d.ts +1 -2
  135. package/dist/locales/bn.js +1 -107
  136. package/dist/locales/da.d.ts +1 -2
  137. package/dist/locales/da.js +1 -107
  138. package/dist/locales/de.d.ts +1 -2
  139. package/dist/locales/de.js +1 -107
  140. package/dist/locales/en.d.ts +1 -2
  141. package/dist/locales/en.js +1 -107
  142. package/dist/locales/es-MX.d.ts +1 -2
  143. package/dist/locales/es-MX.js +1 -106
  144. package/dist/locales/es.d.ts +1 -2
  145. package/dist/locales/es.js +1 -95
  146. package/dist/locales/fi.d.ts +1 -2
  147. package/dist/locales/fi.js +1 -107
  148. package/dist/locales/fr.d.ts +1 -2
  149. package/dist/locales/fr.js +1 -95
  150. package/dist/locales/hi.d.ts +1 -2
  151. package/dist/locales/hi.js +1 -107
  152. package/dist/locales/id.d.ts +1 -2
  153. package/dist/locales/id.js +1 -107
  154. package/dist/locales/index.d.ts +10 -15
  155. package/dist/locales/index.js +1 -3
  156. package/dist/locales/it.d.ts +1 -2
  157. package/dist/locales/it.js +1 -107
  158. package/dist/locales/ja.d.ts +1 -2
  159. package/dist/locales/ja.js +1 -107
  160. package/dist/locales/ko.d.ts +1 -2
  161. package/dist/locales/ko.js +1 -107
  162. package/dist/locales/lazy.d.ts +4 -26
  163. package/dist/locales/lazy.js +1 -220
  164. package/dist/locales/nl.d.ts +1 -2
  165. package/dist/locales/nl.js +1 -107
  166. package/dist/locales/no.d.ts +1 -2
  167. package/dist/locales/no.js +1 -107
  168. package/dist/locales/pl.d.ts +1 -2
  169. package/dist/locales/pl.js +1 -107
  170. package/dist/locales/pt-BR.d.ts +1 -2
  171. package/dist/locales/pt-BR.js +1 -107
  172. package/dist/locales/pt.d.ts +1 -2
  173. package/dist/locales/pt.js +1 -107
  174. package/dist/locales/ru.d.ts +1 -2
  175. package/dist/locales/ru.js +1 -107
  176. package/dist/locales/runtime.d.ts +10 -0
  177. package/dist/locales/runtime.js +1 -0
  178. package/dist/locales/sv.d.ts +1 -2
  179. package/dist/locales/sv.js +1 -107
  180. package/dist/locales/sw.d.ts +1 -2
  181. package/dist/locales/sw.js +1 -107
  182. package/dist/locales/th.d.ts +1 -2
  183. package/dist/locales/th.js +1 -107
  184. package/dist/locales/tr.d.ts +1 -2
  185. package/dist/locales/tr.js +1 -107
  186. package/dist/locales/types.d.ts +0 -1
  187. package/dist/locales/vi.d.ts +1 -2
  188. package/dist/locales/vi.js +1 -107
  189. package/dist/locales/zh.d.ts +1 -2
  190. package/dist/locales/zh.js +1 -107
  191. package/dist/logger.d.ts +0 -1
  192. package/dist/mini.d.ts +67 -68
  193. package/dist/mini.js +1 -132
  194. package/dist/pigment.d.ts +0 -1
  195. package/dist/pigment.js +1 -178
  196. package/dist/plugins/index.d.ts +2 -3
  197. package/dist/plugins/index.js +1 -0
  198. package/dist/plugins/types.d.ts +4 -5
  199. package/dist/registry.d.ts +23 -0
  200. package/dist/registry.js +1 -0
  201. package/dist/utils/codec-utils.d.ts +0 -1
  202. package/dist/utils/deep-merge.d.ts +0 -1
  203. package/dist/utils/ip-validation.d.ts +0 -1
  204. package/dist/utils/json-schema.d.ts +26 -7
  205. package/dist/utils/security.d.ts +2 -6
  206. package/dist/v3/index.d.ts +2 -0
  207. package/dist/v3/index.js +1 -0
  208. package/dist/v4/core/index.d.ts +272 -0
  209. package/dist/v4/core/index.js +1 -0
  210. package/dist/v4/index.d.ts +4 -0
  211. package/dist/v4/index.js +1 -0
  212. package/dist/v4/locales/index.d.ts +57 -0
  213. package/dist/v4/locales/index.js +1 -0
  214. package/dist/v4/mini/index.d.ts +2 -0
  215. package/dist/v4/mini/index.js +1 -0
  216. package/dist/v4-mini/index.d.ts +22 -0
  217. package/dist/v4-mini/index.js +1 -0
  218. package/dist/validators/any.d.ts +7 -2
  219. package/dist/validators/any.js +1 -0
  220. package/dist/validators/array.d.ts +16 -2
  221. package/dist/validators/array.js +1 -0
  222. package/dist/validators/base.d.ts +213 -14
  223. package/dist/validators/base.js +1 -0
  224. package/dist/validators/base64.d.ts +1 -2
  225. package/dist/validators/base64.js +1 -0
  226. package/dist/validators/bigint.d.ts +21 -3
  227. package/dist/validators/bigint.js +1 -0
  228. package/dist/validators/boolean.d.ts +13 -4
  229. package/dist/validators/boolean.js +1 -0
  230. package/dist/validators/codec.d.ts +9 -2
  231. package/dist/validators/codec.js +1 -0
  232. package/dist/validators/custom.d.ts +15 -2
  233. package/dist/validators/custom.js +1 -0
  234. package/dist/validators/date.d.ts +19 -3
  235. package/dist/validators/date.js +1 -0
  236. package/dist/validators/discriminated-union.d.ts +6 -5
  237. package/dist/validators/discriminated-union.js +1 -0
  238. package/dist/validators/enum.d.ts +10 -7
  239. package/dist/validators/enum.js +1 -0
  240. package/dist/validators/file.d.ts +7 -2
  241. package/dist/validators/file.js +1 -0
  242. package/dist/validators/function.d.ts +11 -5
  243. package/dist/validators/function.js +1 -0
  244. package/dist/validators/hex.d.ts +1 -2
  245. package/dist/validators/hex.js +1 -0
  246. package/dist/validators/index.d.ts +38 -39
  247. package/dist/validators/index.js +1 -515
  248. package/dist/validators/intersection.d.ts +1 -2
  249. package/dist/validators/intersection.js +1 -0
  250. package/dist/validators/json.d.ts +1 -2
  251. package/dist/validators/json.js +1 -0
  252. package/dist/validators/lazy.d.ts +5 -9
  253. package/dist/validators/lazy.js +1 -0
  254. package/dist/validators/literal.d.ts +9 -5
  255. package/dist/validators/literal.js +1 -0
  256. package/dist/validators/map.d.ts +15 -2
  257. package/dist/validators/map.js +1 -0
  258. package/dist/validators/nan.d.ts +2 -3
  259. package/dist/validators/nan.js +1 -0
  260. package/dist/validators/never.d.ts +1 -2
  261. package/dist/validators/never.js +1 -0
  262. package/dist/validators/null.d.ts +3 -3
  263. package/dist/validators/null.js +1 -0
  264. package/dist/validators/number.d.ts +75 -27
  265. package/dist/validators/number.js +1 -0
  266. package/dist/validators/object.d.ts +42 -11
  267. package/dist/validators/object.js +1 -0
  268. package/dist/validators/promise.d.ts +15 -10
  269. package/dist/validators/promise.js +1 -0
  270. package/dist/validators/record.d.ts +21 -9
  271. package/dist/validators/record.js +1 -0
  272. package/dist/validators/set.d.ts +11 -2
  273. package/dist/validators/set.js +1 -0
  274. package/dist/validators/string-bool.d.ts +7 -10
  275. package/dist/validators/string-bool.js +1 -0
  276. package/dist/validators/string-formats.d.ts +64 -65
  277. package/dist/validators/string-formats.js +1 -0
  278. package/dist/validators/string.d.ts +84 -26
  279. package/dist/validators/string.js +1 -0
  280. package/dist/validators/symbol.d.ts +8 -3
  281. package/dist/validators/symbol.js +1 -0
  282. package/dist/validators/template-literal.d.ts +1 -2
  283. package/dist/validators/template-literal.js +1 -0
  284. package/dist/validators/tuple.d.ts +29 -12
  285. package/dist/validators/tuple.js +1 -0
  286. package/dist/validators/uint8array.d.ts +3 -4
  287. package/dist/validators/uint8array.js +1 -0
  288. package/dist/validators/undefined.d.ts +3 -3
  289. package/dist/validators/undefined.js +1 -0
  290. package/dist/validators/union.d.ts +7 -4
  291. package/dist/validators/union.js +1 -0
  292. package/dist/validators/unknown.d.ts +7 -2
  293. package/dist/validators/unknown.js +1 -0
  294. package/dist/validators/void.d.ts +3 -2
  295. package/dist/validators/void.js +1 -0
  296. package/dist/validators/xor.d.ts +4 -5
  297. package/dist/validators/xor.js +1 -0
  298. package/package.json +239 -154
  299. package/dist/chunks/bigint-CRS0QVsy.js +0 -1854
  300. package/dist/chunks/bigint-CRS0QVsy.js.map +0 -1
  301. package/dist/chunks/date-50JV_Mfj.js +0 -506
  302. package/dist/chunks/date-50JV_Mfj.js.map +0 -1
  303. package/dist/chunks/index-DO8CFMxD.js +0 -894
  304. package/dist/chunks/index-DO8CFMxD.js.map +0 -1
  305. package/dist/chunks/json-Cp4WO0M9.js +0 -2021
  306. package/dist/chunks/json-Cp4WO0M9.js.map +0 -1
  307. package/dist/chunks/unknown-Dhzri_T-.js +0 -28
  308. package/dist/chunks/unknown-Dhzri_T-.js.map +0 -1
  309. package/dist/cjs/errors.cjs.map +0 -1
  310. package/dist/cjs/index.cjs.map +0 -1
  311. package/dist/cjs/locales/index.cjs.map +0 -1
  312. package/dist/cjs/locales/lazy.cjs.map +0 -1
  313. package/dist/cjs/mini.cjs.map +0 -1
  314. package/dist/cli/bin.d.ts.map +0 -1
  315. package/dist/cli/commands/benchmark.d.ts.map +0 -1
  316. package/dist/cli/commands/validate.d.ts.map +0 -1
  317. package/dist/cli/index.d.ts.map +0 -1
  318. package/dist/codecs/index.d.ts.map +0 -1
  319. package/dist/codecs/index.js.map +0 -1
  320. package/dist/coercion/bigint.d.ts.map +0 -1
  321. package/dist/coercion/boolean.d.ts.map +0 -1
  322. package/dist/coercion/date.d.ts.map +0 -1
  323. package/dist/coercion/index.d.ts.map +0 -1
  324. package/dist/coercion/index.js.map +0 -1
  325. package/dist/coercion/number.d.ts.map +0 -1
  326. package/dist/coercion/string.d.ts.map +0 -1
  327. package/dist/compat/emitter.d.ts.map +0 -1
  328. package/dist/compat/emitter.js.map +0 -1
  329. package/dist/compat/index.d.ts.map +0 -1
  330. package/dist/compat/result.d.ts.map +0 -1
  331. package/dist/compat/result.js.map +0 -1
  332. package/dist/errors.d.ts.map +0 -1
  333. package/dist/errors.js.map +0 -1
  334. package/dist/events.d.ts.map +0 -1
  335. package/dist/index.d.ts.map +0 -1
  336. package/dist/index.js.map +0 -1
  337. package/dist/kernel.d.ts.map +0 -1
  338. package/dist/kernel.js.map +0 -1
  339. package/dist/locales/af.d.ts.map +0 -1
  340. package/dist/locales/af.js.map +0 -1
  341. package/dist/locales/ar.d.ts.map +0 -1
  342. package/dist/locales/ar.js.map +0 -1
  343. package/dist/locales/backup-en.d.ts +0 -3
  344. package/dist/locales/backup-en.d.ts.map +0 -1
  345. package/dist/locales/bn.d.ts.map +0 -1
  346. package/dist/locales/bn.js.map +0 -1
  347. package/dist/locales/da.d.ts.map +0 -1
  348. package/dist/locales/da.js.map +0 -1
  349. package/dist/locales/de.d.ts.map +0 -1
  350. package/dist/locales/de.js.map +0 -1
  351. package/dist/locales/en.d.ts.map +0 -1
  352. package/dist/locales/en.js.map +0 -1
  353. package/dist/locales/es-MX.d.ts.map +0 -1
  354. package/dist/locales/es-MX.js.map +0 -1
  355. package/dist/locales/es.d.ts.map +0 -1
  356. package/dist/locales/es.js.map +0 -1
  357. package/dist/locales/fi.d.ts.map +0 -1
  358. package/dist/locales/fi.js.map +0 -1
  359. package/dist/locales/fr.d.ts.map +0 -1
  360. package/dist/locales/fr.js.map +0 -1
  361. package/dist/locales/hi.d.ts.map +0 -1
  362. package/dist/locales/hi.js.map +0 -1
  363. package/dist/locales/id.d.ts.map +0 -1
  364. package/dist/locales/id.js.map +0 -1
  365. package/dist/locales/index.d.ts.map +0 -1
  366. package/dist/locales/index.js.map +0 -1
  367. package/dist/locales/it.d.ts.map +0 -1
  368. package/dist/locales/it.js.map +0 -1
  369. package/dist/locales/ja.d.ts.map +0 -1
  370. package/dist/locales/ja.js.map +0 -1
  371. package/dist/locales/ko.d.ts.map +0 -1
  372. package/dist/locales/ko.js.map +0 -1
  373. package/dist/locales/lazy.d.ts.map +0 -1
  374. package/dist/locales/lazy.js.map +0 -1
  375. package/dist/locales/nl.d.ts.map +0 -1
  376. package/dist/locales/nl.js.map +0 -1
  377. package/dist/locales/no.d.ts.map +0 -1
  378. package/dist/locales/no.js.map +0 -1
  379. package/dist/locales/pl.d.ts.map +0 -1
  380. package/dist/locales/pl.js.map +0 -1
  381. package/dist/locales/pt-BR.d.ts.map +0 -1
  382. package/dist/locales/pt-BR.js.map +0 -1
  383. package/dist/locales/pt.d.ts.map +0 -1
  384. package/dist/locales/pt.js.map +0 -1
  385. package/dist/locales/ru.d.ts.map +0 -1
  386. package/dist/locales/ru.js.map +0 -1
  387. package/dist/locales/sv.d.ts.map +0 -1
  388. package/dist/locales/sv.js.map +0 -1
  389. package/dist/locales/sw.d.ts.map +0 -1
  390. package/dist/locales/sw.js.map +0 -1
  391. package/dist/locales/th.d.ts.map +0 -1
  392. package/dist/locales/th.js.map +0 -1
  393. package/dist/locales/tr.d.ts.map +0 -1
  394. package/dist/locales/tr.js.map +0 -1
  395. package/dist/locales/types.d.ts.map +0 -1
  396. package/dist/locales/vi.d.ts.map +0 -1
  397. package/dist/locales/vi.js.map +0 -1
  398. package/dist/locales/zh.d.ts.map +0 -1
  399. package/dist/locales/zh.js.map +0 -1
  400. package/dist/logger.d.ts.map +0 -1
  401. package/dist/mini.d.ts.map +0 -1
  402. package/dist/mini.js.map +0 -1
  403. package/dist/pigment.d.ts.map +0 -1
  404. package/dist/pigment.js.map +0 -1
  405. package/dist/plugins/index.d.ts.map +0 -1
  406. package/dist/plugins/types.d.ts.map +0 -1
  407. package/dist/utils/codec-utils.d.ts.map +0 -1
  408. package/dist/utils/deep-merge.d.ts.map +0 -1
  409. package/dist/utils/ip-validation.d.ts.map +0 -1
  410. package/dist/utils/json-schema.d.ts.map +0 -1
  411. package/dist/utils/security.d.ts.map +0 -1
  412. package/dist/validators/any.d.ts.map +0 -1
  413. package/dist/validators/array.d.ts.map +0 -1
  414. package/dist/validators/base.d.ts.map +0 -1
  415. package/dist/validators/base64.d.ts.map +0 -1
  416. package/dist/validators/bigint.d.ts.map +0 -1
  417. package/dist/validators/boolean.d.ts.map +0 -1
  418. package/dist/validators/codec.d.ts.map +0 -1
  419. package/dist/validators/custom.d.ts.map +0 -1
  420. package/dist/validators/date.d.ts.map +0 -1
  421. package/dist/validators/discriminated-union.d.ts.map +0 -1
  422. package/dist/validators/enum.d.ts.map +0 -1
  423. package/dist/validators/file.d.ts.map +0 -1
  424. package/dist/validators/function.d.ts.map +0 -1
  425. package/dist/validators/hex.d.ts.map +0 -1
  426. package/dist/validators/index.d.ts.map +0 -1
  427. package/dist/validators/index.js.map +0 -1
  428. package/dist/validators/intersection.d.ts.map +0 -1
  429. package/dist/validators/json.d.ts.map +0 -1
  430. package/dist/validators/lazy.d.ts.map +0 -1
  431. package/dist/validators/literal.d.ts.map +0 -1
  432. package/dist/validators/map.d.ts.map +0 -1
  433. package/dist/validators/nan.d.ts.map +0 -1
  434. package/dist/validators/never.d.ts.map +0 -1
  435. package/dist/validators/null.d.ts.map +0 -1
  436. package/dist/validators/number.d.ts.map +0 -1
  437. package/dist/validators/object.d.ts.map +0 -1
  438. package/dist/validators/promise.d.ts.map +0 -1
  439. package/dist/validators/record.d.ts.map +0 -1
  440. package/dist/validators/set.d.ts.map +0 -1
  441. package/dist/validators/string-bool.d.ts.map +0 -1
  442. package/dist/validators/string-formats.d.ts.map +0 -1
  443. package/dist/validators/string.d.ts.map +0 -1
  444. package/dist/validators/symbol.d.ts.map +0 -1
  445. package/dist/validators/template-literal.d.ts.map +0 -1
  446. package/dist/validators/tuple.d.ts.map +0 -1
  447. package/dist/validators/uint8array.d.ts.map +0 -1
  448. package/dist/validators/undefined.d.ts.map +0 -1
  449. package/dist/validators/union.d.ts.map +0 -1
  450. package/dist/validators/unknown.d.ts.map +0 -1
  451. package/dist/validators/void.d.ts.map +0 -1
  452. package/dist/validators/xor.d.ts.map +0 -1
@@ -1,894 +0,0 @@
1
- import { i as VldBase, u as getMessages, h as VldString, c as VldNumber, V as VldBigInt, b as VldDate, a as VldBoolean } from './bigint-CRS0QVsy.js';
2
- import { VldError, createIssue } from '../errors.js';
3
- import { V as VldUnknown } from './unknown-Dhzri_T-.js';
4
-
5
- /**
6
- * Codec validator for bidirectional transformations
7
- * Enables converting between different data representations
8
- */
9
- class VldCodec extends VldBase {
10
- constructor(inputValidator, outputValidator, codecTransform) {
11
- super();
12
- this.inputValidator = inputValidator;
13
- this.outputValidator = outputValidator;
14
- this.codecTransform = codecTransform;
15
- }
16
- /**
17
- * Parse (decode) a value from input to output format
18
- */
19
- parse(value) {
20
- const result = this.safeParse(value);
21
- if (!result.success) {
22
- throw result.error;
23
- }
24
- return result.data;
25
- }
26
- /**
27
- * Safely parse (decode) a value from input to output format
28
- */
29
- safeParse(value) {
30
- // First validate the input
31
- const inputResult = this.inputValidator.safeParse(value);
32
- if (!inputResult.success) {
33
- return inputResult;
34
- }
35
- try {
36
- // Then decode to output
37
- const decoded = this.codecTransform.decode(inputResult.data);
38
- // Handle async decode
39
- if (decoded instanceof Promise) {
40
- throw new VldError([
41
- createIssue('custom', [], getMessages().codecAsyncNotSupported)
42
- ]);
43
- }
44
- // Validate the decoded output
45
- return this.outputValidator.safeParse(decoded);
46
- }
47
- catch (error) {
48
- if (error instanceof VldError) {
49
- return { success: false, error };
50
- }
51
- return {
52
- success: false,
53
- error: new VldError([
54
- createIssue('custom', [], getMessages().codecDecodeFailed)
55
- ])
56
- };
57
- }
58
- }
59
- /**
60
- * Encode a value from output back to input format
61
- */
62
- encode(value) {
63
- const result = this.safeEncode(value);
64
- if (!result.success) {
65
- throw result.error;
66
- }
67
- return result.data;
68
- }
69
- /**
70
- * Safely encode a value from output back to input format
71
- */
72
- safeEncode(value) {
73
- // First validate the output
74
- const outputResult = this.outputValidator.safeParse(value);
75
- if (!outputResult.success) {
76
- return outputResult;
77
- }
78
- try {
79
- // Then encode to input
80
- const encoded = this.codecTransform.encode(outputResult.data);
81
- // Handle async encode
82
- if (encoded instanceof Promise) {
83
- throw new VldError([
84
- createIssue('custom', [], getMessages().codecAsyncNotSupported)
85
- ]);
86
- }
87
- // Validate the encoded input
88
- return this.inputValidator.safeParse(encoded);
89
- }
90
- catch (error) {
91
- if (error instanceof VldError) {
92
- return { success: false, error };
93
- }
94
- return {
95
- success: false,
96
- error: new VldError([
97
- createIssue('custom', [], getMessages().codecEncodeFailed)
98
- ])
99
- };
100
- }
101
- }
102
- /**
103
- * Async version of parse (decode)
104
- */
105
- async parseAsync(value) {
106
- const result = await this.safeParseAsync(value);
107
- if (!result.success) {
108
- throw result.error;
109
- }
110
- return result.data;
111
- }
112
- /**
113
- * Async version of safeParse (decode)
114
- */
115
- async safeParseAsync(value) {
116
- // First validate the input
117
- const inputResult = this.inputValidator.safeParse(value);
118
- if (!inputResult.success) {
119
- return inputResult;
120
- }
121
- try {
122
- // Then decode to output (supports async)
123
- const decoded = await this.codecTransform.decode(inputResult.data);
124
- // Validate the decoded output
125
- return this.outputValidator.safeParse(decoded);
126
- }
127
- catch (error) {
128
- if (error instanceof VldError) {
129
- return { success: false, error };
130
- }
131
- return {
132
- success: false,
133
- error: new VldError([
134
- createIssue('custom', [], getMessages().codecDecodeFailed)
135
- ])
136
- };
137
- }
138
- }
139
- /**
140
- * Async version of encode
141
- */
142
- async encodeAsync(value) {
143
- const result = await this.safeEncodeAsync(value);
144
- if (!result.success) {
145
- throw result.error;
146
- }
147
- return result.data;
148
- }
149
- /**
150
- * Async version of safeEncode
151
- */
152
- async safeEncodeAsync(value) {
153
- // First validate the output
154
- const outputResult = this.outputValidator.safeParse(value);
155
- if (!outputResult.success) {
156
- return outputResult;
157
- }
158
- try {
159
- // Then encode to input (supports async)
160
- const encoded = await this.codecTransform.encode(outputResult.data);
161
- // Validate the encoded input
162
- return this.inputValidator.safeParse(encoded);
163
- }
164
- catch (error) {
165
- if (error instanceof VldError) {
166
- return { success: false, error };
167
- }
168
- return {
169
- success: false,
170
- error: new VldError([
171
- createIssue('custom', [], getMessages().codecEncodeFailed)
172
- ])
173
- };
174
- }
175
- }
176
- /**
177
- * Create a codec validator
178
- */
179
- static create(inputValidator, outputValidator, codecTransform) {
180
- return new VldCodec(inputValidator, outputValidator, codecTransform);
181
- }
182
- }
183
-
184
- /**
185
- * Base64 string validator
186
- */
187
- class VldBase64 extends VldBase {
188
- constructor(urlSafe = false) {
189
- super();
190
- this.urlSafe = urlSafe;
191
- }
192
- parse(value) {
193
- const result = this.safeParse(value);
194
- if (!result.success) {
195
- throw result.error;
196
- }
197
- return result.data;
198
- }
199
- safeParse(value) {
200
- if (typeof value !== 'string') {
201
- return {
202
- success: false,
203
- error: new VldError([
204
- createIssue('invalid_type', [], getMessages().expectedString)
205
- ])
206
- };
207
- }
208
- // Check if it's a valid base64 string
209
- const regex = this.urlSafe ? VldBase64.BASE64_URL_REGEX : VldBase64.BASE64_REGEX;
210
- // Check basic format
211
- if (!regex.test(value)) {
212
- return {
213
- success: false,
214
- error: new VldError([
215
- createIssue('custom', [], getMessages().invalidBase64)
216
- ])
217
- };
218
- }
219
- // For standard base64, check length is multiple of 4 (after padding)
220
- // Empty strings are valid (decode to empty buffer)
221
- // For URL-safe base64, padding is not required
222
- if (!this.urlSafe && value.length > 0 && value.length % 4 !== 0) {
223
- return {
224
- success: false,
225
- error: new VldError([
226
- createIssue('custom', [], getMessages().invalidBase64)
227
- ])
228
- };
229
- }
230
- return { success: true, data: value };
231
- }
232
- /**
233
- * Create a URL-safe base64 validator
234
- */
235
- urlSafeMode() {
236
- return new VldBase64(true);
237
- }
238
- static create(urlSafe = false) {
239
- return new VldBase64(urlSafe);
240
- }
241
- }
242
- VldBase64.BASE64_REGEX = /^[A-Za-z0-9+/]*={0,2}$/;
243
- // Note: RFC 4648 specifies URL-safe base64 should omit padding, but we allow it for compatibility
244
- VldBase64.BASE64_URL_REGEX = /^[A-Za-z0-9_-]*={0,2}$/;
245
-
246
- /**
247
- * Hexadecimal string validator
248
- */
249
- class VldHex extends VldBase {
250
- constructor(lowercase = false) {
251
- super();
252
- this.lowercase = lowercase;
253
- }
254
- parse(value) {
255
- const result = this.safeParse(value);
256
- if (!result.success) {
257
- throw result.error;
258
- }
259
- return result.data;
260
- }
261
- safeParse(value) {
262
- if (typeof value !== 'string') {
263
- return {
264
- success: false,
265
- error: new VldError([
266
- createIssue('invalid_type', [], getMessages().expectedString)
267
- ])
268
- };
269
- }
270
- // Check if it's a valid hex string
271
- if (!VldHex.HEX_REGEX.test(value)) {
272
- return {
273
- success: false,
274
- error: new VldError([
275
- createIssue('custom', [], getMessages().invalidHex)
276
- ])
277
- };
278
- }
279
- // Check if even length (full bytes)
280
- if (value.length % 2 !== 0) {
281
- return {
282
- success: false,
283
- error: new VldError([
284
- createIssue('custom', [], getMessages().invalidHex)
285
- ])
286
- };
287
- }
288
- // Normalize case if required
289
- const normalizedValue = this.lowercase ? value.toLowerCase() : value;
290
- return { success: true, data: normalizedValue };
291
- }
292
- /**
293
- * Require lowercase hex characters
294
- */
295
- lowercaseMode() {
296
- return new VldHex(true);
297
- }
298
- static create(lowercase = false) {
299
- return new VldHex(lowercase);
300
- }
301
- }
302
- // BUG-008 FIX: Use * instead of + to allow empty hex strings (consistent with base64 validator)
303
- VldHex.HEX_REGEX = /^[0-9a-fA-F]*$/;
304
-
305
- /**
306
- * Uint8Array validator with immutable configuration
307
- * BUG-NEW-010 FIX: Refactored to follow immutability pattern
308
- */
309
- class VldUint8Array extends VldBase {
310
- /**
311
- * Protected constructor to maintain immutability
312
- */
313
- constructor(config) {
314
- super();
315
- this.config = config || {};
316
- }
317
- parse(value) {
318
- const result = this.safeParse(value);
319
- if (!result.success) {
320
- throw result.error;
321
- }
322
- return result.data;
323
- }
324
- safeParse(value) {
325
- if (!(value instanceof Uint8Array)) {
326
- return {
327
- success: false,
328
- error: new VldError([
329
- createIssue('invalid_type', [], getMessages().expectedUint8Array)
330
- ])
331
- };
332
- }
333
- // Check exact length if specified
334
- if (this.config.exactLength !== undefined && value.length !== this.config.exactLength) {
335
- return {
336
- success: false,
337
- error: new VldError([
338
- createIssue('custom', [], getMessages().uint8ArrayExactLength(this.config.exactLength))
339
- ])
340
- };
341
- }
342
- // Check minimum length
343
- if (this.config.minLength !== undefined && value.length < this.config.minLength) {
344
- return {
345
- success: false,
346
- error: new VldError([
347
- createIssue('custom', [], getMessages().uint8ArrayMinLength(this.config.minLength))
348
- ])
349
- };
350
- }
351
- // Check maximum length
352
- if (this.config.maxLength !== undefined && value.length > this.config.maxLength) {
353
- return {
354
- success: false,
355
- error: new VldError([
356
- createIssue('custom', [], getMessages().uint8ArrayMaxLength(this.config.maxLength))
357
- ])
358
- };
359
- }
360
- return { success: true, data: value };
361
- }
362
- /**
363
- * Set minimum byte length
364
- * Returns new immutable validator instance
365
- */
366
- min(length) {
367
- return new VldUint8Array({
368
- ...this.config,
369
- minLength: length
370
- });
371
- }
372
- /**
373
- * Set maximum byte length
374
- * Returns new immutable validator instance
375
- */
376
- max(length) {
377
- return new VldUint8Array({
378
- ...this.config,
379
- maxLength: length
380
- });
381
- }
382
- /**
383
- * Set exact byte length
384
- * Returns new immutable validator instance
385
- * Clears min/max when setting exact length
386
- */
387
- length(length) {
388
- return new VldUint8Array({
389
- exactLength: length,
390
- // Clear min/max when exact length is set
391
- minLength: undefined,
392
- maxLength: undefined
393
- });
394
- }
395
- static create() {
396
- return new VldUint8Array();
397
- }
398
- }
399
-
400
- /**
401
- * Utility functions for codec transformations
402
- */
403
- /**
404
- * Convert a base64 string to Uint8Array
405
- */
406
- function base64ToUint8Array(base64) {
407
- // Handle URL-safe base64
408
- const base64Clean = base64.replace(/-/g, '+').replace(/_/g, '/');
409
- // Add padding if necessary
410
- const padded = base64Clean.padEnd(base64Clean.length + (4 - base64Clean.length % 4) % 4, '=');
411
- // Decode base64 to binary string
412
- const binaryString = safeAtob(padded);
413
- // Convert binary string to Uint8Array
414
- const bytes = new Uint8Array(binaryString.length);
415
- for (let i = 0; i < binaryString.length; i++) {
416
- bytes[i] = binaryString.charCodeAt(i);
417
- }
418
- return bytes;
419
- }
420
- /**
421
- * Convert Uint8Array to base64 string
422
- */
423
- function uint8ArrayToBase64(bytes) {
424
- // Convert Uint8Array to binary string
425
- let binaryString = '';
426
- for (let i = 0; i < bytes.length; i++) {
427
- binaryString += String.fromCharCode(bytes[i]);
428
- }
429
- // Encode to base64
430
- return safeBtoa(binaryString);
431
- }
432
- /**
433
- * Convert Uint8Array to URL-safe base64 string
434
- */
435
- function uint8ArrayToBase64Url(bytes) {
436
- const base64 = uint8ArrayToBase64(bytes);
437
- // Make URL-safe and remove padding
438
- return base64
439
- .replace(/\+/g, '-')
440
- .replace(/\//g, '_')
441
- .replace(/=/g, '');
442
- }
443
- /**
444
- * Convert hex string to Uint8Array
445
- */
446
- function hexToUint8Array(hex) {
447
- // BUG-010 FIX: Add length validation to prevent memory exhaustion
448
- // 20 million characters = 10MB of data (consistent with base64 limits)
449
- if (hex.length > 20000000) {
450
- throw new Error('Hex string is too large (max 10MB)');
451
- }
452
- // Remove any 0x prefix if present
453
- const cleanHex = hex.startsWith('0x') ? hex.slice(2) : hex;
454
- // BUG-NPM-006 FIX: Validate hex characters to prevent silent data corruption
455
- // parseInt silently returns NaN for invalid hex, which becomes 0 in Uint8Array
456
- const hexPattern = /^[0-9a-fA-F]*$/;
457
- if (!hexPattern.test(cleanHex)) {
458
- throw new Error('Invalid hex string: contains non-hexadecimal characters');
459
- }
460
- // Ensure even length
461
- const paddedHex = cleanHex.length % 2 === 0 ? cleanHex : '0' + cleanHex;
462
- const bytes = new Uint8Array(paddedHex.length / 2);
463
- for (let i = 0; i < paddedHex.length; i += 2) {
464
- bytes[i / 2] = parseInt(paddedHex.substring(i, i + 2), 16);
465
- }
466
- return bytes;
467
- }
468
- /**
469
- * Convert Uint8Array to hex string
470
- */
471
- function uint8ArrayToHex(bytes) {
472
- let hex = '';
473
- for (let i = 0; i < bytes.length; i++) {
474
- const byte = bytes[i].toString(16);
475
- hex += byte.length === 1 ? '0' + byte : byte;
476
- }
477
- return hex;
478
- }
479
- /**
480
- * Convert string to Uint8Array using UTF-8 encoding
481
- * BUG-NEW-011 FIX: Add DoS protection with 10MB limit
482
- */
483
- function stringToUint8Array(str) {
484
- // Add DoS protection - limit to 10MB (consistent with base64 limit)
485
- const MAX_STRING_LENGTH = 10000000; // 10 million characters (~10MB)
486
- if (str.length > MAX_STRING_LENGTH) {
487
- throw new Error(`String is too large for UTF-8 encoding (max ${MAX_STRING_LENGTH} characters)`);
488
- }
489
- const encoder = new TextEncoder();
490
- return encoder.encode(str);
491
- }
492
- /**
493
- * Convert Uint8Array to string using UTF-8 decoding
494
- * BUG-NEW-012 FIX: Add DoS protection with 10MB limit
495
- */
496
- function uint8ArrayToString(bytes) {
497
- // Add DoS protection - limit to 10MB
498
- const MAX_BYTES_LENGTH = 10000000; // 10 million bytes
499
- if (bytes.length > MAX_BYTES_LENGTH) {
500
- throw new Error(`Byte array is too large for UTF-8 decoding (max ${MAX_BYTES_LENGTH} bytes)`);
501
- }
502
- const decoder = new TextDecoder();
503
- return decoder.decode(bytes);
504
- }
505
- /**
506
- * Check if running in Node.js environment
507
- */
508
- function isNodeEnvironment() {
509
- return typeof globalThis !== 'undefined' &&
510
- typeof globalThis.process !== 'undefined' &&
511
- globalThis.process.versions != null &&
512
- globalThis.process.versions.node != null;
513
- }
514
- /**
515
- * Validate and sanitize base64 input to prevent prototype pollution
516
- */
517
- function validateBase64Input(encoded) {
518
- // Check for null/undefined
519
- if (encoded == null) {
520
- throw new Error('Base64 input cannot be null or undefined');
521
- }
522
- // Ensure it's a string
523
- if (typeof encoded !== 'string') {
524
- throw new Error('Base64 input must be a string');
525
- }
526
- // Length validation - base64 strings should be reasonable length
527
- if (encoded.length > 10000000) { // 10MB limit
528
- throw new Error('Base64 input is too large');
529
- }
530
- // Base64 character validation - only allow valid base64 characters
531
- const base64Regex = /^[A-Za-z0-9+/]*={0,2}$/;
532
- if (!base64Regex.test(encoded)) {
533
- throw new Error('Invalid base64 format');
534
- }
535
- // BUG-NEW-004 FIX: Correct base64 padding validation per RFC 4648
536
- // Base64 only uses '=' or '==' as padding, never '==='
537
- const paddingIndex = encoded.indexOf('=');
538
- if (paddingIndex !== -1) {
539
- const padding = encoded.substring(paddingIndex);
540
- // Only allow '=' or '==' as valid padding (RFC 4648 compliant)
541
- if (!/^={1,2}$/.test(padding)) {
542
- throw new Error('Invalid base64 padding');
543
- }
544
- // Padding should only be at the end
545
- if (paddingIndex < encoded.length - 2) {
546
- throw new Error('Base64 padding must be at the end');
547
- }
548
- }
549
- // Additional security check: prevent potential encoded JavaScript
550
- // by looking for suspicious patterns that might indicate malicious content
551
- const suspiciousPatterns = [
552
- /eval/i,
553
- /function/i,
554
- /javascript:/i,
555
- /<script/i,
556
- /on\w+\s*=/i,
557
- /__proto__/i,
558
- /constructor/i,
559
- /prototype/i
560
- ];
561
- // Decode a small portion to check for suspicious content
562
- try {
563
- const sampleSize = Math.min(100, encoded.length);
564
- const sample = encoded.substring(0, sampleSize);
565
- const sampleDecoded = typeof atob !== 'undefined'
566
- ? atob(sample)
567
- : Buffer.from(sample, 'base64').toString('utf8', 0, 50); // Only decode first 50 chars
568
- for (const pattern of suspiciousPatterns) {
569
- if (pattern.test(sampleDecoded)) {
570
- throw new Error('Suspicious content detected in base64 input');
571
- }
572
- }
573
- }
574
- catch (error) {
575
- if (error instanceof Error && error.message.includes('Suspicious content')) {
576
- throw error;
577
- }
578
- // If decoding fails, continue - it might be invalid base64 which will be caught later
579
- }
580
- }
581
- /**
582
- * Polyfill for atob in Node.js with proper input validation
583
- */
584
- function safeAtob(encoded) {
585
- // Input validation and sanitization
586
- validateBase64Input(encoded);
587
- if (typeof atob !== 'undefined') {
588
- try {
589
- return atob(encoded);
590
- }
591
- catch (error) {
592
- throw new Error('Failed to decode base64 data');
593
- }
594
- }
595
- // Node.js fallback with additional validation
596
- if (isNodeEnvironment()) {
597
- try {
598
- // Use Buffer with explicit error handling
599
- const buffer = Buffer.from(encoded, 'base64');
600
- // Additional validation: ensure the decoded data is reasonable size
601
- if (buffer.length > 5000000) { // 5MB limit for decoded data
602
- throw new Error('Decoded base64 data is too large');
603
- }
604
- return buffer.toString('binary');
605
- }
606
- catch (error) {
607
- if (error instanceof Error && error.message.includes('Invalid base64')) {
608
- throw new Error('Invalid base64 format');
609
- }
610
- throw new Error('Failed to decode base64 data in Node.js environment');
611
- }
612
- }
613
- throw new Error('Base64 decoding not supported in this environment');
614
- }
615
- /**
616
- * Polyfill for btoa in Node.js
617
- */
618
- function safeBtoa(str) {
619
- if (typeof btoa !== 'undefined') {
620
- return btoa(str);
621
- }
622
- // Node.js fallback
623
- if (isNodeEnvironment()) {
624
- return Buffer.from(str, 'binary').toString('base64');
625
- }
626
- throw new Error('Base64 encoding not supported in this environment');
627
- }
628
-
629
- /**
630
- * Predefined codecs for common transformations (Zod-compatible)
631
- */
632
- // ===== STRING TO NUMBER CODECS =====
633
- /**
634
- * String to number codec
635
- */
636
- const stringToNumber = VldCodec.create(VldString.create(), VldNumber.create(), {
637
- decode: (str) => {
638
- const num = Number(str);
639
- if (isNaN(num))
640
- throw new Error('Invalid number');
641
- return num;
642
- },
643
- encode: (num) => num.toString()
644
- });
645
- /**
646
- * String to integer codec
647
- */
648
- const stringToInt = VldCodec.create(VldString.create(), VldNumber.create().int(), {
649
- decode: (str) => {
650
- const num = parseInt(str, 10);
651
- if (isNaN(num))
652
- throw new Error('Invalid integer');
653
- return num;
654
- },
655
- encode: (num) => Math.floor(num).toString()
656
- });
657
- /**
658
- * String to BigInt codec
659
- */
660
- const stringToBigInt = VldCodec.create(VldString.create(), VldBigInt.create(), {
661
- decode: (str) => {
662
- try {
663
- return BigInt(str);
664
- }
665
- catch {
666
- throw new Error('Invalid BigInt');
667
- }
668
- },
669
- encode: (bigint) => bigint.toString()
670
- });
671
- /**
672
- * Number to BigInt codec
673
- */
674
- const numberToBigInt = VldCodec.create(VldNumber.create().int(), VldBigInt.create(), {
675
- decode: (num) => BigInt(Math.floor(num)),
676
- encode: (bigint) => Number(bigint)
677
- });
678
- // ===== DATE CODECS =====
679
- /**
680
- * ISO datetime string to Date codec
681
- */
682
- const isoDatetimeToDate = VldCodec.create(VldString.create().regex(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z?$/, 'Invalid ISO datetime format'), VldDate.create(), {
683
- decode: (isoString) => {
684
- const date = new Date(isoString);
685
- if (isNaN(date.getTime()))
686
- throw new Error('Invalid date');
687
- return date;
688
- },
689
- encode: (date) => date.toISOString()
690
- });
691
- /**
692
- * Epoch seconds to Date codec
693
- */
694
- const epochSecondsToDate = VldCodec.create(VldNumber.create(), VldDate.create(), {
695
- decode: (seconds) => new Date(seconds * 1000),
696
- encode: (date) => Math.floor(date.getTime() / 1000)
697
- });
698
- /**
699
- * Epoch milliseconds to Date codec
700
- */
701
- const epochMillisToDate = VldCodec.create(VldNumber.create(), VldDate.create(), {
702
- decode: (millis) => new Date(millis),
703
- encode: (date) => date.getTime()
704
- });
705
- // ===== JSON CODEC =====
706
- /**
707
- * JSON string codec for any type
708
- */
709
- const jsonCodec = (schema) => {
710
- const outputSchema = schema || VldUnknown.create();
711
- return VldCodec.create(VldString.create(), outputSchema, {
712
- decode: (jsonString) => {
713
- try {
714
- return JSON.parse(jsonString);
715
- }
716
- catch {
717
- throw new Error('Invalid JSON');
718
- }
719
- },
720
- encode: (data) => JSON.stringify(data)
721
- });
722
- };
723
- // ===== URL CODECS =====
724
- /**
725
- * String to URL codec
726
- */
727
- const stringToURL = VldCodec.create(VldString.create().url(), VldUnknown.create(), // URL object
728
- {
729
- decode: (urlString) => {
730
- try {
731
- return new URL(urlString);
732
- }
733
- catch {
734
- throw new Error('Invalid URL');
735
- }
736
- },
737
- encode: (url) => url.toString()
738
- });
739
- /**
740
- * String to HTTP/HTTPS URL codec
741
- */
742
- const stringToHttpURL = VldCodec.create(VldString.create().regex(/^https?:\/\//, 'Must be HTTP or HTTPS URL'), VldUnknown.create(), // URL object
743
- {
744
- decode: (urlString) => {
745
- try {
746
- const url = new URL(urlString);
747
- if (!['http:', 'https:'].includes(url.protocol)) {
748
- throw new Error('Must be HTTP or HTTPS');
749
- }
750
- return url;
751
- }
752
- catch {
753
- throw new Error('Invalid HTTP URL');
754
- }
755
- },
756
- encode: (url) => url.toString()
757
- });
758
- /**
759
- * URI component encode/decode codec
760
- */
761
- const uriComponent = VldCodec.create(VldString.create(), VldString.create(), {
762
- decode: (encoded) => {
763
- try {
764
- return decodeURIComponent(encoded);
765
- }
766
- catch {
767
- throw new Error('Invalid URI component');
768
- }
769
- },
770
- encode: (decoded) => encodeURIComponent(decoded)
771
- });
772
- /**
773
- * String to boolean codec
774
- */
775
- const stringToBoolean = VldCodec.create(VldString.create(), VldBoolean.create(), {
776
- decode: (str) => {
777
- const lower = str.toLowerCase();
778
- if (lower === 'true' || lower === '1' || lower === 'yes' || lower === 'on')
779
- return true;
780
- if (lower === 'false' || lower === '0' || lower === 'no' || lower === 'off')
781
- return false;
782
- throw new Error('Invalid boolean string');
783
- },
784
- encode: (bool) => bool.toString()
785
- });
786
- // ===== EXISTING BYTE CODECS (updated) =====
787
- /**
788
- * Base64 to Uint8Array codec
789
- */
790
- const base64ToBytes = VldCodec.create(VldBase64.create(), VldUint8Array.create(), {
791
- decode: base64ToUint8Array,
792
- encode: uint8ArrayToBase64
793
- });
794
- /**
795
- * URL-safe Base64 to Uint8Array codec
796
- */
797
- const base64UrlToBytes = VldCodec.create(VldBase64.create().urlSafeMode(), VldUint8Array.create(), {
798
- decode: base64ToUint8Array,
799
- encode: uint8ArrayToBase64Url
800
- });
801
- /**
802
- * Hexadecimal to Uint8Array codec
803
- */
804
- const hexToBytes = VldCodec.create(VldHex.create(), VldUint8Array.create(), {
805
- decode: hexToUint8Array,
806
- encode: uint8ArrayToHex
807
- });
808
- /**
809
- * Lowercase hexadecimal to Uint8Array codec
810
- */
811
- const hexLowerToBytes = VldCodec.create(VldHex.create().lowercaseMode(), VldUint8Array.create(), {
812
- decode: hexToUint8Array,
813
- encode: (bytes) => uint8ArrayToHex(bytes).toLowerCase()
814
- });
815
- /**
816
- * UTF-8 string to Uint8Array codec
817
- */
818
- const utf8ToBytes = VldCodec.create(VldString.create(), VldUint8Array.create(), {
819
- decode: stringToUint8Array,
820
- encode: uint8ArrayToString
821
- });
822
- /**
823
- * Uint8Array to UTF-8 string codec (reverse of utf8ToBytes)
824
- */
825
- const bytesToUtf8 = VldCodec.create(VldUint8Array.create(), VldString.create(), {
826
- decode: uint8ArrayToString,
827
- encode: stringToUint8Array
828
- });
829
- /**
830
- * Base64URL to Uint8Array codec (updated)
831
- */
832
- const base64urlToBytes = VldCodec.create(VldBase64.create().urlSafeMode(), VldUint8Array.create(), {
833
- decode: base64ToUint8Array,
834
- encode: uint8ArrayToBase64Url
835
- });
836
- /**
837
- * Base64 encoded JSON codec (updated)
838
- */
839
- const base64Json = (schema) => {
840
- const outputSchema = schema || VldUnknown.create();
841
- return VldCodec.create(VldBase64.create(), outputSchema, {
842
- decode: (base64) => {
843
- // BUG-NPM-005 FIX: Add error handling for JSON parsing
844
- try {
845
- const jsonString = uint8ArrayToString(base64ToUint8Array(base64));
846
- return JSON.parse(jsonString);
847
- }
848
- catch (error) {
849
- throw new Error(`Failed to parse base64 JSON: ${error.message}`);
850
- }
851
- },
852
- encode: (data) => {
853
- const jsonString = JSON.stringify(data);
854
- return uint8ArrayToBase64(stringToUint8Array(jsonString));
855
- }
856
- });
857
- };
858
- /**
859
- * JWT payload decoder (base64url encoded JSON) - updated
860
- */
861
- const jwtPayload = (schema) => {
862
- const outputSchema = schema || VldUnknown.create();
863
- return VldCodec.create(VldString.create().refine(s => s.split('.').length === 3, 'Invalid JWT format'), outputSchema, {
864
- decode: (jwt) => {
865
- // BUG-NPM-004 FIX: Add comprehensive error handling for JWT parsing
866
- try {
867
- const parts = jwt.split('.');
868
- if (parts.length !== 3) {
869
- throw new Error('JWT must have exactly 3 parts');
870
- }
871
- const payloadBase64 = parts[1];
872
- if (!payloadBase64) {
873
- throw new Error('JWT payload is empty');
874
- }
875
- // Convert base64url to base64
876
- const base64 = payloadBase64
877
- .replace(/-/g, '+')
878
- .replace(/_/g, '/')
879
- .padEnd(payloadBase64.length + (4 - payloadBase64.length % 4) % 4, '=');
880
- const jsonString = uint8ArrayToString(base64ToUint8Array(base64));
881
- return JSON.parse(jsonString);
882
- }
883
- catch (error) {
884
- throw new Error(`Failed to decode JWT payload: ${error.message}`);
885
- }
886
- },
887
- encode: () => {
888
- throw new Error('JWT encoding not supported - use a proper JWT library');
889
- }
890
- });
891
- };
892
-
893
- export { uint8ArrayToBase64Url as A, uint8ArrayToHex as B, uint8ArrayToString as C, uriComponent as D, utf8ToBytes as E, VldCodec as V, VldUint8Array as a, VldHex as b, VldBase64 as c, base64Json as d, base64ToBytes as e, base64ToUint8Array as f, base64UrlToBytes as g, base64urlToBytes as h, bytesToUtf8 as i, epochMillisToDate as j, epochSecondsToDate as k, hexLowerToBytes as l, hexToBytes as m, hexToUint8Array as n, isoDatetimeToDate as o, jsonCodec as p, jwtPayload as q, numberToBigInt as r, stringToBigInt as s, stringToBoolean as t, stringToHttpURL as u, stringToInt as v, stringToNumber as w, stringToURL as x, stringToUint8Array as y, uint8ArrayToBase64 as z };
894
- //# sourceMappingURL=index-DO8CFMxD.js.map