@oxog/vld 2.0.2 → 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.
- package/CHANGELOG.md +75 -1
- package/LICENSE +20 -20
- package/README.md +101 -37
- package/dist/chunks/errors-core-BeiFUtZM.js +81 -0
- package/dist/chunks/{index-CETyGkrv.js → index-0R2ntSud.js} +16 -402
- package/dist/chunks/index-BvH403Yy.js +88 -0
- package/dist/chunks/security-B0Pd_vSY.js +35 -0
- package/dist/chunks/string-BJRQod3t.js +530 -0
- package/dist/cjs/chunks/errors-core-DWxLFs2f.cjs +83 -0
- package/dist/cjs/chunks/index-BkI37108.cjs +538 -0
- package/dist/cjs/chunks/index-Cc3bjUMX.cjs +91 -0
- package/dist/cjs/chunks/security-Dc3Jh13T.cjs +37 -0
- package/dist/cjs/chunks/string-BKZrc4hs.cjs +533 -0
- package/dist/cjs/cli/bin.cjs +506 -0
- package/dist/cjs/cli/index.cjs +209 -0
- package/dist/cjs/codecs/index.cjs +45 -0
- package/dist/{chunks/date-ODue_rtq.js → cjs/coercion/index.cjs} +185 -103
- package/dist/cjs/compat/emitter.cjs +184 -0
- package/dist/cjs/compat/result.cjs +189 -0
- package/dist/cjs/errors.cjs +6 -213
- package/dist/cjs/index.cjs +1558 -9647
- package/dist/cjs/kernel.cjs +415 -0
- package/dist/cjs/locales/af.cjs +108 -0
- package/dist/cjs/locales/ar.cjs +108 -0
- package/dist/cjs/locales/bn.cjs +108 -0
- package/dist/cjs/locales/da.cjs +108 -0
- package/dist/cjs/locales/de.cjs +108 -0
- package/dist/cjs/locales/en.cjs +108 -0
- package/dist/cjs/locales/es-MX.cjs +107 -0
- package/dist/cjs/locales/es.cjs +96 -0
- package/dist/cjs/locales/fi.cjs +108 -0
- package/dist/cjs/locales/fr.cjs +96 -0
- package/dist/cjs/locales/hi.cjs +108 -0
- package/dist/cjs/locales/id.cjs +108 -0
- package/dist/cjs/locales/index.cjs +41 -2875
- package/dist/cjs/locales/it.cjs +108 -0
- package/dist/cjs/locales/ja.cjs +108 -0
- package/dist/cjs/locales/ko.cjs +108 -0
- package/dist/cjs/locales/lazy.cjs +42 -3023
- package/dist/cjs/locales/nl.cjs +108 -0
- package/dist/cjs/locales/no.cjs +108 -0
- package/dist/cjs/locales/pl.cjs +108 -0
- package/dist/cjs/locales/pt-BR.cjs +108 -0
- package/dist/cjs/locales/pt.cjs +108 -0
- package/dist/cjs/locales/ru.cjs +108 -0
- package/dist/cjs/locales/runtime.cjs +51 -0
- package/dist/cjs/locales/sv.cjs +108 -0
- package/dist/cjs/locales/sw.cjs +108 -0
- package/dist/cjs/locales/th.cjs +108 -0
- package/dist/cjs/locales/tr.cjs +108 -0
- package/dist/cjs/locales/vi.cjs +108 -0
- package/dist/cjs/locales/zh.cjs +108 -0
- package/dist/cjs/mini.cjs +121 -7208
- package/dist/cjs/pigment.cjs +207 -0
- package/dist/cjs/plugins/index.cjs +12 -0
- package/dist/cjs/registry.cjs +37 -0
- package/dist/cjs/v3/index.cjs +425 -0
- package/dist/cjs/v4/core/index.cjs +894 -0
- package/dist/cjs/v4/index.cjs +425 -0
- package/dist/cjs/v4/locales/index.cjs +130 -0
- package/dist/cjs/v4/mini/index.cjs +509 -0
- package/dist/cjs/v4-mini/index.cjs +532 -0
- package/dist/cjs/validators/any.cjs +40 -0
- package/dist/cjs/validators/array.cjs +283 -0
- package/dist/cjs/validators/base.cjs +887 -0
- package/dist/cjs/validators/base64.cjs +73 -0
- package/dist/cjs/validators/bigint.cjs +232 -0
- package/dist/cjs/validators/boolean.cjs +146 -0
- package/dist/cjs/validators/codec.cjs +205 -0
- package/dist/cjs/validators/custom.cjs +71 -0
- package/dist/cjs/validators/date.cjs +278 -0
- package/dist/cjs/validators/discriminated-union.cjs +130 -0
- package/dist/cjs/validators/enum.cjs +154 -0
- package/dist/cjs/validators/file.cjs +130 -0
- package/dist/cjs/validators/function.cjs +63 -0
- package/dist/cjs/validators/hex.cjs +70 -0
- package/dist/cjs/validators/index.cjs +123 -0
- package/dist/cjs/validators/intersection.cjs +120 -0
- package/dist/cjs/validators/json.cjs +70 -0
- package/dist/cjs/validators/lazy.cjs +53 -0
- package/dist/cjs/validators/literal.cjs +64 -0
- package/dist/cjs/validators/map.cjs +218 -0
- package/dist/cjs/validators/nan.cjs +41 -0
- package/dist/cjs/validators/never.cjs +36 -0
- package/dist/cjs/validators/null.cjs +43 -0
- package/dist/cjs/validators/number.cjs +427 -0
- package/dist/cjs/validators/object.cjs +868 -0
- package/dist/cjs/validators/promise.cjs +115 -0
- package/dist/cjs/validators/record.cjs +262 -0
- package/dist/cjs/validators/set.cjs +203 -0
- package/dist/cjs/validators/string-bool.cjs +124 -0
- package/dist/cjs/validators/string-formats.cjs +168 -0
- package/dist/cjs/validators/string.cjs +12 -0
- package/dist/cjs/validators/symbol.cjs +62 -0
- package/dist/cjs/validators/template-literal.cjs +108 -0
- package/dist/cjs/validators/tuple.cjs +187 -0
- package/dist/cjs/validators/uint8array.cjs +106 -0
- package/dist/cjs/validators/undefined.cjs +43 -0
- package/dist/cjs/validators/union.cjs +191 -0
- package/dist/cjs/validators/unknown.cjs +40 -0
- package/dist/cjs/validators/void.cjs +48 -0
- package/dist/cjs/validators/xor.cjs +69 -0
- package/dist/cli/bin.d.ts +0 -1
- package/dist/cli/bin.js +407 -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 +205 -0
- package/dist/codecs/index.d.ts +21 -4
- package/dist/codecs/index.js +11 -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 +473 -5
- 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 +0 -1
- package/dist/compat/index.d.ts +4 -5
- package/dist/compat/result.d.ts +1 -2
- package/dist/compat/result.js +0 -1
- package/dist/errors-core.d.ts +39 -0
- package/dist/errors.d.ts +4 -54
- package/dist/errors.js +4 -68
- package/dist/events.d.ts +3 -4
- package/dist/index.d.ts +1195 -600
- package/dist/index.js +1262 -44
- package/dist/kernel.d.ts +2 -3
- package/dist/kernel.js +10 -6
- package/dist/locales/af.d.ts +1 -2
- package/dist/locales/af.js +0 -1
- package/dist/locales/ar.d.ts +1 -2
- package/dist/locales/ar.js +0 -1
- package/dist/locales/bn.d.ts +1 -2
- package/dist/locales/bn.js +0 -1
- package/dist/locales/da.d.ts +1 -2
- package/dist/locales/da.js +0 -1
- package/dist/locales/de.d.ts +1 -2
- package/dist/locales/de.js +0 -1
- package/dist/locales/en.d.ts +1 -2
- package/dist/locales/en.js +0 -1
- package/dist/locales/es-MX.d.ts +1 -2
- package/dist/locales/es-MX.js +0 -1
- package/dist/locales/es.d.ts +1 -2
- package/dist/locales/es.js +0 -1
- package/dist/locales/fi.d.ts +1 -2
- package/dist/locales/fi.js +0 -1
- package/dist/locales/fr.d.ts +1 -2
- package/dist/locales/fr.js +0 -1
- package/dist/locales/hi.d.ts +1 -2
- package/dist/locales/hi.js +0 -1
- package/dist/locales/id.d.ts +1 -2
- package/dist/locales/id.js +0 -1
- package/dist/locales/index.d.ts +10 -15
- package/dist/locales/index.js +28 -2
- package/dist/locales/it.d.ts +1 -2
- package/dist/locales/it.js +0 -1
- package/dist/locales/ja.d.ts +1 -2
- package/dist/locales/ja.js +0 -1
- package/dist/locales/ko.d.ts +1 -2
- package/dist/locales/ko.js +0 -1
- package/dist/locales/lazy.d.ts +4 -26
- package/dist/locales/lazy.js +12 -55
- package/dist/locales/nl.d.ts +1 -2
- package/dist/locales/nl.js +0 -1
- package/dist/locales/no.d.ts +1 -2
- package/dist/locales/no.js +0 -1
- package/dist/locales/pl.d.ts +1 -2
- package/dist/locales/pl.js +0 -1
- package/dist/locales/pt-BR.d.ts +1 -2
- package/dist/locales/pt-BR.js +0 -1
- package/dist/locales/pt.d.ts +1 -2
- package/dist/locales/pt.js +0 -1
- package/dist/locales/ru.d.ts +1 -2
- package/dist/locales/ru.js +0 -1
- package/dist/locales/runtime.d.ts +10 -0
- package/dist/locales/runtime.js +41 -0
- package/dist/locales/sv.d.ts +1 -2
- package/dist/locales/sv.js +0 -1
- package/dist/locales/sw.d.ts +1 -2
- package/dist/locales/sw.js +0 -1
- package/dist/locales/th.d.ts +1 -2
- package/dist/locales/th.js +0 -1
- package/dist/locales/tr.d.ts +1 -2
- package/dist/locales/tr.js +0 -1
- package/dist/locales/types.d.ts +0 -1
- package/dist/locales/vi.d.ts +1 -2
- package/dist/locales/vi.js +0 -1
- package/dist/locales/zh.d.ts +1 -2
- package/dist/locales/zh.js +0 -1
- package/dist/logger.d.ts +0 -1
- package/dist/mini.d.ts +64 -65
- package/dist/mini.js +31 -7
- package/dist/pigment.d.ts +0 -1
- package/dist/pigment.js +6 -4
- 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 +34 -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 +77 -0
- package/dist/utils/security.d.ts +2 -6
- package/dist/v3/index.d.ts +2 -0
- package/dist/v3/index.js +46 -0
- package/dist/v4/core/index.d.ts +260 -0
- package/dist/v4/core/index.js +277 -0
- package/dist/v4/index.d.ts +4 -0
- package/dist/v4/index.js +50 -0
- package/dist/v4/locales/index.d.ts +53 -0
- package/dist/v4/locales/index.js +77 -0
- package/dist/v4/mini/index.d.ts +2 -0
- package/dist/v4/mini/index.js +47 -0
- package/dist/v4-mini/index.d.ts +22 -0
- package/dist/v4-mini/index.js +75 -0
- package/dist/validators/any.d.ts +7 -2
- package/dist/validators/any.js +37 -0
- package/dist/validators/array.d.ts +9 -2
- package/dist/validators/array.js +279 -0
- package/dist/validators/base.d.ts +228 -5
- package/dist/validators/base.js +868 -0
- package/dist/validators/base64.d.ts +1 -2
- package/dist/validators/base64.js +68 -0
- package/dist/validators/bigint.d.ts +21 -3
- package/dist/validators/bigint.js +228 -0
- package/dist/validators/boolean.d.ts +13 -4
- package/dist/validators/boolean.js +142 -0
- package/dist/validators/codec.d.ts +9 -2
- package/dist/validators/codec.js +200 -0
- package/dist/validators/custom.d.ts +15 -2
- package/dist/validators/custom.js +67 -0
- package/dist/validators/date.d.ts +19 -3
- package/dist/validators/date.js +274 -0
- package/dist/validators/discriminated-union.d.ts +4 -3
- package/dist/validators/discriminated-union.js +123 -0
- package/dist/validators/enum.d.ts +10 -7
- package/dist/validators/enum.js +150 -0
- package/dist/validators/file.d.ts +7 -2
- package/dist/validators/file.js +125 -0
- package/dist/validators/function.d.ts +11 -5
- package/dist/validators/function.js +58 -0
- package/dist/validators/hex.d.ts +1 -2
- package/dist/validators/hex.js +65 -0
- package/dist/validators/index.d.ts +38 -38
- package/dist/validators/index.js +35 -5
- package/dist/validators/intersection.d.ts +1 -2
- package/dist/validators/intersection.js +116 -0
- package/dist/validators/json.d.ts +1 -2
- package/dist/validators/json.js +66 -0
- package/dist/validators/lazy.d.ts +5 -9
- package/dist/validators/lazy.js +50 -0
- package/dist/validators/literal.d.ts +2 -2
- package/dist/validators/literal.js +60 -0
- package/dist/validators/map.d.ts +15 -2
- package/dist/validators/map.js +214 -0
- package/dist/validators/nan.d.ts +2 -3
- package/dist/validators/nan.js +38 -0
- package/dist/validators/never.d.ts +1 -2
- package/dist/validators/never.js +32 -0
- package/dist/validators/null.d.ts +3 -3
- package/dist/validators/null.js +40 -0
- package/dist/validators/number.d.ts +80 -21
- package/dist/validators/number.js +423 -0
- package/dist/validators/object.d.ts +30 -9
- package/dist/validators/object.js +864 -0
- package/dist/validators/promise.d.ts +58 -0
- package/dist/validators/promise.js +111 -0
- package/dist/validators/record.d.ts +11 -2
- package/dist/validators/record.js +258 -0
- package/dist/validators/set.d.ts +11 -2
- package/dist/validators/set.js +199 -0
- package/dist/validators/string-bool.d.ts +7 -10
- package/dist/validators/string-bool.js +120 -0
- package/dist/validators/string-formats.d.ts +13 -4
- package/dist/validators/string-formats.js +135 -0
- package/dist/validators/string.d.ts +39 -18
- package/dist/validators/string.js +4 -0
- package/dist/validators/symbol.d.ts +8 -3
- package/dist/validators/symbol.js +58 -0
- package/dist/validators/template-literal.d.ts +1 -2
- package/dist/validators/template-literal.js +103 -0
- package/dist/validators/tuple.d.ts +15 -2
- package/dist/validators/tuple.js +183 -0
- package/dist/validators/uint8array.d.ts +3 -4
- package/dist/validators/uint8array.js +101 -0
- package/dist/validators/undefined.d.ts +3 -3
- package/dist/validators/undefined.js +40 -0
- package/dist/validators/union.d.ts +7 -4
- package/dist/validators/union.js +187 -0
- package/dist/validators/unknown.d.ts +7 -2
- package/dist/{chunks/unknown-SLIH1VCf.js → validators/unknown.js} +12 -3
- package/dist/validators/void.d.ts +3 -2
- package/dist/validators/void.js +44 -0
- package/dist/validators/xor.d.ts +2 -3
- package/dist/validators/xor.js +66 -0
- package/package.json +116 -31
- package/dist/chunks/bigint-DgsCr2dC.js +0 -1709
- package/dist/chunks/bigint-DgsCr2dC.js.map +0 -1
- package/dist/chunks/date-ODue_rtq.js.map +0 -1
- package/dist/chunks/index-BZqWZvVe.js +0 -426
- package/dist/chunks/index-BZqWZvVe.js.map +0 -1
- package/dist/chunks/index-CETyGkrv.js.map +0 -1
- package/dist/chunks/json-o20GFhTh.js +0 -2021
- package/dist/chunks/json-o20GFhTh.js.map +0 -1
- package/dist/chunks/unknown-SLIH1VCf.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/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/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
|
@@ -0,0 +1,168 @@
|
|
|
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
|
+
* Top-level string format validators
|
|
10
|
+
* Part of Zod 4 API parity implementation
|
|
11
|
+
* Provides convenient validators for common string formats
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Pre-compiled regex patterns for performance
|
|
15
|
+
*/
|
|
16
|
+
const REGEXES = {
|
|
17
|
+
email: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
|
|
18
|
+
uuid: /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,
|
|
19
|
+
uuidv4: /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,
|
|
20
|
+
uuidv6: /^[0-9a-f]{8}-[0-9a-f]{4}-6[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,
|
|
21
|
+
uuidv7: /^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,
|
|
22
|
+
hostname: /^(?=.{1,253}$)(?:(?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,63}$/,
|
|
23
|
+
emoji: /^(?:\p{Emoji_Presentation}|\p{Emoji}\uFE0F)(?:\u200D(?:\p{Emoji_Presentation}|\p{Emoji}\uFE0F))*$/u,
|
|
24
|
+
base64: /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,
|
|
25
|
+
base64url: /^[A-Za-z0-9_-]*$/,
|
|
26
|
+
hex: /^[0-9a-fA-F]*$/,
|
|
27
|
+
jwt: /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$/,
|
|
28
|
+
nanoid: /^[A-Za-z0-9_-]{21}$/,
|
|
29
|
+
cuid: /^c[^\s-]{8,}$/i,
|
|
30
|
+
cuid2: /^[0-9a-z]+$/,
|
|
31
|
+
ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
|
|
32
|
+
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]?)$/,
|
|
33
|
+
ipv6: /^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/,
|
|
34
|
+
mac: /^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$/,
|
|
35
|
+
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])$/,
|
|
36
|
+
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])$/,
|
|
37
|
+
e164: /^\+[1-9]\d{1,14}$/,
|
|
38
|
+
isoDate: /^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/,
|
|
39
|
+
isoTime: /^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?$/,
|
|
40
|
+
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?$/,
|
|
41
|
+
md5: /^[a-f0-9]{32}$/i,
|
|
42
|
+
sha1: /^[a-f0-9]{40}$/i,
|
|
43
|
+
sha256: /^[a-f0-9]{64}$/i,
|
|
44
|
+
sha384: /^[a-f0-9]{96}$/i,
|
|
45
|
+
sha512: /^[a-f0-9]{128}$/i,
|
|
46
|
+
// Additional formats (Zod v4 parity)
|
|
47
|
+
xid: /^[A-HJKMNP-TV-Z0-9]{20}$/, // ksort's XID format
|
|
48
|
+
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
|
|
49
|
+
httpUrl: /^https?:\/\/[^\s/$.?#].[^\s]*$/, // HTTP/HTTPS URL
|
|
50
|
+
ksuid: /^[0-9A-Za-z]{27}$/,
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Generic string format validator
|
|
54
|
+
*/
|
|
55
|
+
class VldStringFormat extends validators_base.VldBase {
|
|
56
|
+
constructor(_format, _validator, _errorMessage) {
|
|
57
|
+
super(validators_base.VLD_VALIDATOR_TYPES.STRING_FORMAT);
|
|
58
|
+
this._format = _format;
|
|
59
|
+
this._validator = _validator;
|
|
60
|
+
this._errorMessage = _errorMessage;
|
|
61
|
+
}
|
|
62
|
+
static create(format, validator, errorMessage) {
|
|
63
|
+
return new VldStringFormat(format, validator, errorMessage);
|
|
64
|
+
}
|
|
65
|
+
parse(value) {
|
|
66
|
+
if (typeof value !== 'string') {
|
|
67
|
+
throw new Error(locales_runtime.getMessages().invalidString);
|
|
68
|
+
}
|
|
69
|
+
if (!this._validator(value)) {
|
|
70
|
+
throw new Error(this._errorMessage || `Invalid ${this._format} format`);
|
|
71
|
+
}
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
safeParse(value) {
|
|
75
|
+
if (typeof value !== 'string') {
|
|
76
|
+
return {
|
|
77
|
+
success: false,
|
|
78
|
+
error: new Error(locales_runtime.getMessages().invalidString)
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (!this._validator(value)) {
|
|
82
|
+
return {
|
|
83
|
+
success: false,
|
|
84
|
+
error: new Error(this._errorMessage || `Invalid ${this._format} format`)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return { success: true, data: value };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Top-level string format validators
|
|
92
|
+
*/
|
|
93
|
+
const email = (options) => VldStringFormat.create('email', (val) => (options?.pattern ?? REGEXES.email).test(val));
|
|
94
|
+
const uuid = (options) => {
|
|
95
|
+
const pattern = options?.version ? REGEXES[`uuid${options.version}`] : REGEXES.uuid;
|
|
96
|
+
return VldStringFormat.create('uuid', (val) => pattern.test(val));
|
|
97
|
+
};
|
|
98
|
+
const uuidv4 = () => VldStringFormat.create('uuid', (val) => REGEXES.uuidv4.test(val));
|
|
99
|
+
const uuidv6 = () => VldStringFormat.create('uuid', (val) => REGEXES.uuidv6.test(val));
|
|
100
|
+
const uuidv7 = () => VldStringFormat.create('uuid', (val) => REGEXES.uuidv7.test(val));
|
|
101
|
+
const hostname = () => VldStringFormat.create('hostname', (val) => REGEXES.hostname.test(val));
|
|
102
|
+
const emoji = () => VldStringFormat.create('emoji', (val) => REGEXES.emoji.test(val));
|
|
103
|
+
const base64 = () => VldStringFormat.create('base64', (val) => REGEXES.base64.test(val));
|
|
104
|
+
const base64url = () => VldStringFormat.create('base64url', (val) => REGEXES.base64url.test(val));
|
|
105
|
+
const hex = () => VldStringFormat.create('hex', (val) => REGEXES.hex.test(val));
|
|
106
|
+
const jwt = () => VldStringFormat.create('jwt', (val) => REGEXES.jwt.test(val));
|
|
107
|
+
const nanoid = () => VldStringFormat.create('nanoid', (val) => REGEXES.nanoid.test(val));
|
|
108
|
+
const cuid = () => VldStringFormat.create('cuid', (val) => REGEXES.cuid.test(val));
|
|
109
|
+
const cuid2 = () => VldStringFormat.create('cuid2', (val) => REGEXES.cuid2.test(val));
|
|
110
|
+
const ulid = () => VldStringFormat.create('ulid', (val) => REGEXES.ulid.test(val));
|
|
111
|
+
const ipv4 = () => VldStringFormat.create('ipv4', (val) => REGEXES.ipv4.test(val));
|
|
112
|
+
const ipv6 = () => VldStringFormat.create('ipv6', (val) => REGEXES.ipv6.test(val));
|
|
113
|
+
const mac = () => VldStringFormat.create('mac', (val) => REGEXES.mac.test(val));
|
|
114
|
+
const cidrv4 = () => VldStringFormat.create('cidrv4', (val) => REGEXES.cidrv4.test(val));
|
|
115
|
+
const cidrv6 = () => VldStringFormat.create('cidrv6', (val) => REGEXES.cidrv6.test(val));
|
|
116
|
+
const e164 = () => VldStringFormat.create('e164', (val) => REGEXES.e164.test(val));
|
|
117
|
+
const xid = () => VldStringFormat.create('xid', (val) => REGEXES.xid.test(val));
|
|
118
|
+
const guid = () => VldStringFormat.create('guid', (val) => REGEXES.guid.test(val));
|
|
119
|
+
const httpUrl = () => VldStringFormat.create('httpUrl', (val) => REGEXES.httpUrl.test(val));
|
|
120
|
+
const ksuid = () => VldStringFormat.create('ksuid', (val) => REGEXES.ksuid.test(val));
|
|
121
|
+
const hash = (algorithm) => VldStringFormat.create('hash', (val) => REGEXES[algorithm]?.test(val) ?? false, `Invalid ${algorithm} hash`);
|
|
122
|
+
/**
|
|
123
|
+
* ISO date/time validators
|
|
124
|
+
*/
|
|
125
|
+
const iso = {
|
|
126
|
+
date: () => VldStringFormat.create('date', (val) => REGEXES.isoDate.test(val)),
|
|
127
|
+
time: () => VldStringFormat.create('time', (val) => REGEXES.isoTime.test(val)),
|
|
128
|
+
dateTime: (_options) => VldStringFormat.create('datetime', (val) => REGEXES.isoDateTime.test(val)),
|
|
129
|
+
duration: () => VldStringFormat.create('duration', (val) => /^-?P(?!$)(?:\d+(?:\.\d+)?Y)?(?:\d+(?:\.\d+)?M)?(?:\d+(?:\.\d+)?W)?(?:\d+(?:\.\d+)?D)?(?:T(?=\d)(?:\d+(?:\.\d+)?H)?(?:\d+(?:\.\d+)?M)?(?:\d+(?:\.\d+)?S)?)?$/.test(val)),
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Custom format validator
|
|
133
|
+
*/
|
|
134
|
+
const stringFormat = (name, validator) => {
|
|
135
|
+
const fn = validator instanceof RegExp ? (val) => validator.test(val) : validator;
|
|
136
|
+
return VldStringFormat.create(name, fn);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
exports.VldStringFormat = VldStringFormat;
|
|
140
|
+
exports.base64 = base64;
|
|
141
|
+
exports.base64url = base64url;
|
|
142
|
+
exports.cidrv4 = cidrv4;
|
|
143
|
+
exports.cidrv6 = cidrv6;
|
|
144
|
+
exports.cuid = cuid;
|
|
145
|
+
exports.cuid2 = cuid2;
|
|
146
|
+
exports.e164 = e164;
|
|
147
|
+
exports.email = email;
|
|
148
|
+
exports.emoji = emoji;
|
|
149
|
+
exports.guid = guid;
|
|
150
|
+
exports.hash = hash;
|
|
151
|
+
exports.hex = hex;
|
|
152
|
+
exports.hostname = hostname;
|
|
153
|
+
exports.httpUrl = httpUrl;
|
|
154
|
+
exports.ipv4 = ipv4;
|
|
155
|
+
exports.ipv6 = ipv6;
|
|
156
|
+
exports.iso = iso;
|
|
157
|
+
exports.jwt = jwt;
|
|
158
|
+
exports.ksuid = ksuid;
|
|
159
|
+
exports.mac = mac;
|
|
160
|
+
exports.nanoid = nanoid;
|
|
161
|
+
exports.regexes = REGEXES;
|
|
162
|
+
exports.stringFormat = stringFormat;
|
|
163
|
+
exports.ulid = ulid;
|
|
164
|
+
exports.uuid = uuid;
|
|
165
|
+
exports.uuidv4 = uuidv4;
|
|
166
|
+
exports.uuidv6 = uuidv6;
|
|
167
|
+
exports.uuidv7 = uuidv7;
|
|
168
|
+
exports.xid = xid;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('./base.cjs');
|
|
4
|
+
require('../locales/runtime.cjs');
|
|
5
|
+
var validators_string = require('../chunks/string-BKZrc4hs.cjs');
|
|
6
|
+
require('../chunks/errors-core-DWxLFs2f.cjs');
|
|
7
|
+
require('../registry.cjs');
|
|
8
|
+
require('../locales/en.cjs');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.VldString = validators_string.VldString;
|
|
@@ -0,0 +1,62 @@
|
|
|
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 createSymbolError(message) {
|
|
10
|
+
return new errorsCore.VldError([{ code: 'invalid_type', path: [], message }]);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Immutable symbol validator
|
|
14
|
+
*/
|
|
15
|
+
class VldSymbol extends validators_base.VldBase {
|
|
16
|
+
/**
|
|
17
|
+
* Private constructor to enforce immutability
|
|
18
|
+
*/
|
|
19
|
+
constructor(errorMessage) {
|
|
20
|
+
super(validators_base.VLD_VALIDATOR_TYPES.SYMBOL);
|
|
21
|
+
this.errorMessage = errorMessage;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Create a new symbol validator
|
|
25
|
+
*/
|
|
26
|
+
static create() {
|
|
27
|
+
return new VldSymbol();
|
|
28
|
+
}
|
|
29
|
+
get isSimple() {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Parse and validate a symbol value
|
|
34
|
+
*/
|
|
35
|
+
parse(value) {
|
|
36
|
+
if (typeof value !== 'symbol') {
|
|
37
|
+
throw new Error(this.errorMessage || locales_runtime.getMessages().invalidSymbol);
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Parse a value that has already passed the symbol type guard.
|
|
43
|
+
* @internal Used by object validators to avoid duplicate hot-path checks.
|
|
44
|
+
*/
|
|
45
|
+
parseKnownSymbol(value) {
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Safely parse and validate a symbol value
|
|
50
|
+
*/
|
|
51
|
+
safeParse(value) {
|
|
52
|
+
if (typeof value === 'symbol') {
|
|
53
|
+
return { success: true, data: value };
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
success: false,
|
|
57
|
+
error: createSymbolError(this.errorMessage || locales_runtime.getMessages().invalidSymbol)
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
exports.VldSymbol = VldSymbol;
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
* Immutable template literal validator
|
|
10
|
+
* Validates strings matching a template pattern
|
|
11
|
+
*/
|
|
12
|
+
class VldTemplateLiteral extends validators_base.VldBase {
|
|
13
|
+
constructor(pattern) {
|
|
14
|
+
super(validators_base.VLD_VALIDATOR_TYPES.TEMPLATE_LITERAL);
|
|
15
|
+
this.pattern = pattern;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create a template literal validator from components
|
|
19
|
+
*/
|
|
20
|
+
static create(...components) {
|
|
21
|
+
// Build regex pattern from components
|
|
22
|
+
let pattern = '^';
|
|
23
|
+
for (const comp of components) {
|
|
24
|
+
if (typeof comp === 'string') {
|
|
25
|
+
// Escape special regex characters
|
|
26
|
+
pattern += comp.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
// Add appropriate pattern based on validator type
|
|
30
|
+
pattern += getPatternForValidator(comp);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
pattern += '$';
|
|
34
|
+
return new VldTemplateLiteral(new RegExp(pattern));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Parse and validate a template literal string
|
|
38
|
+
*/
|
|
39
|
+
parse(value) {
|
|
40
|
+
if (typeof value !== 'string') {
|
|
41
|
+
throw new Error(locales_runtime.getMessages().invalidString);
|
|
42
|
+
}
|
|
43
|
+
if (!this.pattern.test(value)) {
|
|
44
|
+
throw new Error(locales_runtime.getMessages().stringPatternInvalid);
|
|
45
|
+
}
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Safely parse and validate a template literal string
|
|
50
|
+
*/
|
|
51
|
+
safeParse(value) {
|
|
52
|
+
try {
|
|
53
|
+
return { success: true, data: this.parse(value) };
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
return {
|
|
57
|
+
success: false,
|
|
58
|
+
error: error
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get regex pattern for a validator type
|
|
65
|
+
*/
|
|
66
|
+
function getPatternForValidator(validator) {
|
|
67
|
+
// For template literals, we need to identify the validator type
|
|
68
|
+
// and return an appropriate capture group pattern
|
|
69
|
+
switch (validator.validatorType) {
|
|
70
|
+
case validators_base.VLD_VALIDATOR_TYPES.STRING:
|
|
71
|
+
case validators_base.VLD_VALIDATOR_TYPES.STRING_FORMAT:
|
|
72
|
+
return '(.+)';
|
|
73
|
+
case validators_base.VLD_VALIDATOR_TYPES.NUMBER:
|
|
74
|
+
case validators_base.VLD_VALIDATOR_TYPES.COERCE_NUMBER:
|
|
75
|
+
return '(-?\\d+(?:\\.\\d+)?)';
|
|
76
|
+
case validators_base.VLD_VALIDATOR_TYPES.BIGINT:
|
|
77
|
+
case validators_base.VLD_VALIDATOR_TYPES.COERCE_BIGINT:
|
|
78
|
+
return '(-?\\d+)';
|
|
79
|
+
case validators_base.VLD_VALIDATOR_TYPES.BOOLEAN:
|
|
80
|
+
case validators_base.VLD_VALIDATOR_TYPES.COERCE_BOOLEAN:
|
|
81
|
+
return '(true|false)';
|
|
82
|
+
case validators_base.VLD_VALIDATOR_TYPES.NULL:
|
|
83
|
+
return '(null)';
|
|
84
|
+
case validators_base.VLD_VALIDATOR_TYPES.UNDEFINED:
|
|
85
|
+
case validators_base.VLD_VALIDATOR_TYPES.VOID:
|
|
86
|
+
return '(undefined)';
|
|
87
|
+
case validators_base.VLD_VALIDATOR_TYPES.LITERAL: {
|
|
88
|
+
const literalValidator = validator;
|
|
89
|
+
if (literalValidator.literal !== undefined) {
|
|
90
|
+
const valueStr = String(literalValidator.literal);
|
|
91
|
+
return '(' + valueStr.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + ')';
|
|
92
|
+
}
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// Default: match any string
|
|
97
|
+
return '(.+)';
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Helper function to create template literal validators
|
|
101
|
+
* Usage: v.templateLiteral(v.string(), '-', v.number())
|
|
102
|
+
*/
|
|
103
|
+
function templateLiteral(...components) {
|
|
104
|
+
return VldTemplateLiteral.create(...components);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
exports.VldTemplateLiteral = VldTemplateLiteral;
|
|
108
|
+
exports.templateLiteral = templateLiteral;
|
|
@@ -0,0 +1,187 @@
|
|
|
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 createTupleError(message) {
|
|
10
|
+
return new errorsCore.VldError([{ code: 'invalid_array', path: [], message }]);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Immutable tuple validator for fixed-length arrays
|
|
14
|
+
*/
|
|
15
|
+
class VldTuple extends validators_base.VldBase {
|
|
16
|
+
constructor(validators, errorMessage) {
|
|
17
|
+
super(validators_base.VLD_VALIDATOR_TYPES.TUPLE);
|
|
18
|
+
this.validators = validators;
|
|
19
|
+
this.errorMessage = errorMessage;
|
|
20
|
+
this._length = validators.length;
|
|
21
|
+
this._validatorTypes = validators.map(validator => validator.validatorType);
|
|
22
|
+
this._simpleItemModes = validators.map((validator, index) => this.getSimpleItemMode(validator, this._validatorTypes[index]));
|
|
23
|
+
this._simpleItemValues = validators.map((validator, index) => this._simpleItemModes[index] === 'literal' ? validator.literal : undefined);
|
|
24
|
+
}
|
|
25
|
+
get items() {
|
|
26
|
+
return this.validators;
|
|
27
|
+
}
|
|
28
|
+
getSimpleItemMode(validator, type) {
|
|
29
|
+
if (validator.isSimple !== true) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
switch (type) {
|
|
33
|
+
case validators_base.VLD_VALIDATOR_TYPES.STRING:
|
|
34
|
+
return 'string';
|
|
35
|
+
case validators_base.VLD_VALIDATOR_TYPES.NUMBER:
|
|
36
|
+
return 'number';
|
|
37
|
+
case validators_base.VLD_VALIDATOR_TYPES.BOOLEAN:
|
|
38
|
+
return 'boolean';
|
|
39
|
+
case validators_base.VLD_VALIDATOR_TYPES.BIGINT:
|
|
40
|
+
return 'bigint';
|
|
41
|
+
case validators_base.VLD_VALIDATOR_TYPES.SYMBOL:
|
|
42
|
+
return 'symbol';
|
|
43
|
+
case validators_base.VLD_VALIDATOR_TYPES.NULL:
|
|
44
|
+
return 'null';
|
|
45
|
+
case validators_base.VLD_VALIDATOR_TYPES.UNDEFINED:
|
|
46
|
+
case validators_base.VLD_VALIDATOR_TYPES.VOID:
|
|
47
|
+
return 'undefinedValue';
|
|
48
|
+
case validators_base.VLD_VALIDATOR_TYPES.LITERAL:
|
|
49
|
+
return 'literal';
|
|
50
|
+
case validators_base.VLD_VALIDATOR_TYPES.ANY:
|
|
51
|
+
case validators_base.VLD_VALIDATOR_TYPES.UNKNOWN:
|
|
52
|
+
return 'passthrough';
|
|
53
|
+
default:
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
getSimpleItemError(mode, expected, received) {
|
|
58
|
+
switch (mode) {
|
|
59
|
+
case 'string':
|
|
60
|
+
return locales_runtime.getMessages().invalidString;
|
|
61
|
+
case 'number':
|
|
62
|
+
return locales_runtime.getMessages().invalidNumber;
|
|
63
|
+
case 'boolean':
|
|
64
|
+
return locales_runtime.getMessages().invalidBoolean;
|
|
65
|
+
case 'bigint':
|
|
66
|
+
return locales_runtime.getMessages().invalidBigint;
|
|
67
|
+
case 'symbol':
|
|
68
|
+
return locales_runtime.getMessages().invalidSymbol;
|
|
69
|
+
case 'null':
|
|
70
|
+
return `Expected null, received ${typeof received}`;
|
|
71
|
+
case 'undefinedValue':
|
|
72
|
+
return locales_runtime.getMessages().expectedUndefined;
|
|
73
|
+
case 'literal':
|
|
74
|
+
return locales_runtime.getMessages().literalExpected(JSON.stringify(expected), JSON.stringify(received));
|
|
75
|
+
default:
|
|
76
|
+
return locales_runtime.getMessages().invalidTuple;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Create a new tuple validator
|
|
81
|
+
*/
|
|
82
|
+
static create(...validators) {
|
|
83
|
+
return new VldTuple(validators);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Parse and validate a tuple value
|
|
87
|
+
*/
|
|
88
|
+
parse(value) {
|
|
89
|
+
if (!Array.isArray(value)) {
|
|
90
|
+
throw new Error(this.errorMessage || locales_runtime.getMessages().invalidTuple);
|
|
91
|
+
}
|
|
92
|
+
return this.parseKnownTuple(value);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Parse a value that has already passed the tuple array type guard.
|
|
96
|
+
* @internal Used by object validators to avoid duplicate hot-path checks.
|
|
97
|
+
*/
|
|
98
|
+
parseKnownTuple(value) {
|
|
99
|
+
if (value.length !== this._length) {
|
|
100
|
+
throw new Error(this.errorMessage ||
|
|
101
|
+
locales_runtime.getMessages().tupleLength(this._length, value.length));
|
|
102
|
+
}
|
|
103
|
+
const result = new Array(this._length);
|
|
104
|
+
for (let i = 0; i < this._length; i++) {
|
|
105
|
+
const simpleMode = this._simpleItemModes[i];
|
|
106
|
+
const item = value[i];
|
|
107
|
+
if (simpleMode !== undefined) {
|
|
108
|
+
switch (simpleMode) {
|
|
109
|
+
case 'string':
|
|
110
|
+
if (typeof item !== 'string') {
|
|
111
|
+
throw new Error(locales_runtime.getMessages().arrayItem(i, locales_runtime.getMessages().invalidString));
|
|
112
|
+
}
|
|
113
|
+
result[i] = item;
|
|
114
|
+
continue;
|
|
115
|
+
case 'number':
|
|
116
|
+
if (typeof item !== 'number' || isNaN(item)) {
|
|
117
|
+
throw new Error(locales_runtime.getMessages().arrayItem(i, locales_runtime.getMessages().invalidNumber));
|
|
118
|
+
}
|
|
119
|
+
result[i] = item;
|
|
120
|
+
continue;
|
|
121
|
+
case 'boolean':
|
|
122
|
+
if (typeof item !== 'boolean') {
|
|
123
|
+
throw new Error(locales_runtime.getMessages().arrayItem(i, locales_runtime.getMessages().invalidBoolean));
|
|
124
|
+
}
|
|
125
|
+
result[i] = item;
|
|
126
|
+
continue;
|
|
127
|
+
case 'bigint':
|
|
128
|
+
if (typeof item !== 'bigint') {
|
|
129
|
+
throw new Error(locales_runtime.getMessages().arrayItem(i, locales_runtime.getMessages().invalidBigint));
|
|
130
|
+
}
|
|
131
|
+
result[i] = item;
|
|
132
|
+
continue;
|
|
133
|
+
case 'symbol':
|
|
134
|
+
if (typeof item !== 'symbol') {
|
|
135
|
+
throw new Error(locales_runtime.getMessages().arrayItem(i, locales_runtime.getMessages().invalidSymbol));
|
|
136
|
+
}
|
|
137
|
+
result[i] = item;
|
|
138
|
+
continue;
|
|
139
|
+
case 'null':
|
|
140
|
+
if (item !== null) {
|
|
141
|
+
throw new Error(locales_runtime.getMessages().arrayItem(i, this.getSimpleItemError(simpleMode, undefined, item)));
|
|
142
|
+
}
|
|
143
|
+
result[i] = null;
|
|
144
|
+
continue;
|
|
145
|
+
case 'undefinedValue':
|
|
146
|
+
if (item !== undefined) {
|
|
147
|
+
throw new Error(locales_runtime.getMessages().arrayItem(i, locales_runtime.getMessages().expectedUndefined));
|
|
148
|
+
}
|
|
149
|
+
result[i] = undefined;
|
|
150
|
+
continue;
|
|
151
|
+
case 'literal': {
|
|
152
|
+
const literal = this._simpleItemValues[i];
|
|
153
|
+
if (item !== literal) {
|
|
154
|
+
throw new Error(locales_runtime.getMessages().arrayItem(i, this.getSimpleItemError(simpleMode, literal, item)));
|
|
155
|
+
}
|
|
156
|
+
result[i] = literal;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
case 'passthrough':
|
|
160
|
+
result[i] = item;
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
const validator = this.validators[i];
|
|
166
|
+
result[i] = validator.parse(item);
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
throw new Error(locales_runtime.getMessages().arrayItem(i, error.message));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Safely parse and validate a tuple value
|
|
176
|
+
*/
|
|
177
|
+
safeParse(value) {
|
|
178
|
+
try {
|
|
179
|
+
return { success: true, data: this.parse(value) };
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
return { success: false, error: createTupleError(error.message) };
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
exports.VldTuple = VldTuple;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var validators_base = require('./base.cjs');
|
|
4
|
+
var errors = require('../errors.cjs');
|
|
5
|
+
var locales_runtime = require('../locales/runtime.cjs');
|
|
6
|
+
var errorsCore = require('../chunks/errors-core-DWxLFs2f.cjs');
|
|
7
|
+
require('../registry.cjs');
|
|
8
|
+
require('../pigment.cjs');
|
|
9
|
+
require('../locales/en.cjs');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Uint8Array validator with immutable configuration
|
|
13
|
+
* BUG-NEW-010 FIX: Refactored to follow immutability pattern
|
|
14
|
+
*/
|
|
15
|
+
class VldUint8Array extends validators_base.VldBase {
|
|
16
|
+
/**
|
|
17
|
+
* Protected constructor to maintain immutability
|
|
18
|
+
*/
|
|
19
|
+
constructor(config) {
|
|
20
|
+
super(validators_base.VLD_VALIDATOR_TYPES.UINT8_ARRAY);
|
|
21
|
+
this.config = config || {};
|
|
22
|
+
}
|
|
23
|
+
parse(value) {
|
|
24
|
+
const result = this.safeParse(value);
|
|
25
|
+
if (!result.success) {
|
|
26
|
+
throw result.error;
|
|
27
|
+
}
|
|
28
|
+
return result.data;
|
|
29
|
+
}
|
|
30
|
+
safeParse(value) {
|
|
31
|
+
if (!(value instanceof Uint8Array)) {
|
|
32
|
+
return {
|
|
33
|
+
success: false,
|
|
34
|
+
error: new errorsCore.VldError([
|
|
35
|
+
errors.createIssue('invalid_type', [], locales_runtime.getMessages().expectedUint8Array)
|
|
36
|
+
])
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
// Check exact length if specified
|
|
40
|
+
if (this.config.exactLength !== undefined && value.length !== this.config.exactLength) {
|
|
41
|
+
return {
|
|
42
|
+
success: false,
|
|
43
|
+
error: new errorsCore.VldError([
|
|
44
|
+
errors.createIssue('custom', [], locales_runtime.getMessages().uint8ArrayExactLength(this.config.exactLength))
|
|
45
|
+
])
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
// Check minimum length
|
|
49
|
+
if (this.config.minLength !== undefined && value.length < this.config.minLength) {
|
|
50
|
+
return {
|
|
51
|
+
success: false,
|
|
52
|
+
error: new errorsCore.VldError([
|
|
53
|
+
errors.createIssue('custom', [], locales_runtime.getMessages().uint8ArrayMinLength(this.config.minLength))
|
|
54
|
+
])
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
// Check maximum length
|
|
58
|
+
if (this.config.maxLength !== undefined && value.length > this.config.maxLength) {
|
|
59
|
+
return {
|
|
60
|
+
success: false,
|
|
61
|
+
error: new errorsCore.VldError([
|
|
62
|
+
errors.createIssue('custom', [], locales_runtime.getMessages().uint8ArrayMaxLength(this.config.maxLength))
|
|
63
|
+
])
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return { success: true, data: value };
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Set minimum byte length
|
|
70
|
+
* Returns new immutable validator instance
|
|
71
|
+
*/
|
|
72
|
+
min(length) {
|
|
73
|
+
return new VldUint8Array({
|
|
74
|
+
...this.config,
|
|
75
|
+
minLength: length
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Set maximum byte length
|
|
80
|
+
* Returns new immutable validator instance
|
|
81
|
+
*/
|
|
82
|
+
max(length) {
|
|
83
|
+
return new VldUint8Array({
|
|
84
|
+
...this.config,
|
|
85
|
+
maxLength: length
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Set exact byte length
|
|
90
|
+
* Returns new immutable validator instance
|
|
91
|
+
* Clears min/max when setting exact length
|
|
92
|
+
*/
|
|
93
|
+
length(length) {
|
|
94
|
+
return new VldUint8Array({
|
|
95
|
+
exactLength: length,
|
|
96
|
+
// Clear min/max when exact length is set
|
|
97
|
+
minLength: undefined,
|
|
98
|
+
maxLength: undefined
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
static create() {
|
|
102
|
+
return new VldUint8Array();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
exports.VldUint8Array = VldUint8Array;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var validators_base = require('./base.cjs');
|
|
4
|
+
var errorsCore = require('../chunks/errors-core-DWxLFs2f.cjs');
|
|
5
|
+
require('../registry.cjs');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* VldUndefined - Validates that a value is exactly undefined
|
|
9
|
+
* Part of Zod 4 API parity implementation
|
|
10
|
+
*/
|
|
11
|
+
function createUndefinedError(message) {
|
|
12
|
+
return new errorsCore.VldError([{ code: 'invalid_type', path: [], message }]);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Undefined validator - validates that a value is exactly undefined
|
|
16
|
+
*/
|
|
17
|
+
class VldUndefined extends validators_base.VldBase {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(validators_base.VLD_VALIDATOR_TYPES.UNDEFINED);
|
|
20
|
+
}
|
|
21
|
+
static create() {
|
|
22
|
+
return new VldUndefined();
|
|
23
|
+
}
|
|
24
|
+
get isSimple() {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
parse(value) {
|
|
28
|
+
if (value !== undefined) {
|
|
29
|
+
throw new Error(`Expected undefined, received ${typeof value}`);
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
safeParse(value) {
|
|
34
|
+
try {
|
|
35
|
+
return { success: true, data: this.parse(value) };
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
return { success: false, error: createUndefinedError(error.message) };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
exports.VldUndefined = VldUndefined;
|