Documentation
¶
Overview ¶
Package utils provides internal utility functions for the gozod validation library, including error map conversion, parameter normalization, value origin detection, value comparison, and error path formatting.
Index ¶
- func ApplySchemaParams(def *core.ZodTypeDef, params *core.SchemaParams)
- func CompareValues(a, b any) int
- func FirstParam(params ...any) any
- func FormatErrorPath(path []any, style string) string
- func LengthableOrigin(value any) string
- func NormalizeCustomParams(params ...any) *core.CustomParams
- func NormalizeParams(params ...any) *core.SchemaParams
- func NumericOrigin(value any) string
- func OriginFromValue(value any) string
- func SizableOrigin(value any) string
- func ToDotPath(path []any) string
- func ToErrorMap(err any) (*core.ZodErrorMap, bool)
- func WriteDotPath(b *strings.Builder, path []any)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplySchemaParams ¶ added in v0.3.0
func ApplySchemaParams(def *core.ZodTypeDef, params *core.SchemaParams)
ApplySchemaParams sets the error map on def from params. It is a no-op when params or params.Error is nil.
func CompareValues ¶
CompareValues compares a and b after dereferencing all pointers. It returns -1, 0, or 1. Mismatched or unsupported types return 0.
func FirstParam ¶ added in v0.6.0
FirstParam returns the first element of params, or nil if params is empty.
func FormatErrorPath ¶ added in v0.4.0
FormatErrorPath formats an error path for display using the given style. Supported styles are "bracket" (all bracket notation) and "dot" (default).
func LengthableOrigin ¶ added in v0.6.0
LengthableOrigin classifies value into a lengthable origin category. Possible results: "nil", "string", "slice", "array", or "unknown".
func NormalizeCustomParams ¶ added in v0.3.1
func NormalizeCustomParams(params ...any) *core.CustomParams
NormalizeCustomParams converts the first variadic argument into a CustomParams. It accepts nil, string, CustomParams, or *CustomParams. Any other type is stored as the Error field directly.
func NormalizeParams ¶ added in v0.3.0
func NormalizeParams(params ...any) *core.SchemaParams
NormalizeParams converts the first variadic argument into a SchemaParams. It accepts nil, string, SchemaParams, or *SchemaParams. Unrecognized types yield an empty SchemaParams.
func NumericOrigin ¶ added in v0.6.0
NumericOrigin classifies value into a numeric origin category. Possible results: "nil", "integer", "number", "bigint", "string", or "unknown".
func OriginFromValue ¶ added in v0.6.0
OriginFromValue returns a human-readable origin label for value, used in error messages. Possible results: "number", "string", "array", "object", or "unknown".
func SizableOrigin ¶ added in v0.6.0
SizableOrigin classifies value into a sizable origin category. Possible results: "nil", "string", "slice", "array", "map", "struct", "file", or "unknown".
func ToDotPath ¶ added in v0.4.0
ToDotPath converts an error path to dot notation. Integer segments use bracket notation (e.g., [0]), string segments use dot notation unless they contain non-identifier characters, in which case bracket notation with quotes is used. Compatible with TypeScript Zod v4 path formatting.
func ToErrorMap ¶ added in v0.3.0
func ToErrorMap(err any) (*core.ZodErrorMap, bool)
ToErrorMap converts various error representations to a ZodErrorMap. It accepts string, ZodErrorMap, *ZodErrorMap, or func(ZodRawIssue) string. The second return value reports whether the conversion succeeded.
func WriteDotPath ¶ added in v0.11.1
WriteDotPath appends an error path to b using dot notation.
Types ¶
This section is empty.