utils

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

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 applies SchemaParams to a type definition Updates the definition with normalized parameters

func CompareValues

func CompareValues(a, b any) int

CompareValues compares two values, returns -1, 0, or 1 Automatically dereferences pointers before comparison

func EscapeRegex

func EscapeRegex(str string) string

EscapeRegex escapes special characters in a string for use in regex

func GetFirstParam added in v0.3.0

func GetFirstParam(params ...any) any

GetFirstParam extracts the first parameter from variadic arguments Provides convenience for Go's variadic parameter style while maintaining compatibility with Zod TypeScript v4's single parameter pattern Returns nil if no parameters provided

func GetLengthableOrigin

func GetLengthableOrigin(value any) string

GetLengthableOrigin returns the origin type for lengthable values

func GetNumericOrigin

func GetNumericOrigin(value any) string

GetNumericOrigin determines the numeric origin type for error messages

func GetOriginFromValue

func GetOriginFromValue(value any) string

GetOriginFromValue smartly determines the origin of a value (general purpose)

func GetSizableOrigin

func GetSizableOrigin(value any) string

GetSizableOrigin determines the origin type for sizable values

func IsPrimitiveType added in v0.2.1

func IsPrimitiveType(typeName core.ZodTypeCode) bool

IsPrimitiveType checks if a schema type is a primitive type that supports coercion Only primitive types should support coercion according to TypeScript Zod v4 alignment

func NormalizeCustomParams added in v0.3.1

func NormalizeCustomParams(params ...any) *core.CustomParams

NormalizeCustomParams normalizes input parameters into a standard CustomParams struct Supports variadic arguments where the first parameter is used: - nil -> empty CustomParams - string -> { Error: string } - CustomParams -> normalized copy - *CustomParams -> normalized copy - any -> { Error: any }

func NormalizeParams added in v0.3.0

func NormalizeParams(params ...any) *core.SchemaParams

NormalizeParams normalizes input parameters into a standard SchemaParams struct Supports variadic arguments where the first parameter is used: - nil -> empty SchemaParams - string -> { Error: string } - SchemaParams -> normalized copy - *SchemaParams -> normalized copy

func ToErrorMap added in v0.3.0

func ToErrorMap(err any) (*core.ZodErrorMap, bool)

ToErrorMap converts various error representations to ZodErrorMap Supports: string, ZodErrorMap, *ZodErrorMap, func(ZodRawIssue) string

Types

This section is empty.

Jump to

Keyboard shortcuts

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