stringutil

package
v1.18.1 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2025 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base58Encode added in v1.17.0

func Base58Encode(input []byte) string

Base58Encode encodes a byte slice to base58 string. Uses the Bitcoin alphabet which excludes ambiguous characters (0, O, l, I).

func Base58EncodeSHA256 added in v1.17.0

func Base58EncodeSHA256(input string) string

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 added in v1.18.0

func FormatDuration(d time.Duration) string

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 FormatTime

func FormatTime(t time.Time) string

FormatTime returns formatted time.

func IsJSONArray added in v1.17.0

func IsJSONArray(s string) bool

IsJSONArray checks if the given string is a valid JSON array. This is useful for determining if parallel input should be parsed as JSON or space-separated.

func KebabToCamel added in v1.18.0

func KebabToCamel(s string) string

KebabToCamel converts a kebab-case string to camelCase.

func MatchPattern

func MatchPattern(ctx context.Context, content string, patterns []string, opts ...MatchOption) bool

MatchPattern matches content against patterns using either literal or regex matching. For files or large content, use MatchPatternScanner instead.

func MatchPatternScanner

func MatchPatternScanner(ctx context.Context, scanner *bufio.Scanner, patterns []string, opts ...MatchOption) bool

func ParseBool added in v1.17.0

func ParseBool(_ context.Context, value any) (bool, error)

ParseBool parses a boolean value from the given input.

func ParseTime

func ParseTime(val string) (time.Time, error)

ParseTime parses time string.

func RandomString added in v1.18.0

func RandomString(n int) string

RandomString generates a random string of length n using letters from letterBytes.

func RemoveQuotes added in v1.17.0

func RemoveQuotes(s string) string

RemoveQuotes removes leading and trailing double quotes from a string if present, and unescapes the content using strconv.Unquote.

func TruncString

func TruncString(val string, max int) string

TruncString returns truncated string.

Types

type KeyValue

type KeyValue string

func NewKeyValue

func NewKeyValue(key, value string) KeyValue

func (KeyValue) Bool

func (kv KeyValue) Bool() bool

func (KeyValue) Key

func (kv KeyValue) Key() string

func (KeyValue) MarshalJSON

func (kv KeyValue) MarshalJSON() ([]byte, error)

func (KeyValue) String

func (kv KeyValue) String() string

func (*KeyValue) UnmarshalJSON

func (kv *KeyValue) UnmarshalJSON(data []byte) error

func (KeyValue) Value

func (kv KeyValue) Value() string

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 added in v1.18.0

func WithMaxBufferSize(size int) MatchOption

WithMaxBufferSize configures the maximum buffer size for handling long lines

Jump to

Keyboard shortcuts

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