Documentation
¶
Index ¶
- Variables
- func Base58Encode(input []byte) string
- func Base58EncodeSHA256(input string) string
- func ExtractEmailDomain(email string) string
- func FormatDuration(d time.Duration) string
- func FormatTime(t time.Time) string
- func HasNumericPrefix(pattern string) bool
- func HasRegexPrefix(pattern string) bool
- func IsJSON(s string) bool
- func IsMultiLine(s string) bool
- func KebabToCamel(s string) string
- func KeyValuesToMap(kvSlice []string) map[string]string
- func MatchPattern(ctx context.Context, content string, patterns []string, opts ...MatchOption) bool
- func MatchPatternScanner(ctx context.Context, scanner *bufio.Scanner, patterns []string, ...) bool
- func ParseBool(value any) (bool, error)
- func ParseSeparatedValues(s string) ([]string, error)
- func ParseTime(val string) (time.Time, error)
- func RandomString(n int) string
- func RemoveQuotes(s string) string
- func ScreamingSnakeToCamel(s string) string
- func SplitNumericPattern(pattern string) (operator, operand string, err error)
- func StripANSI(s string) string
- func TrimRegexPrefix(pattern string) (string, bool)
- func TruncString(val string, max int) string
- func TruncUTF8Bytes(val string, max int) string
- func UpperFirst(s string) string
- type KeyValue
- type MatchOption
- type NumericComparison
- type SeparatorType
Constants ¶
This section is empty.
Variables ¶
var SpinnerFrames = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}
SpinnerFrames contains the animation frames for a braille spinner. Used by progress displays throughout the application.
Functions ¶
func Base58Encode ¶
Base58Encode encodes a byte slice to base58 string. Uses the Bitcoin alphabet which excludes ambiguous characters (0, O, l, I).
func Base58EncodeSHA256 ¶
Base58EncodeSHA256 generates a SHA-256 hash of the input and encodes it as base58. This is useful for creating deterministic, URL-safe identifiers.
func ExtractEmailDomain ¶
ExtractEmailDomain extracts the domain part from an email address. Returns an empty string if the email format is invalid.
func FormatDuration ¶
FormatDuration formats a duration into a human-readable string. It handles negative durations by prepending a "-" sign. Examples:
- 500ms -> "500ms"
- 1.5s -> "1.5s"
- 2m30s -> "2m 30s"
- 1h30m -> "1h 30m"
- -500ms -> "-500ms"
- -2m30s -> "-2m 30s"
func HasNumericPrefix ¶ added in v2.17.0
HasNumericPrefix reports whether pattern selects numeric comparison.
func HasRegexPrefix ¶ added in v2.17.0
HasRegexPrefix reports whether pattern selects regular-expression matching.
func IsJSON ¶
IsJSON checks if the given string is valid JSON. Returns true if the string can be parsed as JSON, false otherwise.
func IsMultiLine ¶
IsMultiLine checks if the given string contains multiple lines. Returns true if the string contains line separators (\n, \r\n, or \r).
func KebabToCamel ¶
KebabToCamel converts a kebab-case string to camelCase.
func KeyValuesToMap ¶
KeyValuesToMap converts a slice of "KEY=VALUE" strings into a map of keys to values. It splits each entry at the first '='; entries without '=' are skipped. Values may be empty (for example, "KEY=" results in map["KEY"] = ""). Empty keys are allowed (for example, "=value" results in map[""] = "value").
func MatchPattern ¶
MatchPattern matches content against patterns using either literal or regex matching. For files or large content, use MatchPatternScanner instead.
func MatchPatternScanner ¶
func ParseSeparatedValues ¶
ParseSeparatedValues intelligently parses a string into separate values based on detected separator patterns. Handles JSON arrays, various delimiters, quoted strings, and space-separated values.
func RandomString ¶
RandomString generates a random string of length n using letters from letterBytes.
func RemoveQuotes ¶
RemoveQuotes removes leading and trailing double quotes from a string if present, and unescapes the content using strconv.Unquote.
func ScreamingSnakeToCamel ¶
ScreamingSnakeToCamel converts a SCREAMING_SNAKE_CASE string to camelCase. Example: TOTAL_COUNT -> totalCount, MY_VAR -> myVar, FOO -> foo
func SplitNumericPattern ¶ added in v2.17.0
SplitNumericPattern separates a numeric-comparison pattern into its ordering operator and the text of its operand.
The operand is returned as written apart from surrounding whitespace, so a caller can resolve a value reference in it before requiring a number. It returns an error when pattern does not carry the numeric prefix or does not continue with one of the ordering operators ">", ">=", "<", or "<=". Equality operators are not supported.
func StripANSI ¶ added in v2.18.0
StripANSI returns s with ANSI escape sequences, such as colors and terminal hyperlinks, removed.
func TrimRegexPrefix ¶ added in v2.17.0
TrimRegexPrefix returns the regular-expression source of a pattern that carries the regex prefix.
func TruncString ¶
TruncString returns truncated string.
func TruncUTF8Bytes ¶ added in v2.11.3
TruncUTF8Bytes returns at most max bytes without splitting a UTF-8 codepoint.
func UpperFirst ¶
UpperFirst returns s with its first rune converted to title case. An empty string is returned unchanged.
Types ¶
type KeyValue ¶
type KeyValue string
func NewKeyValue ¶
NewKeyValue constructs a KeyValue by concatenating key and value with an '=' separator. The key must not contain '=' characters to ensure round-trip correctness with Key() and Value(). An empty value produces a trailing '=' (e.g., "KEY=").
func (KeyValue) MarshalJSON ¶
func (*KeyValue) UnmarshalJSON ¶
type MatchOption ¶
type MatchOption func(*matchOptions)
MatchOption represents an option for pattern matching
func WithExactMatch ¶
func WithExactMatch() MatchOption
WithExactMatch configures the matcher to use exact string matching for literal patterns
func WithMaxBufferSize ¶
func WithMaxBufferSize(size int) MatchOption
WithMaxBufferSize configures the maximum buffer size for handling long lines
type NumericComparison ¶ added in v2.17.0
type NumericComparison struct {
// contains filtered or unexported fields
}
NumericComparison is an ordering test against a fixed number.
func ParseNumericPattern ¶ added in v2.17.0
func ParseNumericPattern(pattern string) (NumericComparison, error)
ParseNumericPattern parses a numeric-comparison pattern whose operand is a literal number.
It returns an error when the pattern is not a supported comparison or its operand is not a finite number. A pattern whose operand is a value reference must be resolved before it reaches this function.
func (NumericComparison) Match ¶ added in v2.17.0
func (c NumericComparison) Match(value string) (bool, error)
Match reports whether value satisfies the comparison.
Value is the whole text, not a line of it: surrounding whitespace is ignored and everything else must form a single finite number. It returns an error when value is not such a number.
type SeparatorType ¶
type SeparatorType int
SeparatorType represents different types of separators for parsing text
const ( SeparatorTypeJSON SeparatorType = iota SeparatorTypeNewline SeparatorTypeComma SeparatorTypeSemicolon SeparatorTypePipe SeparatorTypeTab SeparatorTypeQuoted SeparatorTypeSpace )
func DetectSeparatorType ¶
func DetectSeparatorType(s string) SeparatorType
DetectSeparatorType analyzes a string to determine the most likely separator type