@oxog/vld 2.0.3 → 2.1.0

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 (449) hide show
  1. package/CHANGELOG.md +33 -1
  2. package/README.md +101 -37
  3. package/dist/chunks/errors-core-BeiFUtZM.js +81 -0
  4. package/dist/chunks/{index-DO8CFMxD.js → index-0R2ntSud.js} +16 -402
  5. package/dist/chunks/index-BvH403Yy.js +88 -0
  6. package/dist/chunks/security-B0Pd_vSY.js +35 -0
  7. package/dist/chunks/string-BJRQod3t.js +530 -0
  8. package/dist/cjs/chunks/errors-core-DWxLFs2f.cjs +83 -0
  9. package/dist/cjs/chunks/index-BkI37108.cjs +538 -0
  10. package/dist/cjs/chunks/index-Cc3bjUMX.cjs +91 -0
  11. package/dist/cjs/chunks/security-Dc3Jh13T.cjs +37 -0
  12. package/dist/cjs/chunks/string-BKZrc4hs.cjs +533 -0
  13. package/dist/cjs/cli/bin.cjs +506 -0
  14. package/dist/cjs/cli/index.cjs +209 -0
  15. package/dist/cjs/codecs/index.cjs +45 -0
  16. package/dist/{chunks/date-50JV_Mfj.js → cjs/coercion/index.cjs} +185 -103
  17. package/dist/cjs/compat/emitter.cjs +184 -0
  18. package/dist/cjs/compat/result.cjs +189 -0
  19. package/dist/cjs/errors.cjs +6 -213
  20. package/dist/cjs/index.cjs +1471 -10336
  21. package/dist/cjs/kernel.cjs +415 -0
  22. package/dist/cjs/locales/af.cjs +108 -0
  23. package/dist/cjs/locales/ar.cjs +108 -0
  24. package/dist/cjs/locales/bn.cjs +108 -0
  25. package/dist/cjs/locales/da.cjs +108 -0
  26. package/dist/cjs/locales/de.cjs +108 -0
  27. package/dist/cjs/locales/en.cjs +108 -0
  28. package/dist/cjs/locales/es-MX.cjs +107 -0
  29. package/dist/cjs/locales/es.cjs +96 -0
  30. package/dist/cjs/locales/fi.cjs +108 -0
  31. package/dist/cjs/locales/fr.cjs +96 -0
  32. package/dist/cjs/locales/hi.cjs +108 -0
  33. package/dist/cjs/locales/id.cjs +108 -0
  34. package/dist/cjs/locales/index.cjs +41 -2875
  35. package/dist/cjs/locales/it.cjs +108 -0
  36. package/dist/cjs/locales/ja.cjs +108 -0
  37. package/dist/cjs/locales/ko.cjs +108 -0
  38. package/dist/cjs/locales/lazy.cjs +42 -3023
  39. package/dist/cjs/locales/nl.cjs +108 -0
  40. package/dist/cjs/locales/no.cjs +108 -0
  41. package/dist/cjs/locales/pl.cjs +108 -0
  42. package/dist/cjs/locales/pt-BR.cjs +108 -0
  43. package/dist/cjs/locales/pt.cjs +108 -0
  44. package/dist/cjs/locales/ru.cjs +108 -0
  45. package/dist/cjs/locales/runtime.cjs +51 -0
  46. package/dist/cjs/locales/sv.cjs +108 -0
  47. package/dist/cjs/locales/sw.cjs +108 -0
  48. package/dist/cjs/locales/th.cjs +108 -0
  49. package/dist/cjs/locales/tr.cjs +108 -0
  50. package/dist/cjs/locales/vi.cjs +108 -0
  51. package/dist/cjs/locales/zh.cjs +108 -0
  52. package/dist/cjs/mini.cjs +121 -7353
  53. package/dist/cjs/pigment.cjs +207 -0
  54. package/dist/cjs/plugins/index.cjs +12 -0
  55. package/dist/cjs/registry.cjs +37 -0
  56. package/dist/cjs/v3/index.cjs +425 -0
  57. package/dist/cjs/v4/core/index.cjs +894 -0
  58. package/dist/cjs/v4/index.cjs +425 -0
  59. package/dist/cjs/v4/locales/index.cjs +130 -0
  60. package/dist/cjs/v4/mini/index.cjs +509 -0
  61. package/dist/cjs/v4-mini/index.cjs +532 -0
  62. package/dist/cjs/validators/any.cjs +40 -0
  63. package/dist/cjs/validators/array.cjs +283 -0
  64. package/dist/cjs/validators/base.cjs +887 -0
  65. package/dist/cjs/validators/base64.cjs +73 -0
  66. package/dist/cjs/validators/bigint.cjs +232 -0
  67. package/dist/cjs/validators/boolean.cjs +146 -0
  68. package/dist/cjs/validators/codec.cjs +205 -0
  69. package/dist/cjs/validators/custom.cjs +71 -0
  70. package/dist/cjs/validators/date.cjs +278 -0
  71. package/dist/cjs/validators/discriminated-union.cjs +130 -0
  72. package/dist/cjs/validators/enum.cjs +154 -0
  73. package/dist/cjs/validators/file.cjs +130 -0
  74. package/dist/cjs/validators/function.cjs +63 -0
  75. package/dist/cjs/validators/hex.cjs +70 -0
  76. package/dist/cjs/validators/index.cjs +123 -0
  77. package/dist/cjs/validators/intersection.cjs +120 -0
  78. package/dist/cjs/validators/json.cjs +70 -0
  79. package/dist/cjs/validators/lazy.cjs +53 -0
  80. package/dist/cjs/validators/literal.cjs +64 -0
  81. package/dist/cjs/validators/map.cjs +218 -0
  82. package/dist/cjs/validators/nan.cjs +41 -0
  83. package/dist/cjs/validators/never.cjs +36 -0
  84. package/dist/cjs/validators/null.cjs +43 -0
  85. package/dist/cjs/validators/number.cjs +427 -0
  86. package/dist/cjs/validators/object.cjs +868 -0
  87. package/dist/cjs/validators/promise.cjs +115 -0
  88. package/dist/cjs/validators/record.cjs +262 -0
  89. package/dist/cjs/validators/set.cjs +203 -0
  90. package/dist/cjs/validators/string-bool.cjs +124 -0
  91. package/dist/cjs/validators/string-formats.cjs +168 -0
  92. package/dist/cjs/validators/string.cjs +12 -0
  93. package/dist/cjs/validators/symbol.cjs +62 -0
  94. package/dist/cjs/validators/template-literal.cjs +108 -0
  95. package/dist/cjs/validators/tuple.cjs +187 -0
  96. package/dist/cjs/validators/uint8array.cjs +106 -0
  97. package/dist/cjs/validators/undefined.cjs +43 -0
  98. package/dist/cjs/validators/union.cjs +191 -0
  99. package/dist/cjs/validators/unknown.cjs +40 -0
  100. package/dist/cjs/validators/void.cjs +48 -0
  101. package/dist/cjs/validators/xor.cjs +69 -0
  102. package/dist/cli/bin.d.ts +0 -1
  103. package/dist/cli/bin.js +407 -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 +205 -0
  108. package/dist/codecs/index.d.ts +21 -4
  109. package/dist/codecs/index.js +11 -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 +473 -5
  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 +0 -1
  119. package/dist/compat/index.d.ts +4 -5
  120. package/dist/compat/result.d.ts +1 -2
  121. package/dist/compat/result.js +0 -1
  122. package/dist/errors-core.d.ts +39 -0
  123. package/dist/errors.d.ts +4 -54
  124. package/dist/errors.js +4 -68
  125. package/dist/events.d.ts +3 -4
  126. package/dist/index.d.ts +1186 -835
  127. package/dist/index.js +1046 -367
  128. package/dist/kernel.d.ts +2 -3
  129. package/dist/kernel.js +10 -6
  130. package/dist/locales/af.d.ts +1 -2
  131. package/dist/locales/af.js +0 -1
  132. package/dist/locales/ar.d.ts +1 -2
  133. package/dist/locales/ar.js +0 -1
  134. package/dist/locales/bn.d.ts +1 -2
  135. package/dist/locales/bn.js +0 -1
  136. package/dist/locales/da.d.ts +1 -2
  137. package/dist/locales/da.js +0 -1
  138. package/dist/locales/de.d.ts +1 -2
  139. package/dist/locales/de.js +0 -1
  140. package/dist/locales/en.d.ts +1 -2
  141. package/dist/locales/en.js +0 -1
  142. package/dist/locales/es-MX.d.ts +1 -2
  143. package/dist/locales/es-MX.js +0 -1
  144. package/dist/locales/es.d.ts +1 -2
  145. package/dist/locales/es.js +0 -1
  146. package/dist/locales/fi.d.ts +1 -2
  147. package/dist/locales/fi.js +0 -1
  148. package/dist/locales/fr.d.ts +1 -2
  149. package/dist/locales/fr.js +0 -1
  150. package/dist/locales/hi.d.ts +1 -2
  151. package/dist/locales/hi.js +0 -1
  152. package/dist/locales/id.d.ts +1 -2
  153. package/dist/locales/id.js +0 -1
  154. package/dist/locales/index.d.ts +10 -15
  155. package/dist/locales/index.js +28 -2
  156. package/dist/locales/it.d.ts +1 -2
  157. package/dist/locales/it.js +0 -1
  158. package/dist/locales/ja.d.ts +1 -2
  159. package/dist/locales/ja.js +0 -1
  160. package/dist/locales/ko.d.ts +1 -2
  161. package/dist/locales/ko.js +0 -1
  162. package/dist/locales/lazy.d.ts +4 -26
  163. package/dist/locales/lazy.js +12 -55
  164. package/dist/locales/nl.d.ts +1 -2
  165. package/dist/locales/nl.js +0 -1
  166. package/dist/locales/no.d.ts +1 -2
  167. package/dist/locales/no.js +0 -1
  168. package/dist/locales/pl.d.ts +1 -2
  169. package/dist/locales/pl.js +0 -1
  170. package/dist/locales/pt-BR.d.ts +1 -2
  171. package/dist/locales/pt-BR.js +0 -1
  172. package/dist/locales/pt.d.ts +1 -2
  173. package/dist/locales/pt.js +0 -1
  174. package/dist/locales/ru.d.ts +1 -2
  175. package/dist/locales/ru.js +0 -1
  176. package/dist/locales/runtime.d.ts +10 -0
  177. package/dist/locales/runtime.js +41 -0
  178. package/dist/locales/sv.d.ts +1 -2
  179. package/dist/locales/sv.js +0 -1
  180. package/dist/locales/sw.d.ts +1 -2
  181. package/dist/locales/sw.js +0 -1
  182. package/dist/locales/th.d.ts +1 -2
  183. package/dist/locales/th.js +0 -1
  184. package/dist/locales/tr.d.ts +1 -2
  185. package/dist/locales/tr.js +0 -1
  186. package/dist/locales/types.d.ts +0 -1
  187. package/dist/locales/vi.d.ts +1 -2
  188. package/dist/locales/vi.js +0 -1
  189. package/dist/locales/zh.d.ts +1 -2
  190. package/dist/locales/zh.js +0 -1
  191. package/dist/logger.d.ts +0 -1
  192. package/dist/mini.d.ts +64 -65
  193. package/dist/mini.js +31 -7
  194. package/dist/pigment.d.ts +0 -1
  195. package/dist/pigment.js +6 -4
  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 +34 -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 +16 -6
  205. package/dist/utils/security.d.ts +2 -6
  206. package/dist/v3/index.d.ts +2 -0
  207. package/dist/v3/index.js +46 -0
  208. package/dist/v4/core/index.d.ts +260 -0
  209. package/dist/v4/core/index.js +277 -0
  210. package/dist/v4/index.d.ts +4 -0
  211. package/dist/v4/index.js +50 -0
  212. package/dist/v4/locales/index.d.ts +53 -0
  213. package/dist/v4/locales/index.js +77 -0
  214. package/dist/v4/mini/index.d.ts +2 -0
  215. package/dist/v4/mini/index.js +47 -0
  216. package/dist/v4-mini/index.d.ts +22 -0
  217. package/dist/v4-mini/index.js +75 -0
  218. package/dist/validators/any.d.ts +7 -2
  219. package/dist/validators/any.js +37 -0
  220. package/dist/validators/array.d.ts +9 -2
  221. package/dist/validators/array.js +279 -0
  222. package/dist/validators/base.d.ts +150 -6
  223. package/dist/validators/base.js +868 -0
  224. package/dist/validators/base64.d.ts +1 -2
  225. package/dist/validators/base64.js +68 -0
  226. package/dist/validators/bigint.d.ts +21 -3
  227. package/dist/validators/bigint.js +228 -0
  228. package/dist/validators/boolean.d.ts +13 -4
  229. package/dist/validators/boolean.js +142 -0
  230. package/dist/validators/codec.d.ts +9 -2
  231. package/dist/validators/codec.js +200 -0
  232. package/dist/validators/custom.d.ts +15 -2
  233. package/dist/validators/custom.js +67 -0
  234. package/dist/validators/date.d.ts +19 -3
  235. package/dist/validators/date.js +274 -0
  236. package/dist/validators/discriminated-union.d.ts +4 -3
  237. package/dist/validators/discriminated-union.js +123 -0
  238. package/dist/validators/enum.d.ts +10 -7
  239. package/dist/validators/enum.js +150 -0
  240. package/dist/validators/file.d.ts +7 -2
  241. package/dist/validators/file.js +125 -0
  242. package/dist/validators/function.d.ts +11 -5
  243. package/dist/validators/function.js +58 -0
  244. package/dist/validators/hex.d.ts +1 -2
  245. package/dist/validators/hex.js +65 -0
  246. package/dist/validators/index.d.ts +38 -39
  247. package/dist/validators/index.js +35 -515
  248. package/dist/validators/intersection.d.ts +1 -2
  249. package/dist/validators/intersection.js +116 -0
  250. package/dist/validators/json.d.ts +1 -2
  251. package/dist/validators/json.js +66 -0
  252. package/dist/validators/lazy.d.ts +5 -9
  253. package/dist/validators/lazy.js +50 -0
  254. package/dist/validators/literal.d.ts +2 -2
  255. package/dist/validators/literal.js +60 -0
  256. package/dist/validators/map.d.ts +15 -2
  257. package/dist/validators/map.js +214 -0
  258. package/dist/validators/nan.d.ts +2 -3
  259. package/dist/validators/nan.js +38 -0
  260. package/dist/validators/never.d.ts +1 -2
  261. package/dist/validators/never.js +32 -0
  262. package/dist/validators/null.d.ts +3 -3
  263. package/dist/validators/null.js +40 -0
  264. package/dist/validators/number.d.ts +56 -27
  265. package/dist/validators/number.js +423 -0
  266. package/dist/validators/object.d.ts +30 -9
  267. package/dist/validators/object.js +864 -0
  268. package/dist/validators/promise.d.ts +15 -10
  269. package/dist/validators/promise.js +111 -0
  270. package/dist/validators/record.d.ts +11 -2
  271. package/dist/validators/record.js +258 -0
  272. package/dist/validators/set.d.ts +11 -2
  273. package/dist/validators/set.js +199 -0
  274. package/dist/validators/string-bool.d.ts +7 -10
  275. package/dist/validators/string-bool.js +120 -0
  276. package/dist/validators/string-formats.d.ts +7 -4
  277. package/dist/validators/string-formats.js +135 -0
  278. package/dist/validators/string.d.ts +39 -18
  279. package/dist/validators/string.js +4 -0
  280. package/dist/validators/symbol.d.ts +8 -3
  281. package/dist/validators/symbol.js +58 -0
  282. package/dist/validators/template-literal.d.ts +1 -2
  283. package/dist/validators/template-literal.js +103 -0
  284. package/dist/validators/tuple.d.ts +15 -2
  285. package/dist/validators/tuple.js +183 -0
  286. package/dist/validators/uint8array.d.ts +3 -4
  287. package/dist/validators/uint8array.js +101 -0
  288. package/dist/validators/undefined.d.ts +3 -3
  289. package/dist/validators/undefined.js +40 -0
  290. package/dist/validators/union.d.ts +7 -4
  291. package/dist/validators/union.js +187 -0
  292. package/dist/validators/unknown.d.ts +7 -2
  293. package/dist/{chunks/unknown-Dhzri_T-.js → validators/unknown.js} +12 -3
  294. package/dist/validators/void.d.ts +3 -2
  295. package/dist/validators/void.js +44 -0
  296. package/dist/validators/xor.d.ts +2 -3
  297. package/dist/validators/xor.js +66 -0
  298. package/package.json +114 -30
  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.map +0 -1
  302. package/dist/chunks/index-DO8CFMxD.js.map +0 -1
  303. package/dist/chunks/json-Cp4WO0M9.js +0 -2021
  304. package/dist/chunks/json-Cp4WO0M9.js.map +0 -1
  305. package/dist/chunks/unknown-Dhzri_T-.js.map +0 -1
  306. package/dist/cjs/errors.cjs.map +0 -1
  307. package/dist/cjs/index.cjs.map +0 -1
  308. package/dist/cjs/locales/index.cjs.map +0 -1
  309. package/dist/cjs/locales/lazy.cjs.map +0 -1
  310. package/dist/cjs/mini.cjs.map +0 -1
  311. package/dist/cli/bin.d.ts.map +0 -1
  312. package/dist/cli/commands/benchmark.d.ts.map +0 -1
  313. package/dist/cli/commands/validate.d.ts.map +0 -1
  314. package/dist/cli/index.d.ts.map +0 -1
  315. package/dist/codecs/index.d.ts.map +0 -1
  316. package/dist/codecs/index.js.map +0 -1
  317. package/dist/coercion/bigint.d.ts.map +0 -1
  318. package/dist/coercion/boolean.d.ts.map +0 -1
  319. package/dist/coercion/date.d.ts.map +0 -1
  320. package/dist/coercion/index.d.ts.map +0 -1
  321. package/dist/coercion/index.js.map +0 -1
  322. package/dist/coercion/number.d.ts.map +0 -1
  323. package/dist/coercion/string.d.ts.map +0 -1
  324. package/dist/compat/emitter.d.ts.map +0 -1
  325. package/dist/compat/emitter.js.map +0 -1
  326. package/dist/compat/index.d.ts.map +0 -1
  327. package/dist/compat/result.d.ts.map +0 -1
  328. package/dist/compat/result.js.map +0 -1
  329. package/dist/errors.d.ts.map +0 -1
  330. package/dist/errors.js.map +0 -1
  331. package/dist/events.d.ts.map +0 -1
  332. package/dist/index.d.ts.map +0 -1
  333. package/dist/index.js.map +0 -1
  334. package/dist/kernel.d.ts.map +0 -1
  335. package/dist/kernel.js.map +0 -1
  336. package/dist/locales/af.d.ts.map +0 -1
  337. package/dist/locales/af.js.map +0 -1
  338. package/dist/locales/ar.d.ts.map +0 -1
  339. package/dist/locales/ar.js.map +0 -1
  340. package/dist/locales/backup-en.d.ts +0 -3
  341. package/dist/locales/backup-en.d.ts.map +0 -1
  342. package/dist/locales/bn.d.ts.map +0 -1
  343. package/dist/locales/bn.js.map +0 -1
  344. package/dist/locales/da.d.ts.map +0 -1
  345. package/dist/locales/da.js.map +0 -1
  346. package/dist/locales/de.d.ts.map +0 -1
  347. package/dist/locales/de.js.map +0 -1
  348. package/dist/locales/en.d.ts.map +0 -1
  349. package/dist/locales/en.js.map +0 -1
  350. package/dist/locales/es-MX.d.ts.map +0 -1
  351. package/dist/locales/es-MX.js.map +0 -1
  352. package/dist/locales/es.d.ts.map +0 -1
  353. package/dist/locales/es.js.map +0 -1
  354. package/dist/locales/fi.d.ts.map +0 -1
  355. package/dist/locales/fi.js.map +0 -1
  356. package/dist/locales/fr.d.ts.map +0 -1
  357. package/dist/locales/fr.js.map +0 -1
  358. package/dist/locales/hi.d.ts.map +0 -1
  359. package/dist/locales/hi.js.map +0 -1
  360. package/dist/locales/id.d.ts.map +0 -1
  361. package/dist/locales/id.js.map +0 -1
  362. package/dist/locales/index.d.ts.map +0 -1
  363. package/dist/locales/index.js.map +0 -1
  364. package/dist/locales/it.d.ts.map +0 -1
  365. package/dist/locales/it.js.map +0 -1
  366. package/dist/locales/ja.d.ts.map +0 -1
  367. package/dist/locales/ja.js.map +0 -1
  368. package/dist/locales/ko.d.ts.map +0 -1
  369. package/dist/locales/ko.js.map +0 -1
  370. package/dist/locales/lazy.d.ts.map +0 -1
  371. package/dist/locales/lazy.js.map +0 -1
  372. package/dist/locales/nl.d.ts.map +0 -1
  373. package/dist/locales/nl.js.map +0 -1
  374. package/dist/locales/no.d.ts.map +0 -1
  375. package/dist/locales/no.js.map +0 -1
  376. package/dist/locales/pl.d.ts.map +0 -1
  377. package/dist/locales/pl.js.map +0 -1
  378. package/dist/locales/pt-BR.d.ts.map +0 -1
  379. package/dist/locales/pt-BR.js.map +0 -1
  380. package/dist/locales/pt.d.ts.map +0 -1
  381. package/dist/locales/pt.js.map +0 -1
  382. package/dist/locales/ru.d.ts.map +0 -1
  383. package/dist/locales/ru.js.map +0 -1
  384. package/dist/locales/sv.d.ts.map +0 -1
  385. package/dist/locales/sv.js.map +0 -1
  386. package/dist/locales/sw.d.ts.map +0 -1
  387. package/dist/locales/sw.js.map +0 -1
  388. package/dist/locales/th.d.ts.map +0 -1
  389. package/dist/locales/th.js.map +0 -1
  390. package/dist/locales/tr.d.ts.map +0 -1
  391. package/dist/locales/tr.js.map +0 -1
  392. package/dist/locales/types.d.ts.map +0 -1
  393. package/dist/locales/vi.d.ts.map +0 -1
  394. package/dist/locales/vi.js.map +0 -1
  395. package/dist/locales/zh.d.ts.map +0 -1
  396. package/dist/locales/zh.js.map +0 -1
  397. package/dist/logger.d.ts.map +0 -1
  398. package/dist/mini.d.ts.map +0 -1
  399. package/dist/mini.js.map +0 -1
  400. package/dist/pigment.d.ts.map +0 -1
  401. package/dist/pigment.js.map +0 -1
  402. package/dist/plugins/index.d.ts.map +0 -1
  403. package/dist/plugins/types.d.ts.map +0 -1
  404. package/dist/utils/codec-utils.d.ts.map +0 -1
  405. package/dist/utils/deep-merge.d.ts.map +0 -1
  406. package/dist/utils/ip-validation.d.ts.map +0 -1
  407. package/dist/utils/json-schema.d.ts.map +0 -1
  408. package/dist/utils/security.d.ts.map +0 -1
  409. package/dist/validators/any.d.ts.map +0 -1
  410. package/dist/validators/array.d.ts.map +0 -1
  411. package/dist/validators/base.d.ts.map +0 -1
  412. package/dist/validators/base64.d.ts.map +0 -1
  413. package/dist/validators/bigint.d.ts.map +0 -1
  414. package/dist/validators/boolean.d.ts.map +0 -1
  415. package/dist/validators/codec.d.ts.map +0 -1
  416. package/dist/validators/custom.d.ts.map +0 -1
  417. package/dist/validators/date.d.ts.map +0 -1
  418. package/dist/validators/discriminated-union.d.ts.map +0 -1
  419. package/dist/validators/enum.d.ts.map +0 -1
  420. package/dist/validators/file.d.ts.map +0 -1
  421. package/dist/validators/function.d.ts.map +0 -1
  422. package/dist/validators/hex.d.ts.map +0 -1
  423. package/dist/validators/index.d.ts.map +0 -1
  424. package/dist/validators/index.js.map +0 -1
  425. package/dist/validators/intersection.d.ts.map +0 -1
  426. package/dist/validators/json.d.ts.map +0 -1
  427. package/dist/validators/lazy.d.ts.map +0 -1
  428. package/dist/validators/literal.d.ts.map +0 -1
  429. package/dist/validators/map.d.ts.map +0 -1
  430. package/dist/validators/nan.d.ts.map +0 -1
  431. package/dist/validators/never.d.ts.map +0 -1
  432. package/dist/validators/null.d.ts.map +0 -1
  433. package/dist/validators/number.d.ts.map +0 -1
  434. package/dist/validators/object.d.ts.map +0 -1
  435. package/dist/validators/promise.d.ts.map +0 -1
  436. package/dist/validators/record.d.ts.map +0 -1
  437. package/dist/validators/set.d.ts.map +0 -1
  438. package/dist/validators/string-bool.d.ts.map +0 -1
  439. package/dist/validators/string-formats.d.ts.map +0 -1
  440. package/dist/validators/string.d.ts.map +0 -1
  441. package/dist/validators/symbol.d.ts.map +0 -1
  442. package/dist/validators/template-literal.d.ts.map +0 -1
  443. package/dist/validators/tuple.d.ts.map +0 -1
  444. package/dist/validators/uint8array.d.ts.map +0 -1
  445. package/dist/validators/undefined.d.ts.map +0 -1
  446. package/dist/validators/union.d.ts.map +0 -1
  447. package/dist/validators/unknown.d.ts.map +0 -1
  448. package/dist/validators/void.d.ts.map +0 -1
  449. package/dist/validators/xor.d.ts.map +0 -1
