strutils

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Atoi = strconv.Atoi

Functions

func AppendByteSize added in v0.11.0

func AppendByteSize[T ~int | ~uint | ~int64 | ~uint64 | ~float64](size T, buf []byte) []byte

func AppendDuration added in v0.11.0

func AppendDuration(d time.Duration, buf []byte) []byte

AppendDuration appends a duration to a buffer with the following format:

  • 1 ns
  • 1 ms
  • 1 seconds
  • 1 minutes and 1 seconds
  • 1 hours, 1 minutes and 1 seconds
  • 1 days, 1 hours and 1 minutes (ignore seconds if days >= 1)

func AppendTime added in v0.11.0

func AppendTime(t time.Time, buf []byte) []byte

func AppendTimeWithReference added in v0.11.0

func AppendTimeWithReference(t, ref time.Time, buf []byte) []byte

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 ~int | ~uint | ~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 FormatTimeWithReference added in v0.11.0

func FormatTimeWithReference(t, ref time.Time) string

func FormatUnixTime added in v0.11.0

func FormatUnixTime(t int64) 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 Pluralize added in v0.11.0

func Pluralize(n int64) 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