strutils

package
v0.10.0-1 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Atoi = strconv.Atoi

Functions

func CommaSeperatedList

func CommaSeperatedList(s string) []string

CommaSeperatedList returns a list of strings split by commas, then trim spaces from each element.

func DoYouMean

func DoYouMean(s string) string

func FormatByteSize added in v0.10.0

func FormatByteSize[T ~int64 | ~uint64 | ~float64](size T) (value, unit string)

func FormatByteSizeWithUnit added in v0.10.0

func FormatByteSizeWithUnit[T ~int64 | ~uint64 | ~float64](size T) string

func FormatDuration

func FormatDuration(d time.Duration) string

func FormatLastSeen

func FormatLastSeen(t time.Time) string

func FormatTime

func FormatTime(t time.Time) string

func GlobMatch

func GlobMatch(pattern string, s string) bool

func IsValidFilename added in v0.10.0

func IsValidFilename(filename string) bool

IsValidFilename checks if a filename is safe and doesn't contain path traversal attempts Returns true if the filename is valid, false otherwise

func JoinLines

func JoinLines(elems []string) string

JoinLines is a wrapper around JoinRune(elems, '\n').

func JoinRune

func JoinRune(elems []string, sep rune) string

JoinRune is like strings.Join but takes a rune as separator.

func LevenshteinDistance

func LevenshteinDistance(a, b string) int

func MustParse

func MustParse[T Parser](from string) T

func Parse

func Parse[T Parser](from string) (t T, err error)

func ParseBool

func ParseBool(s string) bool

func PortString

func PortString(port uint16) string

func SanitizeURI added in v0.9.10

func SanitizeURI(uri string) string

SanitizeURI sanitizes a URI reference to ensure it is safe It disallows URLs beginning with // or /\ as absolute URLs, cleans the URL path to remove any .. or . path elements, and ensures the URL starts with a / if it doesn't already

func SplitComma

func SplitComma(s string) []string

SplitComma is a wrapper around SplitRune(s, ',').

func SplitLine

func SplitLine(s string) []string

SplitLine is a wrapper around SplitRune(s, '\n').

func SplitRune

func SplitRune(s string, sep rune) []string

SplitRune is like strings.Split but takes a rune as separator.

func SplitSpace

func SplitSpace(s string) []string

SplitSpace is a wrapper around SplitRune(s, ' ').

func Title

func Title(s string) string

func ToLowerNoSnake

func ToLowerNoSnake(s string) string

Types

type Parser

type Parser interface {
	Parse(value string) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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