@@ -0,0 +1,115 @@
1
+ 'use strict';
2
+
3
+ var validators_base = require('./base.cjs');
4
+ require('../registry.cjs');
5
+
6
+ /**
7
+ * Promise validator - validates Promise values
8
+ * Validates that the resolved value matches the inner schema
9
+ */
10
+ /**
11
+ * Promise validator - validates Promise<T> where T matches inner schema
12
+ * Zod 4 API parity - allows async validation with proper type inference
13
+ *
14
+ * Validates that the input is a Promise, and validates the resolved value
15
+ * against the inner schema when parsed.
16
+ *
17
+ * Use parseAsync() or safeParseAsync() for proper async handling.
18
+ */
19
+ class VldPromise {
20
+ constructor(inner) {
21
+ this.inner = inner;
22
+ this.validatorType = validators_base.VLD_VALIDATOR_TYPES.PROMISE;
23
+ }
24
+ get '~standard'() {
25
+ return {
26
+ version: 1,
27
+ vendor: 'vld',
28
+ validate: async (value) => {
29
+ const result = await this.safeParseAsync(value);
30
+ if (result.success) {
31
+ return { value: result.data };
32
+ }
33
+ return { issues: [{ message: result.error.message }] };
34
+ },
35
+ types: undefined
36
+ };
37
+ }
38
+ /**
39
+ * Check if value is thenable (Promise-like)
40
+ * Must be called BEFORE wrapping in Promise.resolve
41
+ */
42
+ _isThenable(value) {
43
+ return value !== null && typeof value.then === 'function';
44
+ }
45
+ unwrap() {
46
+ return this.inner;
47
+ }
48
+ /**
49
+ * Parse and validate a Promise value asynchronously
50
+ * @param value The Promise to validate
51
+ * @returns The validated value
52
+ * @throws {Error} If validation fails when Promise resolves
53
+ */
54
+ async parse(value) {
55
+ // Check if value is thenable BEFORE wrapping in Promise.resolve
56
+ if (!this._isThenable(value)) {
57
+ throw new Error('Expected a Promise value');
58
+ }
59
+ // Now we can safely await it
60
+ const resolved = await Promise.resolve(value);
61
+ return this.inner.parseAsync ? this.inner.parseAsync(resolved) : this.inner.parse(resolved);
62
+ }
63
+ parseAsync(value) {
64
+ return this.parse(value);
65
+ }
66
+ /**
67
+ * Safely parse and validate a Promise value asynchronously
68
+ * @param value The Promise to validate
69
+ * @returns A Promise resolving to ParseResult containing the validated value
70
+ */
71
+ async safeParse(value) {
72
+ // Check if value is thenable BEFORE wrapping in Promise.resolve
73
+ if (!this._isThenable(value)) {
74
+ return {
75
+ success: false,
76
+ error: new Error('Expected a Promise value')
77
+ };
78
+ }
79
+ try {
80
+ const resolved = await Promise.resolve(value);
81
+ if (this.inner.safeParseAsync) {
82
+ return await this.inner.safeParseAsync(resolved);
83
+ }
84
+ const innerResult = this.inner.safeParse(resolved);
85
+ if (!innerResult.success) {
86
+ return innerResult;
87
+ }
88
+ return { success: true, data: innerResult.data };
89
+ }
90
+ catch (err) {
91
+ return {
92
+ success: false,
93
+ error: err instanceof Error ? err : new Error(String(err))
94
+ };
95
+ }
96
+ }
97
+ safeParseAsync(value) {
98
+ return this.safeParse(value);
99
+ }
100
+ }
101
+ /**
102
+ * Create a Promise validator
103
+ * @param inner The schema to validate the resolved value against
104
+ * @returns A new Promise validator
105
+ * @example
106
+ * const promiseSchema = v.promise(v.string());
107
+ * const result = await promiseSchema.parse(Promise.resolve("hello"));
108
+ * // result is string
109
+ */
110
+ function promise(inner) {
111
+ return new VldPromise(inner);
112
+ }
113
+
114
+ exports.VldPromise = VldPromise;
115
+ exports.promise = promise;
@@ -0,0 +1,262 @@
1
+ 'use strict';
2
+
3
+ var validators_base = require('./base.cjs');
4
+ var locales_runtime = require('../locales/runtime.cjs');
5
+ var security = require('../chunks/security-Dc3Jh13T.cjs');
6
+ var errorsCore = require('../chunks/errors-core-DWxLFs2f.cjs');
7
+ require('../registry.cjs');
8
+ require('../locales/en.cjs');
9
+
10
+ function createRecordError(message) {
11
+ return new errorsCore.VldError([{ code: 'invalid_object', path: [], message }]);
12
+ }
13
+ /**
14
+ * Immutable record validator for key-value pairs
15
+ * BUG-NEW-018 FIX: Uses comprehensive dangerous key protection
16
+ */
17
+ class VldRecord extends validators_base.VldBase {
18
+ /**
19
+ * Private constructor to enforce immutability
20
+ */
21
+ constructor(valueValidator, errorMessage) {
22
+ super(validators_base.VLD_VALIDATOR_TYPES.RECORD);
23
+ this.valueValidator = valueValidator;
24
+ this.errorMessage = errorMessage;
25
+ this._simpleValueMode = this.getSimpleValueMode(valueValidator);
26
+ this._simpleValue = this._simpleValueMode === 'literal' ? valueValidator.literal : undefined;
27
+ }
28
+ get valueSchema() {
29
+ return this.valueValidator;
30
+ }
31
+ /**
32
+ * Create a new record validator
33
+ */
34
+ static create(valueValidator) {
35
+ return new VldRecord(valueValidator);
36
+ }
37
+ getSimpleValueMode(valueValidator) {
38
+ if (valueValidator.isSimple !== true) {
39
+ return undefined;
40
+ }
41
+ switch (valueValidator.validatorType) {
42
+ case validators_base.VLD_VALIDATOR_TYPES.STRING:
43
+ return 'string';
44
+ case validators_base.VLD_VALIDATOR_TYPES.NUMBER:
45
+ return 'number';
46
+ case validators_base.VLD_VALIDATOR_TYPES.BOOLEAN:
47
+ return 'boolean';
48
+ case validators_base.VLD_VALIDATOR_TYPES.BIGINT:
49
+ return 'bigint';
50
+ case validators_base.VLD_VALIDATOR_TYPES.SYMBOL:
51
+ return 'symbol';
52
+ case validators_base.VLD_VALIDATOR_TYPES.NULL:
53
+ return 'null';
54
+ case validators_base.VLD_VALIDATOR_TYPES.UNDEFINED:
55
+ case validators_base.VLD_VALIDATOR_TYPES.VOID:
56
+ return 'undefinedValue';
57
+ case validators_base.VLD_VALIDATOR_TYPES.LITERAL:
58
+ return 'literal';
59
+ case validators_base.VLD_VALIDATOR_TYPES.ANY:
60
+ case validators_base.VLD_VALIDATOR_TYPES.UNKNOWN:
61
+ return 'passthrough';
62
+ default:
63
+ return undefined;
64
+ }
65
+ }
66
+ getSimpleValueError(received) {
67
+ switch (this._simpleValueMode) {
68
+ case 'string':
69
+ return locales_runtime.getMessages().invalidString;
70
+ case 'number':
71
+ return locales_runtime.getMessages().invalidNumber;
72
+ case 'boolean':
73
+ return locales_runtime.getMessages().invalidBoolean;
74
+ case 'bigint':
75
+ return locales_runtime.getMessages().invalidBigint;
76
+ case 'symbol':
77
+ return locales_runtime.getMessages().invalidSymbol;
78
+ case 'null':
79
+ return `Expected null, received ${typeof received}`;
80
+ case 'undefinedValue':
81
+ return locales_runtime.getMessages().expectedUndefined;
82
+ case 'literal':
83
+ return locales_runtime.getMessages().literalExpected(JSON.stringify(this._simpleValue), JSON.stringify(received));
84
+ default:
85
+ return locales_runtime.getMessages().invalidRecord;
86
+ }
87
+ }
88
+ /**
89
+ * Parse and validate a record value
90
+ * BUG-NEW-018 FIX: Use comprehensive dangerous key protection
91
+ */
92
+ parse(value) {
93
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
94
+ throw new Error(this.errorMessage || locales_runtime.getMessages().invalidRecord);
95
+ }
96
+ return this.parseKnownRecord(value);
97
+ }
98
+ /**
99
+ * Parse a value that has already passed the record object type guard.
100
+ * @internal Used by object validators to avoid duplicate hot-path checks.
101
+ */
102
+ parseKnownRecord(obj) {
103
+ const result = {};
104
+ const keys = Object.keys(obj);
105
+ const simpleMode = this._simpleValueMode;
106
+ for (let i = 0; i < keys.length; i++) {
107
+ const key = keys[i];
108
+ // Skip dangerous keys to prevent prototype pollution
109
+ // Now using comprehensive protection from shared utility
110
+ if (security.isDangerousKey(key)) {
111
+ continue;
112
+ }
113
+ const val = obj[key];
114
+ if (simpleMode !== undefined) {
115
+ switch (simpleMode) {
116
+ case 'string':
117
+ if (typeof val !== 'string') {
118
+ throw new Error(locales_runtime.getMessages().objectField(key, locales_runtime.getMessages().invalidString));
119
+ }
120
+ result[key] = val;
121
+ continue;
122
+ case 'number':
123
+ if (typeof val !== 'number' || isNaN(val)) {
124
+ throw new Error(locales_runtime.getMessages().objectField(key, locales_runtime.getMessages().invalidNumber));
125
+ }
126
+ result[key] = val;
127
+ continue;
128
+ case 'boolean':
129
+ if (typeof val !== 'boolean') {
130
+ throw new Error(locales_runtime.getMessages().objectField(key, locales_runtime.getMessages().invalidBoolean));
131
+ }
132
+ result[key] = val;
133
+ continue;
134
+ case 'bigint':
135
+ if (typeof val !== 'bigint') {
136
+ throw new Error(locales_runtime.getMessages().objectField(key, locales_runtime.getMessages().invalidBigint));
137
+ }
138
+ result[key] = val;
139
+ continue;
140
+ case 'symbol':
141
+ if (typeof val !== 'symbol') {
142
+ throw new Error(locales_runtime.getMessages().objectField(key, locales_runtime.getMessages().invalidSymbol));
143
+ }
144
+ result[key] = val;
145
+ continue;
146
+ case 'null':
147
+ if (val !== null) {
148
+ throw new Error(locales_runtime.getMessages().objectField(key, this.getSimpleValueError(val)));
149
+ }
150
+ result[key] = null;
151
+ continue;
152
+ case 'undefinedValue':
153
+ if (val !== undefined) {
154
+ throw new Error(locales_runtime.getMessages().objectField(key, locales_runtime.getMessages().expectedUndefined));
155
+ }
156
+ result[key] = undefined;
157
+ continue;
158
+ case 'literal':
159
+ if (val !== this._simpleValue) {
160
+ throw new Error(locales_runtime.getMessages().objectField(key, this.getSimpleValueError(val)));
161
+ }
162
+ result[key] = this._simpleValue;
163
+ continue;
164
+ case 'passthrough':
165
+ result[key] = val;
166
+ continue;
167
+ }
168
+ }
169
+ try {
170
+ result[key] = this.valueValidator.parse(val);
171
+ }
172
+ catch (error) {
173
+ throw new Error(locales_runtime.getMessages().objectField(key, error.message));
174
+ }
175
+ }
176
+ return result;
177
+ }
178
+ /**
179
+ * Safely parse and validate a record value
180
+ */
181
+ safeParse(value) {
182
+ try {
183
+ return { success: true, data: this.parse(value) };
184
+ }
185
+ catch (error) {
186
+ return { success: false, error: createRecordError(error.message) };
187
+ }
188
+ }
189
+ /**
190
+ * Create a partial record variant (all keys optional)
191
+ * Similar to v.object().partial() but for records
192
+ */
193
+ partial() {
194
+ const optionalValidator = this.valueValidator.optional();
195
+ return new VldRecord(optionalValidator);
196
+ }
197
+ /**
198
+ * Create a loose record variant (allows extra keys)
199
+ * Similar to v.object().passthrough() but for records
200
+ * Note: Records already allow any keys, so this mainly affects error handling
201
+ */
202
+ loose() {
203
+ // For records, "loose" means we don't throw errors for validation failures
204
+ // We return a modified version that catches validation errors
205
+ return new VldLooseRecord(this.valueValidator);
206
+ }
207
+ }
208
+ /**
209
+ * Loose record variant that allows validation failures
210
+ * Used internally by .loose() method
211
+ */
212
+ class VldLooseRecord extends validators_base.VldBase {
213
+ constructor(valueValidator) {
214
+ super(validators_base.VLD_VALIDATOR_TYPES.RECORD);
215
+ this.valueValidator = valueValidator;
216
+ }
217
+ get valueSchema() {
218
+ return this.valueValidator;
219
+ }
220
+ parse(value) {
221
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
222
+ throw new Error(locales_runtime.getMessages().invalidRecord);
223
+ }
224
+ const result = {};
225
+ const obj = value;
226
+ for (const [key, val] of Object.entries(obj)) {
227
+ // Skip dangerous keys
228
+ if (security.isDangerousKey(key)) {
229
+ continue;
230
+ }
231
+ // For loose records, skip invalid values instead of throwing
232
+ const parseResult = this.valueValidator.safeParse(val);
233
+ if (parseResult.success) {
234
+ result[key] = parseResult.data;
235
+ }
236
+ }
237
+ return result;
238
+ }
239
+ safeParse(value) {
240
+ try {
241
+ return { success: true, data: this.parse(value) };
242
+ }
243
+ catch (error) {
244
+ return { success: false, error: createRecordError(error.message) };
245
+ }
246
+ }
247
+ /**
248
+ * Create a partial variant (all keys optional)
249
+ */
250
+ partial() {
251
+ const optionalValidator = this.valueValidator.optional();
252
+ return new VldLooseRecord(optionalValidator);
253
+ }
254
+ /**
255
+ * Return self (already loose)
256
+ */
257
+ loose() {
258
+ return this;
259
+ }
260
+ }
261
+
262
+ exports.VldRecord = VldRecord;
@@ -0,0 +1,203 @@
1
+ 'use strict';
2
+
3
+ var validators_base = require('./base.cjs');
4
+ var locales_runtime = require('../locales/runtime.cjs');
5
+ var errorsCore = require('../chunks/errors-core-DWxLFs2f.cjs');
6
+ require('../registry.cjs');
7
+ require('../locales/en.cjs');
8
+
9
+ function createSetError(message) {
10
+ return new errorsCore.VldError([{ code: 'invalid_type', path: [], message }]);
11
+ }
12
+ /**
13
+ * Immutable Set validator
14
+ */
15
+ class VldSet extends validators_base.VldBase {
16
+ /**
17
+ * Private constructor to enforce immutability
18
+ */
19
+ constructor(itemValidator, errorMessage) {
20
+ super(validators_base.VLD_VALIDATOR_TYPES.SET);
21
+ this.itemValidator = itemValidator;
22
+ this.errorMessage = errorMessage;
23
+ this._simpleItemMode = this.getSimpleItemMode(itemValidator);
24
+ this._simpleItemValue = this._simpleItemMode === 'literal' ? itemValidator.literal : undefined;
25
+ }
26
+ get itemSchema() {
27
+ return this.itemValidator;
28
+ }
29
+ /**
30
+ * Create a new Set validator
31
+ */
32
+ static create(itemValidator) {
33
+ return new VldSet(itemValidator);
34
+ }
35
+ getSimpleItemMode(itemValidator) {
36
+ if (itemValidator.isSimple !== true) {
37
+ return undefined;
38
+ }
39
+ switch (itemValidator.validatorType) {
40
+ case validators_base.VLD_VALIDATOR_TYPES.STRING:
41
+ return 'string';
42
+ case validators_base.VLD_VALIDATOR_TYPES.NUMBER:
43
+ return 'number';
44
+ case validators_base.VLD_VALIDATOR_TYPES.BOOLEAN:
45
+ return 'boolean';
46
+ case validators_base.VLD_VALIDATOR_TYPES.BIGINT:
47
+ return 'bigint';
48
+ case validators_base.VLD_VALIDATOR_TYPES.SYMBOL:
49
+ return 'symbol';
50
+ case validators_base.VLD_VALIDATOR_TYPES.NULL:
51
+ return 'null';
52
+ case validators_base.VLD_VALIDATOR_TYPES.UNDEFINED:
53
+ case validators_base.VLD_VALIDATOR_TYPES.VOID:
54
+ return 'undefinedValue';
55
+ case validators_base.VLD_VALIDATOR_TYPES.LITERAL:
56
+ return 'literal';
57
+ case validators_base.VLD_VALIDATOR_TYPES.ANY:
58
+ case validators_base.VLD_VALIDATOR_TYPES.UNKNOWN:
59
+ return 'passthrough';
60
+ default:
61
+ return undefined;
62
+ }
63
+ }
64
+ getSimpleItemError(received) {
65
+ switch (this._simpleItemMode) {
66
+ case 'string':
67
+ return locales_runtime.getMessages().invalidString;
68
+ case 'number':
69
+ return locales_runtime.getMessages().invalidNumber;
70
+ case 'boolean':
71
+ return locales_runtime.getMessages().invalidBoolean;
72
+ case 'bigint':
73
+ return locales_runtime.getMessages().invalidBigint;
74
+ case 'symbol':
75
+ return locales_runtime.getMessages().invalidSymbol;
76
+ case 'null':
77
+ return `Expected null, received ${typeof received}`;
78
+ case 'undefinedValue':
79
+ return locales_runtime.getMessages().expectedUndefined;
80
+ case 'literal':
81
+ return locales_runtime.getMessages().literalExpected(JSON.stringify(this._simpleItemValue), JSON.stringify(received));
82
+ default:
83
+ return locales_runtime.getMessages().invalidSet;
84
+ }
85
+ }
86
+ /**
87
+ * Parse and validate a Set value
88
+ */
89
+ parse(value) {
90
+ if (!(value instanceof Set)) {
91
+ throw new Error(this.errorMessage || locales_runtime.getMessages().invalidSet);
92
+ }
93
+ return this.parseKnownSet(value);
94
+ }
95
+ /**
96
+ * Parse a value that has already passed the Set instance guard.
97
+ * @internal Used by object validators to avoid duplicate hot-path checks.
98
+ */
99
+ parseKnownSet(value) {
100
+ const result = new Set();
101
+ const simpleMode = this._simpleItemMode;
102
+ if (simpleMode === 'string') {
103
+ for (const item of value) {
104
+ if (typeof item !== 'string') {
105
+ throw new Error(this.getSimpleItemError(item));
106
+ }
107
+ result.add(item);
108
+ }
109
+ return result;
110
+ }
111
+ if (simpleMode === 'number') {
112
+ for (const item of value) {
113
+ if (typeof item !== 'number' || isNaN(item)) {
114
+ throw new Error(this.getSimpleItemError(item));
115
+ }
116
+ result.add(item);
117
+ }
118
+ return result;
119
+ }
120
+ if (simpleMode === 'boolean') {
121
+ for (const item of value) {
122
+ if (typeof item !== 'boolean') {
123
+ throw new Error(this.getSimpleItemError(item));
124
+ }
125
+ result.add(item);
126
+ }
127
+ return result;
128
+ }
129
+ if (simpleMode === 'bigint') {
130
+ for (const item of value) {
131
+ if (typeof item !== 'bigint') {
132
+ throw new Error(this.getSimpleItemError(item));
133
+ }
134
+ result.add(item);
135
+ }
136
+ return result;
137
+ }
138
+ if (simpleMode === 'symbol') {
139
+ for (const item of value) {
140
+ if (typeof item !== 'symbol') {
141
+ throw new Error(this.getSimpleItemError(item));
142
+ }
143
+ result.add(item);
144
+ }
145
+ return result;
146
+ }
147
+ if (simpleMode === 'null') {
148
+ for (const item of value) {
149
+ if (item !== null) {
150
+ throw new Error(this.getSimpleItemError(item));
151
+ }
152
+ result.add(null);
153
+ }
154
+ return result;
155
+ }
156
+ if (simpleMode === 'undefinedValue') {
157
+ for (const item of value) {
158
+ if (item !== undefined) {
159
+ throw new Error(this.getSimpleItemError(item));
160
+ }
161
+ result.add(undefined);
162
+ }
163
+ return result;
164
+ }
165
+ if (simpleMode === 'literal') {
166
+ for (const item of value) {
167
+ if (item !== this._simpleItemValue) {
168
+ throw new Error(this.getSimpleItemError(item));
169
+ }
170
+ result.add(this._simpleItemValue);
171
+ }
172
+ return result;
173
+ }
174
+ if (simpleMode === 'passthrough') {
175
+ for (const item of value) {
176
+ result.add(item);
177
+ }
178
+ return result;
179
+ }
180
+ for (const item of value) {
181
+ try {
182
+ result.add(this.itemValidator.parse(item));
183
+ }
184
+ catch (error) {
185
+ throw new Error(error.message);
186
+ }
187
+ }
188
+ return result;
189
+ }
190
+ /**
191
+ * Safely parse and validate a Set value
192
+ */
193
+ safeParse(value) {
194
+ try {
195
+ return { success: true, data: this.parse(value) };
196
+ }
197
+ catch (error) {
198
+ return { success: false, error: createSetError(error.message) };
199
+ }
200
+ }
201
+ }
202
+
203
+ exports.VldSet = VldSet;
@@ -0,0 +1,124 @@
1
+ 'use strict';
2
+
3
+ var validators_base = require('./base.cjs');
4
+ var locales_runtime = require('../locales/runtime.cjs');
5
+ require('../registry.cjs');
6
+ require('../locales/en.cjs');
7
+
8
+ /**
9
+ * Default truthy and falsy value sets
10
+ */
11
+ const DEFAULT_TRUTHY = ['true', '1', 'yes', 'on', 'y', 'enabled'];
12
+ const DEFAULT_FALSY = ['false', '0', 'no', 'off', 'n', 'disabled'];
13
+ /**
14
+ * Immutable string boolean validator for flexible boolean parsing
15
+ * Supports string representations like "true", "yes", "on", "1", etc.
16
+ */
17
+ class VldStringBool extends validators_base.VldBase {
18
+ constructor(options) {
19
+ super(validators_base.VLD_VALIDATOR_TYPES.STRING_BOOL);
20
+ this.options = options;
21
+ this.truthyValues = options.truthy ?? DEFAULT_TRUTHY;
22
+ this.falsyValues = options.falsy ?? DEFAULT_FALSY;
23
+ const normalizedTruthy = this.normalizeValues(this.truthyValues);
24
+ const normalizedFalsy = this.normalizeValues(this.falsyValues);
25
+ this.normalizedTruthySet = new Set(normalizedTruthy);
26
+ this.normalizedFalsySet = new Set(normalizedFalsy);
27
+ this.validValuesText = [...normalizedTruthy, ...normalizedFalsy].join(', ');
28
+ }
29
+ /**
30
+ * Create a new string boolean validator
31
+ */
32
+ static create(options = {}) {
33
+ return new VldStringBool(options);
34
+ }
35
+ /**
36
+ * Normalize a string value based on case sensitivity setting
37
+ */
38
+ normalizeValue(value) {
39
+ return this.options.caseSensitive ? value : value.toLowerCase();
40
+ }
41
+ normalizeValues(values) {
42
+ if (this.options.caseSensitive) {
43
+ return values;
44
+ }
45
+ return values.map(value => value.toLowerCase());
46
+ }
47
+ /**
48
+ * Parse and validate a string boolean value
49
+ */
50
+ parse(value) {
51
+ // First, ensure we have a string
52
+ if (typeof value !== 'string') {
53
+ // Also accept actual boolean values for convenience
54
+ if (typeof value === 'boolean') {
55
+ return value;
56
+ }
57
+ throw new Error(locales_runtime.getMessages().stringExpected(typeof value, 'string'));
58
+ }
59
+ const normalized = this.normalizeValue(value);
60
+ // Check if value is in truthy set
61
+ if (this.normalizedTruthySet.has(normalized)) {
62
+ return true;
63
+ }
64
+ // Check if value is in falsy set
65
+ if (this.normalizedFalsySet.has(normalized)) {
66
+ return false;
67
+ }
68
+ // Value is not recognized
69
+ throw new Error(locales_runtime.getMessages().stringBoolExpected(this.validValuesText, value));
70
+ }
71
+ /**
72
+ * Safely parse and validate a string boolean value
73
+ */
74
+ safeParse(value) {
75
+ try {
76
+ const result = this.parse(value);
77
+ return { success: true, data: result };
78
+ }
79
+ catch (error) {
80
+ return {
81
+ success: false,
82
+ error: error
83
+ };
84
+ }
85
+ }
86
+ /**
87
+ * Create a new validator with custom truthy values
88
+ */
89
+ withTruthy(values) {
90
+ return new VldStringBool({
91
+ ...this.options,
92
+ truthy: values
93
+ });
94
+ }
95
+ /**
96
+ * Create a new validator with custom falsy values
97
+ */
98
+ withFalsy(values) {
99
+ return new VldStringBool({
100
+ ...this.options,
101
+ falsy: values
102
+ });
103
+ }
104
+ /**
105
+ * Create a new validator with case-sensitive matching
106
+ */
107
+ caseSensitive() {
108
+ return new VldStringBool({
109
+ ...this.options,
110
+ caseSensitive: true
111
+ });
112
+ }
113
+ /**
114
+ * Create a new validator with case-insensitive matching (default)
115
+ */
116
+ caseInsensitive() {
117
+ return new VldStringBool({
118
+ ...this.options,
119
+ caseSensitive: false
120
+ });
121
+ }
122
+ }
123
+
124
+ exports.VldStringBool = VldStringBool;