validation

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

validation

数据验证

Overview

概述

Standard Schema helpers for consistent validation and error handling across Zod, Valibot, ArkType, and others.
兼容Standard Schema的工具函数,可在Zod、Valibot、ArkType等库之间实现一致的验证和错误处理逻辑。

When to Use

适用场景

  • Validating inputs or API payloads with Standard Schema-compatible schemas
  • Normalizing sync and async validation paths
  • Handling a single
    ValidationError
    type across schema libraries
  • 使用兼容Standard Schema的schema验证输入或API载荷
  • 统一同步和异步验证流程
  • 跨不同schema库使用统一的
    ValidationError
    类型

When Not to Use

不适用场景

  • You only need simple, ad-hoc checks without schema validation
  • 仅需要无需schema验证的简单临时检查的场景

Quick Reference

快速参考

  • Guard:
    isStandardSchema
  • Validate:
    standardValidate
  • Sync only:
    createSyncStandardValidator
  • Error:
    ValidationError
  • 类型守卫:
    isStandardSchema
  • 验证方法:
    standardValidate
  • 仅同步验证:
    createSyncStandardValidator
  • 错误类:
    ValidationError

Inputs to Request

使用配置项

  • Schema library in use (Zod, Valibot, ArkType)
  • Throwing vs non-throwing validation
  • Desired error shape and handling
  • 所使用的schema库(Zod、Valibot、ArkType)
  • 验证失败时是否抛出异常
  • 期望的错误结构与处理方式

Resources

相关资源