normalization

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: BSD-3-Clause Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package normalization applies opt-in Unicode NFC and whitespace normalization.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractCategoryMetadata added in v0.6.0

func ExtractCategoryMetadata[T any]() map[string]map[string]string

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

func HasRules(typ reflect.Type) (bool, error)

HasRules validates normalization tags and reports whether the type contains any. Compiled type metadata is cached and safe for concurrent use.

func Normalize

func Normalize(value any) error

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

func NormalizeJSON(data []byte, typ reflect.Type) ([]byte, error)

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

func ParseKeywords(keywordsStr string) []string

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

func ParseMetaTag(tag string) map[string]string

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.

Jump to

Keyboard shortcuts

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