Documentation
¶
Overview ¶
Package normalization applies opt-in Unicode NFC and whitespace normalization.
Index ¶
- func ExtractCategoryMetadata[T any]() map[string]map[string]string
- func HasRules(typ reflect.Type) (bool, error)
- func Normalize(value any) error
- func NormalizeJSON(data []byte, typ reflect.Type) ([]byte, error)
- func ParseKeywords(keywordsStr string) []string
- func ParseMetaTag(tag string) map[string]string
- func Text(value string, opts TextOptions) string
- type TextOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractCategoryMetadata ¶ added in v0.6.0
ExtractCategoryMetadata extracts category metadata from T's fields with catmeta tags Returns a map of category ID to category metadata in field order
func HasRules ¶
HasRules validates normalization tags and reports whether the type contains any. Compiled type metadata is cached and safe for concurrent use.
func Normalize ¶
Normalize normalizes tagged fields in place and checks their length constraints. The input must be a non-nil pointer. Untagged strings, maps, and nested nil pointers are left untouched. Tagged string pointers are replaced so normalization does not modify aliased pointees.
func NormalizeJSON ¶
NormalizeJSON normalizes tagged JSON strings before schema validation. Raw JSON values retain their types and precision; unknown fields are preserved. Invalid JSON returns an error so the caller can retain its normal error handling.
func ParseKeywords ¶ added in v0.6.0
ParseKeywords parses a comma-separated keywords string into a slice Returns an empty slice if the input is empty or contains only whitespace
func ParseMetaTag ¶ added in v0.6.0
ParseMetaTag parses a struct tag meta value formatted as `k=v;other=val;...` Returns a map of key-value pairs extracted from the tag
func Text ¶
func Text(value string, opts TextOptions) string
Text applies the normalizations selected by opts: trimming first, then NFC. It preserves case and internal whitespace and must not be used for secrets.
Types ¶
type TextOptions ¶
type TextOptions struct {
// Trim removes leading and trailing whitespace.
Trim bool
// NFC converts the text to Unicode Normalization Form C.
NFC bool
}
TextOptions selects the normalizations Text applies. The zero value returns the input unchanged.