utils

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsJson

func AsJson(i interface{}) string

func ColoredString

func ColoredString(str string, colorAttributes ...color.Attribute) string

ColoredString takes a string and a colour attribute and returns a colored string with that attribute

func ColoredStringDirect

func ColoredStringDirect(str string, colour *color.Color) string

ColoredStringDirect used for aggregating a few color attributes rather than just sending a single one

func Decolorise

func Decolorise(str string) string

Decolorise strips a string of color

func DifferenceInt

func DifferenceInt(a, b []int) []int

DifferenceInt returns the difference of two int arrays

func FindStringSubmatch

func FindStringSubmatch(str string, regexpStr string) (bool, []string)

func GetCurrentRepoName

func GetCurrentRepoName() string

GetCurrentRepoName gets the repo's base name

func GetProjectRoot

func GetProjectRoot() string

GetProjectRoot returns the path to the root of the project. Only to be used in testing contexts, as with binaries it's unlikely this path will exist on the machine

func IncludesInt

func IncludesInt(list []int, a int) bool

IncludesInt if the list contains the Int

func IncludesString

func IncludesString(list []string, a string) bool

IncludesString if the list contains the string

func Loader

func Loader() string

Loader dumps a string to be displayed as a loader

func Min

func Min(x, y int) int

Min returns the minimum of two integers

func ModuloWithWrap

func ModuloWithWrap(n, max int) int

used to keep a number n between 0 and max, allowing for wraparounds

func NextIndex

func NextIndex(numbers []int, currentNumber int) int

NextIndex returns the index of the element that comes after the given number

func NextIntInCycle

func NextIntInCycle(sl []int, current int) int

NextIntInCycle returns the next int in a slice, returning to the first index if we've reached the end

func NormalizeLinefeeds

func NormalizeLinefeeds(str string) string

NormalizeLinefeeds - Removes all Windows and Mac style line feeds

func PrevIndex

func PrevIndex(numbers []int, currentNumber int) int

PrevIndex returns the index that comes before the given number, cycling if we reach the end

func PrevIntInCycle

func PrevIntInCycle(sl []int, current int) int

PrevIntInCycle returns the prev int in a slice, returning to the first index if we've reached the end

func RenderDisplayStrings

func RenderDisplayStrings(displayStringsArr [][]string) string

func ResolvePlaceholderString

func ResolvePlaceholderString(str string, arguments map[string]string) string

ResolvePlaceholderString populates a template with values

func SplitLines

func SplitLines(multilineString string) []string

SplitLines takes a multiline string and splits it on newlines currently we are also stripping \r's which may have adverse effects for windows users (but no issues have been raised yet)

func StringIndex

func StringIndex(haystack []string, needle string) (int, bool)

StringIndex returns the index of an element in a string array. If none is found it returns a false boolean value

func TrimTrailingNewline

func TrimTrailingNewline(str string) string

TrimTrailingNewline - Trims the trailing newline TODO: replace with `chomp` after refactor

func TruncateWithEllipsis

func TruncateWithEllipsis(str string, limit int) string

TruncateWithEllipsis returns a string, truncated to a certain length, with an ellipsis

func UnionInt

func UnionInt(a, b []int) []int

UnionInt returns the union of two int arrays

func UnixToDate

func UnixToDate(timestamp int64) string

func UnixToTimeAgo

func UnixToTimeAgo(timestamp int64) string

func WithPadding

func WithPadding(str string, padding int) string

WithPadding pads a string as much as you want

Types

This section is empty.

Jump to

Keyboard shortcuts

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