Initial commit
CI / test (push) Canceled after 0s

This commit is contained in:
2026-09-12 22:22:17 +02:00
commit 904d14b64c
314 changed files with 31884 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
package validate
import (
"regexp"
"slices"
"strings"
"unicode/utf8"
)
// PermittedValue reports whether value appears in permittedValues.
func PermittedValue[T comparable](value T, permittedValues ...T) bool {
return slices.Contains(permittedValues, value)
}
// Matches reports whether value satisfies rx.
func Matches(value string, rx *regexp.Regexp) bool {
return rx.MatchString(value)
}
// Unique reports whether values contains no duplicate elements.
func Unique[T comparable](values []T) bool {
uniqueValues := make(map[T]bool)
for _, value := range values {
uniqueValues[value] = true
}
return len(values) == len(uniqueValues)
}
// NotBlank reports whether value contains non-whitespace characters.
func NotBlank(value string) bool {
return strings.TrimSpace(value) != ""
}
// MaxChars reports whether value contains at most n Unicode code points.
func MaxChars(value string, n int) bool {
return utf8.RuneCountInString(value) <= n
}
// MinChars reports whether value contains at least n Unicode code points.
func MinChars(value string, n int) bool {
return utf8.RuneCountInString(value) >= n
}