strutils

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2025 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendByteSize

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

func AppendDuration

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

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

func AppendTimeWithReference

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 ContainsFold

func ContainsFold(s, substr string) bool

func FormatByteSize

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

func FormatTimeWithReference(t, ref time.Time) string

func FormatUnixTime

func FormatUnixTime(t int64) string

func IndexFold

func IndexFold(s, substr string) int

func IsValidFilename

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

func Pluralize(n int64) string

func SanitizeURI

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