utils

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2025 License: MIT Imports: 6 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 ContainsString added in v0.5.1

func ContainsString(slice []string, value string) bool

ContainsString checks if a string slice contains a specific value

func CreateErrorContext added in v0.4.0

func CreateErrorContext(code core.IssueCode, path []any, input any) map[string]any

CreateErrorContext creates error context for formatting

func EscapeRegex

func EscapeRegex(str string) string

EscapeRegex escapes special characters in a string for use in regex Optimized with precise memory allocation following TypeScript v4 patterns

func ExtractErrorInfo added in v0.4.0

func ExtractErrorInfo(issue core.ZodRawIssue) map[string]any

ExtractErrorInfo extracts error information from a raw issue

func FormatErrorPath added in v0.4.0

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

FormatErrorPath formats an error path for display

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 GetParsedType

func GetParsedType(value any) core.ParsedType

GetParsedType performs type detection by delegating to pkg/reflectx.ParsedType This ensures consistency across the codebase and avoids duplication

func GetSizableOrigin

func GetSizableOrigin(value any) string

GetSizableOrigin determines the origin type for sizable values

func IndexOfString added in v0.5.1

func IndexOfString(slice []string, value string) int

IndexOfString finds the index of a string in a slice, returns -1 if not found

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 IsPrimitiveValue added in v0.5.1

func IsPrimitiveValue(value any) bool

IsPrimitiveValue checks if a value is of a primitive type for fast-path optimization Uses pkg/reflectx functions for consistent type checking

func MergeStringSlices added in v0.5.1

func MergeStringSlices(slicesInput ...[]string) []string

MergeStringSlices efficiently merges multiple string slices

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 ToDotPath added in v0.4.0

func ToDotPath(path []any) string

ToDotPath converts an error path to dot notation string Compatible with TypeScript Zod v4 path formatting Optimized with precise memory allocation

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

func TypeDescription added in v0.5.1

func TypeDescription(value any) string

TypeDescription returns a human-readable type description for error messages Delegates to pkg/reflectx.ParsedCategory for consistent behavior

func UniqueStrings added in v0.5.1

func UniqueStrings(input []string) []string

UniqueStrings returns unique string values

Types

This section is empty.

Jump to

Keyboard shortcuts

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