Documentation
¶
Index ¶
- func Base58Encode(input []byte) string
- func Base58EncodeSHA256(input string) string
- func FormatDuration(d time.Duration) string
- func FormatTime(t time.Time) string
- 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 TruncString(val string, max int) string
- type KeyValue
- type MatchOption
- type SeparatorType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
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 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 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 ¶ added in v1.29.0
ScreamingSnakeToCamel converts a SCREAMING_SNAKE_CASE string to camelCase. Example: TOTAL_COUNT -> totalCount, MY_VAR -> myVar, FOO -> foo
func TruncString ¶
TruncString returns truncated string.
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 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