utils

package
v0.11.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 6 Imported by: 0

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

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

func CompareValues(a, b any) int

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

func FirstParam(params ...any) any

FirstParam returns the first element of params, or nil if params is empty.

func FormatErrorPath added in v0.4.0

func FormatErrorPath(path []any, style string) string

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

func LengthableOrigin(value any) string

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

func NumericOrigin(value any) string

NumericOrigin classifies value into a numeric origin category. Possible results: "nil", "integer", "number", "bigint", "string", or "unknown".

func OriginFromValue added in v0.6.0

func OriginFromValue(value any) string

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

func SizableOrigin(value any) string

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

func ToDotPath(path []any) string

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

func WriteDotPath(b *strings.Builder, path []any)

WriteDotPath appends an error path to b using dot notation.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL