utils

package
v1.59.1 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteToHumanReadableFormat

func ByteToHumanReadableFormat(b int) string

func CommonElementsInStringSlice

func CommonElementsInStringSlice(s1 []string, s2 []string) (arr []string)

CommonElementsInStringSlice takes 2 Slices of Strings and returns a Third Slice that is the common elements between the first 2 Slices.

func DisplayURL

func DisplayURL(urlStr string) string

func Editor

func Editor(opts EditorOptions) string

func FirstLine added in v1.58.0

func FirstLine(output []byte) string

func FmtDuration

func FmtDuration(d time.Duration) string

func Humanize

func Humanize(s string) string

func Indent

func Indent(s, indent string) string

func IsValidURL

func IsValidURL(toTest string) bool

isValidUrl tests a string to determine if it is a well-structured url or not.

func Map added in v1.26.0

func Map[T1, T2 any](elems []T1, fn func(T1) T2) []T2

Map transfers the elements of its first argument using the result of the second fn(e)

func OpenInBrowser

func OpenInBrowser(url, browserType string) error

OpenInBrowser opens the url in a web browser based on OS and $BROWSER environment variable

func Pluralize

func Pluralize(num int, thing string) string

func PresentInIntSlice

func PresentInIntSlice(hay []int, needle int) bool

PresentInIntSlice take a Hay (Slice of Ints) and a Needle (int) and returns true based on whether or not the Needle is present in the hay.

func PresentInStringSlice

func PresentInStringSlice(hay []string, needle string) bool

PresentInStringSlice take a Hay (Slice of Strings) and a Needle (string) and returns true based on whether or not the Needle is present in the hay.

func PrettyTimeAgo

func PrettyTimeAgo(ago time.Duration) string

func Ptr added in v1.29.2

func Ptr[T any](v T) *T

Ptr takes any value and returns a pointer to that value

func RenderMarkdown

func RenderMarkdown(text, glamourStyle string) (string, error)

func RenderMarkdownWithoutIndentations

func RenderMarkdownWithoutIndentations(text, glamourStyle string) (string, error)

func ReplaceNonAlphaNumericChars

func ReplaceNonAlphaNumericChars(words, replaceWith string) string

ReplaceNonAlphaNumericChars: Replaces non alpha-numeric values with provided char/string

func SanitizePathName added in v1.39.0

func SanitizePathName(path string) string

func StringToInt

func StringToInt(str string) int

func TimeToPrettyTimeAgo

func TimeToPrettyTimeAgo(d time.Time) string

Types

type EditorOptions

type EditorOptions struct {
	FileName      string
	Label         string
	Help          string
	Default       string
	AppendDefault bool
	HideDefault   bool
	EditorCommand string
}

type ListTitleOptions

type ListTitleOptions struct {
	// Name of the List to be used in constructing Description and EmptyMessage if not provided.
	Name string
	// Page represents the page number of the current page
	Page int
	// CurrentPageTotal is the total number of items in current page
	CurrentPageTotal int
	// Total number of records. Default is the total number of rows.
	// Can be set to be greater than the total number of rows especially, if the list is paginated
	Total int
	// RepoName represents the name of the project or repository
	RepoName string
	// ListActionType should be either "search" or "list". Default is list
	ListActionType string
	// Optional. EmptyMessage to display when List is empty. If not provided, default one constructed from list Name.
	EmptyMessage string
}

func NewListTitle

func NewListTitle(listName string) ListTitleOptions

func (*ListTitleOptions) Describe

func (opts *ListTitleOptions) Describe() string

type MarkdownRenderOpts

type MarkdownRenderOpts []glamour.TermRendererOption

Jump to

Keyboard shortcuts

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