util

package
v0.0.0-...-7641ad8 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Capitalize

func Capitalize(s string) string

Capitalize returns a string with the first letter capitalized.

func ClearScreen

func ClearScreen()

ClearScreen clears the terminal screen.

func Delete

func Delete(path string) error

Delete removes the given path from the filesystem. It can handle both files and directories (recursively).

func Exit

func Exit(code int)

Exit do any cleanup needed and exit the program with the given code

func FileStem

func FileStem(path string) string

FileStem returns the file name without the extension.

func Ignore

func Ignore(f func() error)

Ignore calls function and explicitely ignores error

func Max

func Max[T constraints.Ordered](items ...T) (max T)

Max returns the maximum value of the given items.

func Min

func Min[T constraints.Ordered](items ...T) (min T)

Min returns the minimum value of the given items.

func PadZero

func PadZero(s string, l int) string

PadZero pads a number with leading zeros.

func PrintErasable

func PrintErasable(msg string) (eraser func())

PrintErasable prints a string that can be erased by calling a returned function.

func Quantify

func Quantify(count int, singular, plural string) string

Quantify returns a string with the given number and unit.

func ReGroups

func ReGroups(pattern *regexp.Regexp, str string) (groups map[string]string)

ReGroups parses the string with the given regular expression and returns the group values defined in the expression.

func SanitizeFilename

func SanitizeFilename(filename string) string

SanitizeFilename will remove all invalid characters from a path.

func SkipCI

func SkipCI(t *testing.T) bool

func TerminalSize

func TerminalSize() (width, height int, err error)

TerminalSize returns the dimensions of the given terminal.

func Unzip

func Unzip(zipStream io.ReaderAt, size int64, dest string) error

Types

type Stack

type Stack[T any] struct {
	// contains filtered or unexported fields
}

Stack is a LIFO data structure.

func (*Stack[T]) Clear

func (s *Stack[T]) Clear()

Clear removes all items from the stack.

func (*Stack[T]) Len

func (s *Stack[T]) Len() int

Len returns the number of items in the stack.

func (*Stack[T]) Peek

func (s *Stack[T]) Peek() T

Peek returns the top item of the stack without removing it.

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() T

Pop removes an item from the stack.

func (*Stack[T]) Push

func (s *Stack[T]) Push(item T)

Push adds an item to the stack.

Jump to

Keyboard shortcuts

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