@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.
- package/CHANGELOG.md +120 -1
- package/README.md +1296 -1171
- package/dist/chunks/errors-core-Cqi4-9ew.js +1 -0
- package/dist/chunks/index-CkbfQQ4n.js +1 -0
- package/dist/chunks/index-yjpbvFgw.js +1 -0
- package/dist/chunks/ip-validation-g5LWgy9t.js +1 -0
- package/dist/chunks/security-Dy24T8N7.js +1 -0
- package/dist/cjs/chunks/errors-core-DKPohm9I.cjs +1 -0
- package/dist/cjs/chunks/index-BEV9nG0N.cjs +1 -0
- package/dist/cjs/chunks/index-ZjHAxYdA.cjs +1 -0
- package/dist/cjs/chunks/ip-validation-BZqPamPC.cjs +1 -0
- package/dist/cjs/chunks/security-aXZVI7qW.cjs +1 -0
- package/dist/cjs/cli/bin.cjs +2 -0
- package/dist/cjs/cli/index.cjs +1 -0
- package/dist/cjs/codecs/index.cjs +1 -0
- package/dist/cjs/coercion/index.cjs +1 -0
- package/dist/cjs/compat/emitter.cjs +1 -0
- package/dist/cjs/compat/result.cjs +1 -0
- package/dist/cjs/errors.cjs +1 -387
- package/dist/cjs/index.cjs +1 -10759
- package/dist/cjs/kernel.cjs +1 -0
- package/dist/cjs/locales/af.cjs +1 -0
- package/dist/cjs/locales/ar.cjs +1 -0
- package/dist/cjs/locales/bn.cjs +1 -0
- package/dist/cjs/locales/da.cjs +1 -0
- package/dist/cjs/locales/de.cjs +1 -0
- package/dist/cjs/locales/en.cjs +1 -0
- package/dist/cjs/locales/es-MX.cjs +1 -0
- package/dist/cjs/locales/es.cjs +1 -0
- package/dist/cjs/locales/fi.cjs +1 -0
- package/dist/cjs/locales/fr.cjs +1 -0
- package/dist/cjs/locales/hi.cjs +1 -0
- package/dist/cjs/locales/id.cjs +1 -0
- package/dist/cjs/locales/index.cjs +1 -2877
- package/dist/cjs/locales/it.cjs +1 -0
- package/dist/cjs/locales/ja.cjs +1 -0
- package/dist/cjs/locales/ko.cjs +1 -0
- package/dist/cjs/locales/lazy.cjs +1 -3169
- package/dist/cjs/locales/nl.cjs +1 -0
- package/dist/cjs/locales/no.cjs +1 -0
- package/dist/cjs/locales/pl.cjs +1 -0
- package/dist/cjs/locales/pt-BR.cjs +1 -0
- package/dist/cjs/locales/pt.cjs +1 -0
- package/dist/cjs/locales/ru.cjs +1 -0
- package/dist/cjs/locales/runtime.cjs +1 -0
- package/dist/cjs/locales/sv.cjs +1 -0
- package/dist/cjs/locales/sw.cjs +1 -0
- package/dist/cjs/locales/th.cjs +1 -0
- package/dist/cjs/locales/tr.cjs +1 -0
- package/dist/cjs/locales/vi.cjs +1 -0
- package/dist/cjs/locales/zh.cjs +1 -0
- package/dist/cjs/mini.cjs +1 -7474
- package/dist/cjs/pigment.cjs +1 -0
- package/dist/cjs/plugins/index.cjs +1 -0
- package/dist/cjs/registry.cjs +1 -0
- package/dist/cjs/v3/index.cjs +1 -0
- package/dist/cjs/v4/core/index.cjs +1 -0
- package/dist/cjs/v4/index.cjs +1 -0
- package/dist/cjs/v4/locales/index.cjs +1 -0
- package/dist/cjs/v4/mini/index.cjs +1 -0
- package/dist/cjs/v4-mini/index.cjs +1 -0
- package/dist/cjs/validators/any.cjs +1 -0
- package/dist/cjs/validators/array.cjs +1 -0
- package/dist/cjs/validators/base.cjs +1 -0
- package/dist/cjs/validators/base64.cjs +1 -0
- package/dist/cjs/validators/bigint.cjs +1 -0
- package/dist/cjs/validators/boolean.cjs +1 -0
- package/dist/cjs/validators/codec.cjs +1 -0
- package/dist/cjs/validators/custom.cjs +1 -0
- package/dist/cjs/validators/date.cjs +1 -0
- package/dist/cjs/validators/discriminated-union.cjs +1 -0
- package/dist/cjs/validators/enum.cjs +1 -0
- package/dist/cjs/validators/file.cjs +1 -0
- package/dist/cjs/validators/function.cjs +1 -0
- package/dist/cjs/validators/hex.cjs +1 -0
- package/dist/cjs/validators/index.cjs +1 -0
- package/dist/cjs/validators/intersection.cjs +1 -0
- package/dist/cjs/validators/json.cjs +1 -0
- package/dist/cjs/validators/lazy.cjs +1 -0
- package/dist/cjs/validators/literal.cjs +1 -0
- package/dist/cjs/validators/map.cjs +1 -0
- package/dist/cjs/validators/nan.cjs +1 -0
- package/dist/cjs/validators/never.cjs +1 -0
- package/dist/cjs/validators/null.cjs +1 -0
- package/dist/cjs/validators/number.cjs +1 -0
- package/dist/cjs/validators/object.cjs +1 -0
- package/dist/cjs/validators/promise.cjs +1 -0
- package/dist/cjs/validators/record.cjs +1 -0
- package/dist/cjs/validators/set.cjs +1 -0
- package/dist/cjs/validators/string-bool.cjs +1 -0
- package/dist/cjs/validators/string-formats.cjs +1 -0
- package/dist/cjs/validators/string.cjs +1 -0
- package/dist/cjs/validators/symbol.cjs +1 -0
- package/dist/cjs/validators/template-literal.cjs +1 -0
- package/dist/cjs/validators/tuple.cjs +1 -0
- package/dist/cjs/validators/uint8array.cjs +1 -0
- package/dist/cjs/validators/undefined.cjs +1 -0
- package/dist/cjs/validators/union.cjs +1 -0
- package/dist/cjs/validators/unknown.cjs +1 -0
- package/dist/cjs/validators/void.cjs +1 -0
- package/dist/cjs/validators/xor.cjs +1 -0
- package/dist/cli/bin.d.ts +0 -1
- package/dist/cli/bin.js +2 -0
- package/dist/cli/commands/benchmark.d.ts +1 -2
- package/dist/cli/commands/validate.d.ts +1 -2
- package/dist/cli/index.d.ts +0 -1
- package/dist/cli/index.js +1 -0
- package/dist/codecs/index.d.ts +21 -4
- package/dist/codecs/index.js +1 -4
- package/dist/coercion/bigint.d.ts +2 -3
- package/dist/coercion/boolean.d.ts +3 -3
- package/dist/coercion/date.d.ts +3 -3
- package/dist/coercion/index.d.ts +5 -6
- package/dist/coercion/index.js +1 -111
- package/dist/coercion/number.d.ts +2 -3
- package/dist/coercion/string.d.ts +2 -3
- package/dist/compat/emitter.d.ts +0 -1
- package/dist/compat/emitter.js +1 -181
- package/dist/compat/index.d.ts +4 -5
- package/dist/compat/result.d.ts +1 -2
- package/dist/compat/result.js +1 -171
- package/dist/errors-core.d.ts +58 -0
- package/dist/errors.d.ts +4 -54
- package/dist/errors.js +1 -235
- package/dist/events.d.ts +3 -4
- package/dist/index.d.ts +1093 -851
- package/dist/index.js +1 -855
- package/dist/kernel.d.ts +2 -3
- package/dist/kernel.js +1 -405
- package/dist/locales/af.d.ts +1 -2
- package/dist/locales/af.js +1 -107
- package/dist/locales/ar.d.ts +1 -2
- package/dist/locales/ar.js +1 -107
- package/dist/locales/bn.d.ts +1 -2
- package/dist/locales/bn.js +1 -107
- package/dist/locales/da.d.ts +1 -2
- package/dist/locales/da.js +1 -107
- package/dist/locales/de.d.ts +1 -2
- package/dist/locales/de.js +1 -107
- package/dist/locales/en.d.ts +1 -2
- package/dist/locales/en.js +1 -107
- package/dist/locales/es-MX.d.ts +1 -2
- package/dist/locales/es-MX.js +1 -106
- package/dist/locales/es.d.ts +1 -2
- package/dist/locales/es.js +1 -95
- package/dist/locales/fi.d.ts +1 -2
- package/dist/locales/fi.js +1 -107
- package/dist/locales/fr.d.ts +1 -2
- package/dist/locales/fr.js +1 -95
- package/dist/locales/hi.d.ts +1 -2
- package/dist/locales/hi.js +1 -107
- package/dist/locales/id.d.ts +1 -2
- package/dist/locales/id.js +1 -107
- package/dist/locales/index.d.ts +10 -15
- package/dist/locales/index.js +1 -3
- package/dist/locales/it.d.ts +1 -2
- package/dist/locales/it.js +1 -107
- package/dist/locales/ja.d.ts +1 -2
- package/dist/locales/ja.js +1 -107
- package/dist/locales/ko.d.ts +1 -2
- package/dist/locales/ko.js +1 -107
- package/dist/locales/lazy.d.ts +4 -26
- package/dist/locales/lazy.js +1 -220
- package/dist/locales/nl.d.ts +1 -2
- package/dist/locales/nl.js +1 -107
- package/dist/locales/no.d.ts +1 -2
- package/dist/locales/no.js +1 -107
- package/dist/locales/pl.d.ts +1 -2
- package/dist/locales/pl.js +1 -107
- package/dist/locales/pt-BR.d.ts +1 -2
- package/dist/locales/pt-BR.js +1 -107
- package/dist/locales/pt.d.ts +1 -2
- package/dist/locales/pt.js +1 -107
- package/dist/locales/ru.d.ts +1 -2
- package/dist/locales/ru.js +1 -107
- package/dist/locales/runtime.d.ts +10 -0
- package/dist/locales/runtime.js +1 -0
- package/dist/locales/sv.d.ts +1 -2
- package/dist/locales/sv.js +1 -107
- package/dist/locales/sw.d.ts +1 -2
- package/dist/locales/sw.js +1 -107
- package/dist/locales/th.d.ts +1 -2
- package/dist/locales/th.js +1 -107
- package/dist/locales/tr.d.ts +1 -2
- package/dist/locales/tr.js +1 -107
- package/dist/locales/types.d.ts +0 -1
- package/dist/locales/vi.d.ts +1 -2
- package/dist/locales/vi.js +1 -107
- package/dist/locales/zh.d.ts +1 -2
- package/dist/locales/zh.js +1 -107
- package/dist/logger.d.ts +0 -1
- package/dist/mini.d.ts +67 -68
- package/dist/mini.js +1 -132
- package/dist/pigment.d.ts +0 -1
- package/dist/pigment.js +1 -178
- package/dist/plugins/index.d.ts +2 -3
- package/dist/plugins/index.js +1 -0
- package/dist/plugins/types.d.ts +4 -5
- package/dist/registry.d.ts +23 -0
- package/dist/registry.js +1 -0
- package/dist/utils/codec-utils.d.ts +0 -1
- package/dist/utils/deep-merge.d.ts +0 -1
- package/dist/utils/ip-validation.d.ts +0 -1
- package/dist/utils/json-schema.d.ts +26 -7
- package/dist/utils/security.d.ts +2 -6
- package/dist/v3/index.d.ts +2 -0
- package/dist/v3/index.js +1 -0
- package/dist/v4/core/index.d.ts +272 -0
- package/dist/v4/core/index.js +1 -0
- package/dist/v4/index.d.ts +4 -0
- package/dist/v4/index.js +1 -0
- package/dist/v4/locales/index.d.ts +57 -0
- package/dist/v4/locales/index.js +1 -0
- package/dist/v4/mini/index.d.ts +2 -0
- package/dist/v4/mini/index.js +1 -0
- package/dist/v4-mini/index.d.ts +22 -0
- package/dist/v4-mini/index.js +1 -0
- package/dist/validators/any.d.ts +7 -2
- package/dist/validators/any.js +1 -0
- package/dist/validators/array.d.ts +16 -2
- package/dist/validators/array.js +1 -0
- package/dist/validators/base.d.ts +213 -14
- package/dist/validators/base.js +1 -0
- package/dist/validators/base64.d.ts +1 -2
- package/dist/validators/base64.js +1 -0
- package/dist/validators/bigint.d.ts +21 -3
- package/dist/validators/bigint.js +1 -0
- package/dist/validators/boolean.d.ts +13 -4
- package/dist/validators/boolean.js +1 -0
- package/dist/validators/codec.d.ts +9 -2
- package/dist/validators/codec.js +1 -0
- package/dist/validators/custom.d.ts +15 -2
- package/dist/validators/custom.js +1 -0
- package/dist/validators/date.d.ts +19 -3
- package/dist/validators/date.js +1 -0
- package/dist/validators/discriminated-union.d.ts +6 -5
- package/dist/validators/discriminated-union.js +1 -0
- package/dist/validators/enum.d.ts +10 -7
- package/dist/validators/enum.js +1 -0
- package/dist/validators/file.d.ts +7 -2
- package/dist/validators/file.js +1 -0
- package/dist/validators/function.d.ts +11 -5
- package/dist/validators/function.js +1 -0
- package/dist/validators/hex.d.ts +1 -2
- package/dist/validators/hex.js +1 -0
- package/dist/validators/index.d.ts +38 -39
- package/dist/validators/index.js +1 -515
- package/dist/validators/intersection.d.ts +1 -2
- package/dist/validators/intersection.js +1 -0
- package/dist/validators/json.d.ts +1 -2
- package/dist/validators/json.js +1 -0
- package/dist/validators/lazy.d.ts +5 -9
- package/dist/validators/lazy.js +1 -0
- package/dist/validators/literal.d.ts +9 -5
- package/dist/validators/literal.js +1 -0
- package/dist/validators/map.d.ts +15 -2
- package/dist/validators/map.js +1 -0
- package/dist/validators/nan.d.ts +2 -3
- package/dist/validators/nan.js +1 -0
- package/dist/validators/never.d.ts +1 -2
- package/dist/validators/never.js +1 -0
- package/dist/validators/null.d.ts +3 -3
- package/dist/validators/null.js +1 -0
- package/dist/validators/number.d.ts +75 -27
- package/dist/validators/number.js +1 -0
- package/dist/validators/object.d.ts +42 -11
- package/dist/validators/object.js +1 -0
- package/dist/validators/promise.d.ts +15 -10
- package/dist/validators/promise.js +1 -0
- package/dist/validators/record.d.ts +21 -9
- package/dist/validators/record.js +1 -0
- package/dist/validators/set.d.ts +11 -2
- package/dist/validators/set.js +1 -0
- package/dist/validators/string-bool.d.ts +7 -10
- package/dist/validators/string-bool.js +1 -0
- package/dist/validators/string-formats.d.ts +64 -65
- package/dist/validators/string-formats.js +1 -0
- package/dist/validators/string.d.ts +84 -26
- package/dist/validators/string.js +1 -0
- package/dist/validators/symbol.d.ts +8 -3
- package/dist/validators/symbol.js +1 -0
- package/dist/validators/template-literal.d.ts +1 -2
- package/dist/validators/template-literal.js +1 -0
- package/dist/validators/tuple.d.ts +29 -12
- package/dist/validators/tuple.js +1 -0
- package/dist/validators/uint8array.d.ts +3 -4
- package/dist/validators/uint8array.js +1 -0
- package/dist/validators/undefined.d.ts +3 -3
- package/dist/validators/undefined.js +1 -0
- package/dist/validators/union.d.ts +7 -4
- package/dist/validators/union.js +1 -0
- package/dist/validators/unknown.d.ts +7 -2
- package/dist/validators/unknown.js +1 -0
- package/dist/validators/void.d.ts +3 -2
- package/dist/validators/void.js +1 -0
- package/dist/validators/xor.d.ts +4 -5
- package/dist/validators/xor.js +1 -0
- package/package.json +239 -154
- package/dist/chunks/bigint-CRS0QVsy.js +0 -1854
- package/dist/chunks/bigint-CRS0QVsy.js.map +0 -1
- package/dist/chunks/date-50JV_Mfj.js +0 -506
- package/dist/chunks/date-50JV_Mfj.js.map +0 -1
- package/dist/chunks/index-DO8CFMxD.js +0 -894
- package/dist/chunks/index-DO8CFMxD.js.map +0 -1
- package/dist/chunks/json-Cp4WO0M9.js +0 -2021
- package/dist/chunks/json-Cp4WO0M9.js.map +0 -1
- package/dist/chunks/unknown-Dhzri_T-.js +0 -28
- package/dist/chunks/unknown-Dhzri_T-.js.map +0 -1
- package/dist/cjs/errors.cjs.map +0 -1
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/locales/index.cjs.map +0 -1
- package/dist/cjs/locales/lazy.cjs.map +0 -1
- package/dist/cjs/mini.cjs.map +0 -1
- package/dist/cli/bin.d.ts.map +0 -1
- package/dist/cli/commands/benchmark.d.ts.map +0 -1
- package/dist/cli/commands/validate.d.ts.map +0 -1
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/codecs/index.d.ts.map +0 -1
- package/dist/codecs/index.js.map +0 -1
- package/dist/coercion/bigint.d.ts.map +0 -1
- package/dist/coercion/boolean.d.ts.map +0 -1
- package/dist/coercion/date.d.ts.map +0 -1
- package/dist/coercion/index.d.ts.map +0 -1
- package/dist/coercion/index.js.map +0 -1
- package/dist/coercion/number.d.ts.map +0 -1
- package/dist/coercion/string.d.ts.map +0 -1
- package/dist/compat/emitter.d.ts.map +0 -1
- package/dist/compat/emitter.js.map +0 -1
- package/dist/compat/index.d.ts.map +0 -1
- package/dist/compat/result.d.ts.map +0 -1
- package/dist/compat/result.js.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js.map +0 -1
- package/dist/events.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/kernel.d.ts.map +0 -1
- package/dist/kernel.js.map +0 -1
- package/dist/locales/af.d.ts.map +0 -1
- package/dist/locales/af.js.map +0 -1
- package/dist/locales/ar.d.ts.map +0 -1
- package/dist/locales/ar.js.map +0 -1
- package/dist/locales/backup-en.d.ts +0 -3
- package/dist/locales/backup-en.d.ts.map +0 -1
- package/dist/locales/bn.d.ts.map +0 -1
- package/dist/locales/bn.js.map +0 -1
- package/dist/locales/da.d.ts.map +0 -1
- package/dist/locales/da.js.map +0 -1
- package/dist/locales/de.d.ts.map +0 -1
- package/dist/locales/de.js.map +0 -1
- package/dist/locales/en.d.ts.map +0 -1
- package/dist/locales/en.js.map +0 -1
- package/dist/locales/es-MX.d.ts.map +0 -1
- package/dist/locales/es-MX.js.map +0 -1
- package/dist/locales/es.d.ts.map +0 -1
- package/dist/locales/es.js.map +0 -1
- package/dist/locales/fi.d.ts.map +0 -1
- package/dist/locales/fi.js.map +0 -1
- package/dist/locales/fr.d.ts.map +0 -1
- package/dist/locales/fr.js.map +0 -1
- package/dist/locales/hi.d.ts.map +0 -1
- package/dist/locales/hi.js.map +0 -1
- package/dist/locales/id.d.ts.map +0 -1
- package/dist/locales/id.js.map +0 -1
- package/dist/locales/index.d.ts.map +0 -1
- package/dist/locales/index.js.map +0 -1
- package/dist/locales/it.d.ts.map +0 -1
- package/dist/locales/it.js.map +0 -1
- package/dist/locales/ja.d.ts.map +0 -1
- package/dist/locales/ja.js.map +0 -1
- package/dist/locales/ko.d.ts.map +0 -1
- package/dist/locales/ko.js.map +0 -1
- package/dist/locales/lazy.d.ts.map +0 -1
- package/dist/locales/lazy.js.map +0 -1
- package/dist/locales/nl.d.ts.map +0 -1
- package/dist/locales/nl.js.map +0 -1
- package/dist/locales/no.d.ts.map +0 -1
- package/dist/locales/no.js.map +0 -1
- package/dist/locales/pl.d.ts.map +0 -1
- package/dist/locales/pl.js.map +0 -1
- package/dist/locales/pt-BR.d.ts.map +0 -1
- package/dist/locales/pt-BR.js.map +0 -1
- package/dist/locales/pt.d.ts.map +0 -1
- package/dist/locales/pt.js.map +0 -1
- package/dist/locales/ru.d.ts.map +0 -1
- package/dist/locales/ru.js.map +0 -1
- package/dist/locales/sv.d.ts.map +0 -1
- package/dist/locales/sv.js.map +0 -1
- package/dist/locales/sw.d.ts.map +0 -1
- package/dist/locales/sw.js.map +0 -1
- package/dist/locales/th.d.ts.map +0 -1
- package/dist/locales/th.js.map +0 -1
- package/dist/locales/tr.d.ts.map +0 -1
- package/dist/locales/tr.js.map +0 -1
- package/dist/locales/types.d.ts.map +0 -1
- package/dist/locales/vi.d.ts.map +0 -1
- package/dist/locales/vi.js.map +0 -1
- package/dist/locales/zh.d.ts.map +0 -1
- package/dist/locales/zh.js.map +0 -1
- package/dist/logger.d.ts.map +0 -1
- package/dist/mini.d.ts.map +0 -1
- package/dist/mini.js.map +0 -1
- package/dist/pigment.d.ts.map +0 -1
- package/dist/pigment.js.map +0 -1
- package/dist/plugins/index.d.ts.map +0 -1
- package/dist/plugins/types.d.ts.map +0 -1
- package/dist/utils/codec-utils.d.ts.map +0 -1
- package/dist/utils/deep-merge.d.ts.map +0 -1
- package/dist/utils/ip-validation.d.ts.map +0 -1
- package/dist/utils/json-schema.d.ts.map +0 -1
- package/dist/utils/security.d.ts.map +0 -1
- package/dist/validators/any.d.ts.map +0 -1
- package/dist/validators/array.d.ts.map +0 -1
- package/dist/validators/base.d.ts.map +0 -1
- package/dist/validators/base64.d.ts.map +0 -1
- package/dist/validators/bigint.d.ts.map +0 -1
- package/dist/validators/boolean.d.ts.map +0 -1
- package/dist/validators/codec.d.ts.map +0 -1
- package/dist/validators/custom.d.ts.map +0 -1
- package/dist/validators/date.d.ts.map +0 -1
- package/dist/validators/discriminated-union.d.ts.map +0 -1
- package/dist/validators/enum.d.ts.map +0 -1
- package/dist/validators/file.d.ts.map +0 -1
- package/dist/validators/function.d.ts.map +0 -1
- package/dist/validators/hex.d.ts.map +0 -1
- package/dist/validators/index.d.ts.map +0 -1
- package/dist/validators/index.js.map +0 -1
- package/dist/validators/intersection.d.ts.map +0 -1
- package/dist/validators/json.d.ts.map +0 -1
- package/dist/validators/lazy.d.ts.map +0 -1
- package/dist/validators/literal.d.ts.map +0 -1
- package/dist/validators/map.d.ts.map +0 -1
- package/dist/validators/nan.d.ts.map +0 -1
- package/dist/validators/never.d.ts.map +0 -1
- package/dist/validators/null.d.ts.map +0 -1
- package/dist/validators/number.d.ts.map +0 -1
- package/dist/validators/object.d.ts.map +0 -1
- package/dist/validators/promise.d.ts.map +0 -1
- package/dist/validators/record.d.ts.map +0 -1
- package/dist/validators/set.d.ts.map +0 -1
- package/dist/validators/string-bool.d.ts.map +0 -1
- package/dist/validators/string-formats.d.ts.map +0 -1
- package/dist/validators/string.d.ts.map +0 -1
- package/dist/validators/symbol.d.ts.map +0 -1
- package/dist/validators/template-literal.d.ts.map +0 -1
- package/dist/validators/tuple.d.ts.map +0 -1
- package/dist/validators/uint8array.d.ts.map +0 -1
- package/dist/validators/undefined.d.ts.map +0 -1
- package/dist/validators/union.d.ts.map +0 -1
- package/dist/validators/unknown.d.ts.map +0 -1
- package/dist/validators/void.d.ts.map +0 -1
- package/dist/validators/xor.d.ts.map +0 -1
package/dist/validators/index.js
CHANGED
|
@@ -1,515 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { V as VldBigInt, a as VldBoolean, j as VldBrand, k as VldCatch, b as VldDate, l as VldDefault, r as VldExactOptional, d as VldNullable, e as VldNullish, c as VldNumber, f as VldOptional, m as VldPipe, g as VldPreprocess, n as VldReadonly, o as VldRefine, p as VldSuperRefine, q as VldTransform } from '../chunks/bigint-CRS0QVsy.js';
|
|
3
|
-
export { a as VldAny, b as VldArray, c as VldDiscriminatedUnion, d as VldEnum, e as VldIntersection, f as VldJson, g as VldLazy, h as VldLiteral, k as VldMap, l as VldNan, V as VldNever, m as VldNull, i as VldObject, j as VldRecord, n as VldSet, o as VldStringBool, p as VldSymbol, q as VldTuple, r as VldUndefined, s as VldUnion, t as VldVoid, u as VldXor } from '../chunks/json-Cp4WO0M9.js';
|
|
4
|
-
export { V as VldUnknown } from '../chunks/unknown-Dhzri_T-.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Immutable template literal validator
|
|
8
|
-
* Validates strings matching a template pattern
|
|
9
|
-
*/
|
|
10
|
-
class VldTemplateLiteral extends VldBase {
|
|
11
|
-
constructor(pattern) {
|
|
12
|
-
super();
|
|
13
|
-
this.pattern = pattern;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Create a template literal validator from components
|
|
17
|
-
*/
|
|
18
|
-
static create(...components) {
|
|
19
|
-
// Build regex pattern from components
|
|
20
|
-
let pattern = '^';
|
|
21
|
-
for (const comp of components) {
|
|
22
|
-
if (typeof comp === 'string') {
|
|
23
|
-
// Escape special regex characters
|
|
24
|
-
pattern += comp.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
// Add appropriate pattern based on validator type
|
|
28
|
-
pattern += getPatternForValidator(comp);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
pattern += '$';
|
|
32
|
-
return new VldTemplateLiteral(new RegExp(pattern));
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Parse and validate a template literal string
|
|
36
|
-
*/
|
|
37
|
-
parse(value) {
|
|
38
|
-
if (typeof value !== 'string') {
|
|
39
|
-
throw new Error(getMessages().invalidString);
|
|
40
|
-
}
|
|
41
|
-
if (!this.pattern.test(value)) {
|
|
42
|
-
throw new Error(getMessages().stringPatternInvalid);
|
|
43
|
-
}
|
|
44
|
-
return value;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Safely parse and validate a template literal string
|
|
48
|
-
*/
|
|
49
|
-
safeParse(value) {
|
|
50
|
-
try {
|
|
51
|
-
return { success: true, data: this.parse(value) };
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
return {
|
|
55
|
-
success: false,
|
|
56
|
-
error: error
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Get regex pattern for a validator type
|
|
63
|
-
*/
|
|
64
|
-
function getPatternForValidator(validator) {
|
|
65
|
-
// For template literals, we need to identify the validator type
|
|
66
|
-
// and return an appropriate capture group pattern
|
|
67
|
-
const className = validator.constructor.name;
|
|
68
|
-
// Check for specific validator types
|
|
69
|
-
if (className === 'VldString') {
|
|
70
|
-
return '(.+)';
|
|
71
|
-
}
|
|
72
|
-
if (className === 'VldNumber' || className === 'VldInt') {
|
|
73
|
-
return '(-?\\d+(?:\\.\\d+)?)';
|
|
74
|
-
}
|
|
75
|
-
if (className === 'VldBigInt') {
|
|
76
|
-
return '(-?\\d+)';
|
|
77
|
-
}
|
|
78
|
-
if (className === 'VldBoolean') {
|
|
79
|
-
return '(true|false)';
|
|
80
|
-
}
|
|
81
|
-
if (className === 'VldNull') {
|
|
82
|
-
return '(null)';
|
|
83
|
-
}
|
|
84
|
-
if (className === 'VldUndefined' || className === 'VldVoid') {
|
|
85
|
-
return '(undefined)';
|
|
86
|
-
}
|
|
87
|
-
if (className === 'VldLiteral') {
|
|
88
|
-
// Extract literal value - access private literal property via any
|
|
89
|
-
const literalValidator = validator;
|
|
90
|
-
if (literalValidator.literal !== undefined) {
|
|
91
|
-
const valueStr = String(literalValidator.literal);
|
|
92
|
-
return '(' + valueStr.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + ')';
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
// Default: match any string
|
|
96
|
-
return '(.+)';
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Helper function to create template literal validators
|
|
100
|
-
* Usage: v.templateLiteral(v.string(), '-', v.number())
|
|
101
|
-
*/
|
|
102
|
-
function templateLiteral(...components) {
|
|
103
|
-
return VldTemplateLiteral.create(...components);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Immutable custom validator for user-defined validation logic
|
|
108
|
-
* Provides type safety while allowing complete control over validation
|
|
109
|
-
*/
|
|
110
|
-
class VldCustom extends VldBase {
|
|
111
|
-
constructor(options) {
|
|
112
|
-
super();
|
|
113
|
-
this._parseFn = options.parse;
|
|
114
|
-
this._safeParseFn = options.safeParse || ((value) => {
|
|
115
|
-
try {
|
|
116
|
-
return { success: true, data: this._parseFn(value) };
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
return { success: false, error: error };
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Create a new custom validator
|
|
125
|
-
*/
|
|
126
|
-
static create(options) {
|
|
127
|
-
return new VldCustom(options);
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Parse and validate using the custom parse function
|
|
131
|
-
*/
|
|
132
|
-
parse(value) {
|
|
133
|
-
return this._parseFn(value);
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Safely parse using the custom safeParse function or default implementation
|
|
137
|
-
*/
|
|
138
|
-
safeParse(value) {
|
|
139
|
-
return this._safeParseFn(value);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Helper function to create custom validators
|
|
144
|
-
* Usage: v.custom<number>({
|
|
145
|
-
* parse: (value) => {
|
|
146
|
-
* if (typeof value !== 'string') throw new Error('Expected string');
|
|
147
|
-
* return parseInt(value, 10);
|
|
148
|
-
* }
|
|
149
|
-
* })
|
|
150
|
-
*/
|
|
151
|
-
function custom(options) {
|
|
152
|
-
return VldCustom.create(options);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Immutable file validator for file uploads
|
|
157
|
-
* Supports size and MIME type validation
|
|
158
|
-
*/
|
|
159
|
-
class VldFile extends VldBase {
|
|
160
|
-
constructor(checks = []) {
|
|
161
|
-
super();
|
|
162
|
-
this.checks = checks;
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Create a new file validator
|
|
166
|
-
*/
|
|
167
|
-
static create() {
|
|
168
|
-
return new VldFile();
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Parse and validate a file value
|
|
172
|
-
*/
|
|
173
|
-
parse(value) {
|
|
174
|
-
// Check if File API is supported
|
|
175
|
-
const FileSupported = typeof File !== 'undefined';
|
|
176
|
-
if (!FileSupported) {
|
|
177
|
-
throw new Error(getMessages().fileNotSupported || 'File API not supported in this environment');
|
|
178
|
-
}
|
|
179
|
-
// Check if value is a File object
|
|
180
|
-
if (!(value instanceof File)) {
|
|
181
|
-
// Allow plain object with size and type for Node.js compatibility
|
|
182
|
-
if (typeof value === 'object' &&
|
|
183
|
-
value !== null &&
|
|
184
|
-
'size' in value &&
|
|
185
|
-
'type' in value) {
|
|
186
|
-
const fileObj = value;
|
|
187
|
-
return this.runChecks(fileObj);
|
|
188
|
-
}
|
|
189
|
-
throw new Error(getMessages().invalidFile || 'Expected a File object');
|
|
190
|
-
}
|
|
191
|
-
return this.runChecks(value);
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Run all validation checks on the file
|
|
195
|
-
*/
|
|
196
|
-
runChecks(file) {
|
|
197
|
-
const msgs = getMessages();
|
|
198
|
-
for (const check of this.checks) {
|
|
199
|
-
switch (check.type) {
|
|
200
|
-
case 'min':
|
|
201
|
-
if (file.size < check.value) {
|
|
202
|
-
throw new Error(check.message ||
|
|
203
|
-
(msgs.fileMinSize?.(check.value) || `File size must be at least ${check.value} bytes`));
|
|
204
|
-
}
|
|
205
|
-
break;
|
|
206
|
-
case 'max':
|
|
207
|
-
if (file.size > check.value) {
|
|
208
|
-
throw new Error(check.message ||
|
|
209
|
-
(msgs.fileMaxSize?.(check.value) || `File size must not exceed ${check.value} bytes`));
|
|
210
|
-
}
|
|
211
|
-
break;
|
|
212
|
-
case 'mime':
|
|
213
|
-
if (!check.value.includes(file.type)) {
|
|
214
|
-
throw new Error(check.message ||
|
|
215
|
-
(msgs.fileMimeType?.(check.value) || `Invalid file type. Expected: ${check.value.join(', ')}`));
|
|
216
|
-
}
|
|
217
|
-
break;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
return file;
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Safely parse and validate a file value
|
|
224
|
-
*/
|
|
225
|
-
safeParse(value) {
|
|
226
|
-
try {
|
|
227
|
-
return { success: true, data: this.parse(value) };
|
|
228
|
-
}
|
|
229
|
-
catch (error) {
|
|
230
|
-
return { success: false, error: error };
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Set minimum file size in bytes
|
|
235
|
-
*/
|
|
236
|
-
min(bytes, message) {
|
|
237
|
-
return new VldFile([...this.checks, { type: 'min', value: bytes, message }]);
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Set maximum file size in bytes
|
|
241
|
-
*/
|
|
242
|
-
max(bytes, message) {
|
|
243
|
-
return new VldFile([...this.checks, { type: 'max', value: bytes, message }]);
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Set allowed MIME types
|
|
247
|
-
*/
|
|
248
|
-
mime(types, message) {
|
|
249
|
-
const typeArray = Array.isArray(types) ? types : [types];
|
|
250
|
-
return new VldFile([...this.checks, { type: 'mime', value: typeArray, message }]);
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Set both minimum and maximum file size
|
|
254
|
-
*/
|
|
255
|
-
size(min, max, message) {
|
|
256
|
-
return this.min(min, message).max(max, message);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Helper function to create file validators
|
|
261
|
-
* Usage: v.file().min(1024).max(10485760).mime(['image/jpeg', 'image/png'])
|
|
262
|
-
*/
|
|
263
|
-
function file() {
|
|
264
|
-
return VldFile.create();
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Immutable function validator
|
|
269
|
-
* Validates that a value is a function
|
|
270
|
-
*/
|
|
271
|
-
class VldFunction extends VldBase {
|
|
272
|
-
constructor() {
|
|
273
|
-
super();
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* Create a new function validator
|
|
277
|
-
*/
|
|
278
|
-
static create() {
|
|
279
|
-
return new VldFunction();
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Parse and validate a function value
|
|
283
|
-
*/
|
|
284
|
-
parse(value) {
|
|
285
|
-
if (typeof value !== 'function') {
|
|
286
|
-
throw new Error(getMessages().invalidFunction || 'Expected a function');
|
|
287
|
-
}
|
|
288
|
-
return value;
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Safely parse and validate a function value
|
|
292
|
-
*/
|
|
293
|
-
safeParse(value) {
|
|
294
|
-
try {
|
|
295
|
-
return { success: true, data: this.parse(value) };
|
|
296
|
-
}
|
|
297
|
-
catch (error) {
|
|
298
|
-
return { success: false, error: error };
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Helper function to create function validators
|
|
304
|
-
* Usage: v.function()
|
|
305
|
-
*/
|
|
306
|
-
function functionValidator() {
|
|
307
|
-
return VldFunction.create();
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Promise validator - validates Promise values
|
|
312
|
-
* Validates that the resolved value matches the inner schema
|
|
313
|
-
*/
|
|
314
|
-
/**
|
|
315
|
-
* Promise validator - validates Promise<T> where T matches inner schema
|
|
316
|
-
* Zod 4 API parity - allows async validation with proper type inference
|
|
317
|
-
*
|
|
318
|
-
* Validates that the input is a Promise, and validates the resolved value
|
|
319
|
-
* against the inner schema when parsed.
|
|
320
|
-
*
|
|
321
|
-
* Use parseAsync() or safeParseAsync() for proper async handling.
|
|
322
|
-
*/
|
|
323
|
-
class VldPromise {
|
|
324
|
-
constructor(inner) {
|
|
325
|
-
this.inner = inner;
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Check if value is thenable (Promise-like)
|
|
329
|
-
* Must be called BEFORE wrapping in Promise.resolve
|
|
330
|
-
*/
|
|
331
|
-
_isThenable(value) {
|
|
332
|
-
return value !== null && typeof value.then === 'function';
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* Parse and validate a Promise value asynchronously
|
|
336
|
-
* @param value The Promise to validate
|
|
337
|
-
* @returns The validated value
|
|
338
|
-
* @throws {Error} If validation fails when Promise resolves
|
|
339
|
-
*/
|
|
340
|
-
async parse(value) {
|
|
341
|
-
// Check if value is thenable BEFORE wrapping in Promise.resolve
|
|
342
|
-
if (!this._isThenable(value)) {
|
|
343
|
-
throw new Error('Expected a Promise value');
|
|
344
|
-
}
|
|
345
|
-
// Now we can safely await it
|
|
346
|
-
const resolved = await Promise.resolve(value);
|
|
347
|
-
return this.inner.parse(resolved);
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* Safely parse and validate a Promise value asynchronously
|
|
351
|
-
* @param value The Promise to validate
|
|
352
|
-
* @returns A Promise resolving to ParseResult containing the validated value
|
|
353
|
-
*/
|
|
354
|
-
async safeParse(value) {
|
|
355
|
-
// Check if value is thenable BEFORE wrapping in Promise.resolve
|
|
356
|
-
if (!this._isThenable(value)) {
|
|
357
|
-
return {
|
|
358
|
-
success: false,
|
|
359
|
-
error: new Error('Expected a Promise value')
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
try {
|
|
363
|
-
const resolved = await Promise.resolve(value);
|
|
364
|
-
const validated = this.inner.parse(resolved);
|
|
365
|
-
return {
|
|
366
|
-
success: true,
|
|
367
|
-
data: validated
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
catch (err) {
|
|
371
|
-
return {
|
|
372
|
-
success: false,
|
|
373
|
-
error: err instanceof Error ? err : new Error(String(err))
|
|
374
|
-
};
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
/**
|
|
379
|
-
* Create a Promise validator
|
|
380
|
-
* @param inner The schema to validate the resolved value against
|
|
381
|
-
* @returns A new Promise validator
|
|
382
|
-
* @example
|
|
383
|
-
* const promiseSchema = v.promise(v.string());
|
|
384
|
-
* const result = await promiseSchema.parse(Promise.resolve("hello"));
|
|
385
|
-
* // result is string
|
|
386
|
-
*/
|
|
387
|
-
function promise(inner) {
|
|
388
|
-
return new VldPromise(inner);
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
/**
|
|
392
|
-
* Top-level string format validators
|
|
393
|
-
* Part of Zod 4 API parity implementation
|
|
394
|
-
* Provides convenient validators for common string formats
|
|
395
|
-
*/
|
|
396
|
-
/**
|
|
397
|
-
* Pre-compiled regex patterns for performance
|
|
398
|
-
*/
|
|
399
|
-
const REGEXES = {
|
|
400
|
-
email: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
|
|
401
|
-
uuid: /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,
|
|
402
|
-
uuidv4: /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,
|
|
403
|
-
uuidv6: /^[0-9a-f]{8}-[0-9a-f]{4}-6[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,
|
|
404
|
-
uuidv7: /^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,
|
|
405
|
-
hostname: /^(?=.{1,253}$)(?:(?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,63}$/,
|
|
406
|
-
emoji: /^(?:\p{Emoji_Presentation}|\p{Emoji}\uFE0F)(?:\u200D(?:\p{Emoji_Presentation}|\p{Emoji}\uFE0F))*$/u,
|
|
407
|
-
base64: /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/,
|
|
408
|
-
base64url: /^[A-Za-z0-9_-]*$/,
|
|
409
|
-
hex: /^[0-9a-fA-F]*$/,
|
|
410
|
-
jwt: /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$/,
|
|
411
|
-
nanoid: /^[A-Za-z0-9_-]{21}$/,
|
|
412
|
-
cuid: /^c[^\s-]{8,}$/i,
|
|
413
|
-
cuid2: /^[0-9a-z]+$/,
|
|
414
|
-
ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
|
|
415
|
-
ipv4: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,
|
|
416
|
-
ipv6: /^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/,
|
|
417
|
-
mac: /^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$/,
|
|
418
|
-
cidrv4: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/(?:3[0-2]|[12]?[0-9])$/,
|
|
419
|
-
cidrv6: /^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\/(?:12[0-8]|1[01][0-9]|[1-9]?[0-9])$|^::(?:[0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{1,4}\/(?:12[0-8]|1[01][0-9]|[1-9]?[0-9])$|^(?:[0-9a-fA-F]{1,4}:){1,7}:\/(?:12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,
|
|
420
|
-
e164: /^\+[1-9]\d{1,14}$/,
|
|
421
|
-
isoDate: /^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/,
|
|
422
|
-
isoTime: /^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?$/,
|
|
423
|
-
isoDateTime: /^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?Z?$/,
|
|
424
|
-
md5: /^[a-f0-9]{32}$/i,
|
|
425
|
-
sha1: /^[a-f0-9]{40}$/i,
|
|
426
|
-
sha256: /^[a-f0-9]{64}$/i,
|
|
427
|
-
sha384: /^[a-f0-9]{96}$/i,
|
|
428
|
-
sha512: /^[a-f0-9]{128}$/i,
|
|
429
|
-
// Additional formats (Zod v4 parity)
|
|
430
|
-
xid: /^[A-HJKMNP-TV-Z0-9]{20}$/, // ksort's XID format
|
|
431
|
-
guid: /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/i, // Alias for UUID
|
|
432
|
-
httpUrl: /^https?:\/\/[^\s/$.?#].[^\s]*$/, // HTTP/HTTPS URL
|
|
433
|
-
};
|
|
434
|
-
/**
|
|
435
|
-
* Generic string format validator
|
|
436
|
-
*/
|
|
437
|
-
class VldStringFormat extends VldBase {
|
|
438
|
-
constructor(_format, _validator, _errorMessage) {
|
|
439
|
-
super();
|
|
440
|
-
this._format = _format;
|
|
441
|
-
this._validator = _validator;
|
|
442
|
-
this._errorMessage = _errorMessage;
|
|
443
|
-
}
|
|
444
|
-
static create(format, validator, errorMessage) {
|
|
445
|
-
return new VldStringFormat(format, validator, errorMessage);
|
|
446
|
-
}
|
|
447
|
-
parse(value) {
|
|
448
|
-
const result = VldString.create().parse(value);
|
|
449
|
-
if (!this._validator(result)) {
|
|
450
|
-
throw new Error(this._errorMessage || `Invalid ${this._format} format`);
|
|
451
|
-
}
|
|
452
|
-
return result;
|
|
453
|
-
}
|
|
454
|
-
safeParse(value) {
|
|
455
|
-
const stringResult = VldString.create().safeParse(value);
|
|
456
|
-
if (!stringResult.success) {
|
|
457
|
-
return stringResult;
|
|
458
|
-
}
|
|
459
|
-
if (!this._validator(stringResult.data)) {
|
|
460
|
-
return {
|
|
461
|
-
success: false,
|
|
462
|
-
error: new Error(this._errorMessage || `Invalid ${this._format} format`)
|
|
463
|
-
};
|
|
464
|
-
}
|
|
465
|
-
return { success: true, data: stringResult.data };
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
/**
|
|
469
|
-
* Top-level string format validators
|
|
470
|
-
*/
|
|
471
|
-
const email = (options) => VldStringFormat.create('email', (val) => (options?.pattern ?? REGEXES.email).test(val));
|
|
472
|
-
const uuid = (options) => {
|
|
473
|
-
const pattern = options?.version ? REGEXES[`uuid${options.version}`] : REGEXES.uuid;
|
|
474
|
-
return VldStringFormat.create('uuid', (val) => pattern.test(val));
|
|
475
|
-
};
|
|
476
|
-
const uuidv4 = () => VldStringFormat.create('uuid', (val) => REGEXES.uuidv4.test(val));
|
|
477
|
-
const hostname = () => VldStringFormat.create('hostname', (val) => REGEXES.hostname.test(val));
|
|
478
|
-
const emoji = () => VldStringFormat.create('emoji', (val) => REGEXES.emoji.test(val));
|
|
479
|
-
const base64 = () => VldStringFormat.create('base64', (val) => REGEXES.base64.test(val));
|
|
480
|
-
const base64url = () => VldStringFormat.create('base64url', (val) => REGEXES.base64url.test(val));
|
|
481
|
-
const hex = () => VldStringFormat.create('hex', (val) => REGEXES.hex.test(val));
|
|
482
|
-
const jwt = () => VldStringFormat.create('jwt', (val) => REGEXES.jwt.test(val));
|
|
483
|
-
const nanoid = () => VldStringFormat.create('nanoid', (val) => REGEXES.nanoid.test(val));
|
|
484
|
-
const cuid = () => VldStringFormat.create('cuid', (val) => REGEXES.cuid.test(val));
|
|
485
|
-
const cuid2 = () => VldStringFormat.create('cuid2', (val) => REGEXES.cuid2.test(val));
|
|
486
|
-
const ulid = () => VldStringFormat.create('ulid', (val) => REGEXES.ulid.test(val));
|
|
487
|
-
const ipv4 = () => VldStringFormat.create('ipv4', (val) => REGEXES.ipv4.test(val));
|
|
488
|
-
const ipv6 = () => VldStringFormat.create('ipv6', (val) => REGEXES.ipv6.test(val));
|
|
489
|
-
const mac = () => VldStringFormat.create('mac', (val) => REGEXES.mac.test(val));
|
|
490
|
-
const cidrv4 = () => VldStringFormat.create('cidrv4', (val) => REGEXES.cidrv4.test(val));
|
|
491
|
-
const cidrv6 = () => VldStringFormat.create('cidrv6', (val) => REGEXES.cidrv6.test(val));
|
|
492
|
-
const e164 = () => VldStringFormat.create('e164', (val) => REGEXES.e164.test(val));
|
|
493
|
-
const xid = () => VldStringFormat.create('xid', (val) => REGEXES.xid.test(val));
|
|
494
|
-
const guid = () => VldStringFormat.create('guid', (val) => REGEXES.guid.test(val));
|
|
495
|
-
const httpUrl = () => VldStringFormat.create('httpUrl', (val) => REGEXES.httpUrl.test(val));
|
|
496
|
-
const hash = (algorithm) => VldStringFormat.create('hash', (val) => REGEXES[algorithm]?.test(val) ?? false, `Invalid ${algorithm} hash`);
|
|
497
|
-
/**
|
|
498
|
-
* ISO date/time validators
|
|
499
|
-
*/
|
|
500
|
-
const iso = {
|
|
501
|
-
date: () => VldStringFormat.create('date', (val) => REGEXES.isoDate.test(val)),
|
|
502
|
-
time: () => VldStringFormat.create('time', (val) => REGEXES.isoTime.test(val)),
|
|
503
|
-
dateTime: (_options) => VldStringFormat.create('datetime', (val) => REGEXES.isoDateTime.test(val)),
|
|
504
|
-
duration: () => VldStringFormat.create('duration', (val) => /^P/.test(val)),
|
|
505
|
-
};
|
|
506
|
-
/**
|
|
507
|
-
* Custom format validator
|
|
508
|
-
*/
|
|
509
|
-
const stringFormat = (name, validator) => {
|
|
510
|
-
const fn = validator instanceof RegExp ? (val) => validator.test(val) : validator;
|
|
511
|
-
return VldStringFormat.create(name, fn);
|
|
512
|
-
};
|
|
513
|
-
|
|
514
|
-
export { VldBase, VldCustom, VldFile, VldFunction, VldPromise, VldString, VldTemplateLiteral, base64, base64url, cidrv4, cidrv6, cuid, cuid2, custom, e164, email, emoji, file, functionValidator, guid, hash, hex, hostname, httpUrl, ipv4, ipv6, iso, jwt, mac, nanoid, promise, REGEXES as regexes, stringFormat, templateLiteral, ulid, uuid, uuidv4, xid };
|
|
515
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export{VldBase,VldBrand,VldCatch,VldDefault,VldExactOptional,VldNullable,VldNullish,VldOptional,VldPipe,VldPreprocess,VldReadonly,VldRefine,VldSuperRefine,VldTransform}from"./base.js";export{VldString}from"./string.js";export{VldNumber}from"./number.js";export{VldBoolean}from"./boolean.js";export{VldDate}from"./date.js";export{VldStringBool}from"./string-bool.js";export{VldArray}from"./array.js";export{VldObject}from"./object.js";export{VldUnion}from"./union.js";export{VldIntersection}from"./intersection.js";export{VldLiteral}from"./literal.js";export{VldEnum}from"./enum.js";export{VldTuple}from"./tuple.js";export{VldRecord}from"./record.js";export{VldSet}from"./set.js";export{VldMap}from"./map.js";export{VldBigInt}from"./bigint.js";export{VldSymbol}from"./symbol.js";export{VldAny}from"./any.js";export{VldUnknown}from"./unknown.js";export{VldVoid}from"./void.js";export{VldNever}from"./never.js";export{VldNull}from"./null.js";export{VldUndefined}from"./undefined.js";export{VldNan}from"./nan.js";export{VldLazy}from"./lazy.js";export{VldDiscriminatedUnion}from"./discriminated-union.js";export{VldXor}from"./xor.js";export{VldJson}from"./json.js";export{VldTemplateLiteral,templateLiteral}from"./template-literal.js";export{VldCustom,custom}from"./custom.js";export{VldFile,file}from"./file.js";export{VldFunction,functionValidator}from"./function.js";export{VldPromise,promise}from"./promise.js";export{base64,base64url,cidrv4,cidrv6,cuid,cuid2,e164,email,emoji,guid,hash,hex,hostname,httpUrl,ipv4,ipv6,iso,jwt,ksuid,mac,nanoid,regexes,stringFormat,ulid,url,uuid,uuidv4,uuidv6,uuidv7,xid}from"./string-formats.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VldBase, ParseResult } from './base';
|
|
1
|
+
import { VldBase, ParseResult } from './base.js';
|
|
2
2
|
/**
|
|
3
3
|
* Immutable intersection validator for combining validators
|
|
4
4
|
*/
|
|
@@ -22,4 +22,3 @@ export declare class VldIntersection<A, B> extends VldBase<unknown, A & B> {
|
|
|
22
22
|
*/
|
|
23
23
|
safeParse(value: unknown): ParseResult<A & B>;
|
|
24
24
|
}
|
|
25
|
-
//# sourceMappingURL=intersection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{VldBase as t,VLD_VALIDATOR_TYPES as e}from"./base.js";import{i as r}from"../chunks/security-Dy24T8N7.js";import{getMessages as o}from"../locales/runtime.js";import{V as s}from"../chunks/errors-core-Cqi4-9ew.js";function n(t){return null!==t&&"object"==typeof t&&t.constructor===Object&&"[object Object]"===Object.prototype.toString.call(t)}function c(t,e){const o={...t},s=Object.keys(e);for(let i=0;i<s.length;i++){const a=s[i];if(r(a))continue;if(!Object.prototype.hasOwnProperty.call(e,a))continue;const u=e[a],p=t[a];n(u)&&n(p)?o[a]=c(p,u):o[a]=u}return o}class VldIntersection extends t{constructor(t,r){super(e.INTERSECTION),this.validatorA=t,this.validatorB=r}static create(t,e){return new VldIntersection(t,e)}parse(t){try{const e=this.validatorA.parse(t),r=this.validatorB.parse(t),o=n(e),s=n(r);if(o&&s)return c(e,r);if(!o&&!s){if(e===r)return e;throw new Error("Values must be identical for intersection of primitive types")}throw new Error("Cannot create intersection of object and primitive types. Both validators must produce the same type category.")}catch(t){throw new Error(o().intersectionError(t.message))}}safeParse(t){try{return{success:!0,data:this.parse(t)}}catch(t){return{success:!1,error:(e=t.message,new s([{code:"invalid_type",path:[],message:e}]))}}var e}}export{VldIntersection};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VldBase, ParseResult } from './base';
|
|
1
|
+
import { VldBase, ParseResult } from './base.js';
|
|
2
2
|
/**
|
|
3
3
|
* Immutable JSON validator that validates and parses JSON strings
|
|
4
4
|
* Accepts both strings (which are parsed) and already-parsed objects
|
|
@@ -23,4 +23,3 @@ export declare class VldJson<T = unknown> extends VldBase<unknown, T> {
|
|
|
23
23
|
*/
|
|
24
24
|
withSchema<U>(schema: VldBase<unknown, U>): VldJson<U>;
|
|
25
25
|
}
|
|
26
|
-
//# sourceMappingURL=json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{VldBase as s,VLD_VALIDATOR_TYPES as r}from"./base.js";import{getMessages as e}from"../locales/runtime.js";class VldJson extends s{constructor(s){super(r.JSON),this.schema=s}static create(s){return new VldJson(s)}parse(s){let r;if("string"==typeof s)try{r=JSON.parse(s)}catch{throw new Error(e().invalidJson)}else r=s;return this.schema?this.schema.parse(r):r}safeParse(s){try{return{success:!0,data:this.parse(s)}}catch(s){return{success:!1,error:s}}}withSchema(s){return new VldJson(s)}}export{VldJson};
|
|
@@ -3,25 +3,22 @@
|
|
|
3
3
|
* Part of Zod 4 API parity implementation
|
|
4
4
|
* Allows schemas that reference themselves (e.g., tree structures, nested categories)
|
|
5
5
|
*/
|
|
6
|
-
import { VldBase } from './base';
|
|
7
|
-
import type { ParseResult } from './base';
|
|
6
|
+
import { VldBase } from './base.js';
|
|
7
|
+
import type { ParseResult } from './base.js';
|
|
8
8
|
/**
|
|
9
9
|
* Lazy validator - defers schema evaluation until runtime
|
|
10
10
|
* Essential for recursive and self-referencing types
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* applications with dynamically created schemas.
|
|
12
|
+
* Caches the resolved schema after first use. This keeps recursive schemas stable
|
|
13
|
+
* and avoids re-running the schema getter on hot parse paths.
|
|
15
14
|
*/
|
|
16
15
|
export declare class VldLazy<TInput, TOutput> extends VldBase<TInput, TOutput> {
|
|
17
16
|
private readonly _schemaGetter;
|
|
18
|
-
private
|
|
19
|
-
private _strongRef;
|
|
17
|
+
private _cachedSchema;
|
|
20
18
|
private constructor();
|
|
21
19
|
static create<TInput, TOutput>(schemaGetter: () => VldBase<TInput, TOutput>): VldLazy<TInput, TOutput>;
|
|
22
20
|
/**
|
|
23
21
|
* Get the actual schema, caching it after first retrieval
|
|
24
|
-
* Uses WeakRef to allow garbage collection when validator is not in use
|
|
25
22
|
*/
|
|
26
23
|
private _getSchema;
|
|
27
24
|
/**
|
|
@@ -32,4 +29,3 @@ export declare class VldLazy<TInput, TOutput> extends VldBase<TInput, TOutput> {
|
|
|
32
29
|
parse(value: unknown): TOutput;
|
|
33
30
|
safeParse(value: unknown): ParseResult<TOutput>;
|
|
34
31
|
}
|
|
35
|
-
//# sourceMappingURL=lazy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{VldBase as e,VLD_VALIDATOR_TYPES as t}from"./base.js";class VldLazy extends e{constructor(e){super(t.LAZY),this._schemaGetter=e,this._cachedSchema=null}static create(e){return new VldLazy(e)}_getSchema(){if(this._cachedSchema)return this._cachedSchema;const e=this._schemaGetter();return this._cachedSchema=e,e}unwrap(){return this._getSchema()}parse(e){return this._getSchema().parse(e)}safeParse(e){return this._getSchema().safeParse(e)}}export{VldLazy};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { VldBase, ParseResult } from './base';
|
|
1
|
+
import { VldBase, ParseResult } from './base.js';
|
|
2
2
|
/**
|
|
3
3
|
* Immutable literal validator for exact value matching
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
6
|
-
|
|
5
|
+
export type LiteralValue = string | number | bigint | boolean | null | undefined;
|
|
6
|
+
export declare class VldLiteral<T extends LiteralValue> extends VldBase<T, T> {
|
|
7
|
+
private readonly _values;
|
|
7
8
|
private readonly errorMessage?;
|
|
8
9
|
/**
|
|
9
10
|
* Private constructor to enforce immutability
|
|
@@ -13,17 +14,20 @@ export declare class VldLiteral<T extends string | number | boolean | null | und
|
|
|
13
14
|
* Get the literal value
|
|
14
15
|
*/
|
|
15
16
|
get literal(): T;
|
|
17
|
+
get values(): readonly T[];
|
|
18
|
+
get isSimple(): boolean;
|
|
19
|
+
private get expectedDisplay();
|
|
16
20
|
/**
|
|
17
21
|
* Create a new literal validator
|
|
18
22
|
*/
|
|
19
|
-
static create<T extends
|
|
23
|
+
static create<T extends LiteralValue>(literal: T | readonly T[]): VldLiteral<T>;
|
|
20
24
|
/**
|
|
21
25
|
* Parse and validate a literal value
|
|
22
26
|
*/
|
|
23
27
|
parse(value: unknown): T;
|
|
28
|
+
private _createLiteralError;
|
|
24
29
|
/**
|
|
25
30
|
* Safely parse and validate a literal value
|
|
26
31
|
*/
|
|
27
32
|
safeParse(value: unknown): ParseResult<T>;
|
|
28
33
|
}
|
|
29
|
-
//# sourceMappingURL=literal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{VldBase as e,VLD_VALIDATOR_TYPES as r}from"./base.js";import{getMessages as t}from"../locales/runtime.js";import{V as s}from"../chunks/errors-core-Cqi4-9ew.js";function a(e){const r=JSON.stringify(e,(e,r)=>"bigint"==typeof r?r.toString():r);return void 0===r?String(e):r}class VldLiteral extends e{constructor(e,t){super(r.LITERAL),this._values=e,this.errorMessage=t}get literal(){return this._values[0]}get values(){return this._values}get isSimple(){return 1===this._values.length}get expectedDisplay(){return a(1===this._values.length?this._values[0]:this._values)}static create(e){const r=Array.isArray(e)?e:[e];if(0===r.length)throw new Error("Cannot create literal schema with no valid values");return new VldLiteral(r)}parse(e){if(!this._values.includes(e))throw this._createLiteralError(e);return e}_createLiteralError(e){const r={code:"invalid_value",path:[],values:[...this._values],message:this.errorMessage||t().literalExpected(this.expectedDisplay,a(e))};return new s([r])}safeParse(e){return this._values.includes(e)?{success:!0,data:e}:{success:!1,error:this._createLiteralError(e)}}}export{VldLiteral};
|
package/dist/validators/map.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VldBase, ParseResult } from './base';
|
|
1
|
+
import { VldBase, ParseResult } from './base.js';
|
|
2
2
|
/**
|
|
3
3
|
* Immutable Map validator
|
|
4
4
|
*/
|
|
@@ -10,17 +10,30 @@ export declare class VldMap<K, V> extends VldBase<unknown, Map<K, V>> {
|
|
|
10
10
|
* Private constructor to enforce immutability
|
|
11
11
|
*/
|
|
12
12
|
private constructor();
|
|
13
|
+
private readonly _simpleKeyMode;
|
|
14
|
+
private readonly _simpleValueMode;
|
|
15
|
+
private readonly _simpleKeyValue;
|
|
16
|
+
private readonly _simpleValueValue;
|
|
17
|
+
get keySchema(): VldBase<unknown, K>;
|
|
18
|
+
get valueSchema(): VldBase<unknown, V>;
|
|
13
19
|
/**
|
|
14
20
|
* Create a new Map validator
|
|
15
21
|
*/
|
|
16
22
|
static create<K, V>(keyValidator: VldBase<unknown, K>, valueValidator: VldBase<unknown, V>): VldMap<K, V>;
|
|
23
|
+
private getSimpleItemMode;
|
|
24
|
+
private getSimpleItemError;
|
|
25
|
+
private parseSimpleItem;
|
|
17
26
|
/**
|
|
18
27
|
* Parse and validate a Map value
|
|
19
28
|
*/
|
|
20
29
|
parse(value: unknown): Map<K, V>;
|
|
30
|
+
/**
|
|
31
|
+
* Parse a value that has already passed the Map instance guard.
|
|
32
|
+
* @internal Used by object validators to avoid duplicate hot-path checks.
|
|
33
|
+
*/
|
|
34
|
+
parseKnownMap(value: Map<unknown, unknown>): Map<K, V>;
|
|
21
35
|
/**
|
|
22
36
|
* Safely parse and validate a Map value
|
|
23
37
|
*/
|
|
24
38
|
safeParse(value: unknown): ParseResult<Map<K, V>>;
|
|
25
39
|
}
|
|
26
|
-
//# sourceMappingURL=map.d.ts.map
|