utils

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BreakOutMap

func BreakOutMap(m map[string]string) (keys []string, values []string)

BreakOutMap takes a map and returns two slices, one containing the keys and the other containing the values.

func Contains

func Contains(slice []string, item string) bool

Contains checks if a string is in a slice of strings.

func DedupeStringSlice

func DedupeStringSlice(s []string) []string

DedupeStringSlice removes duplicate strings from a slice of strings.

func EndsWithAny added in v0.0.3

func EndsWithAny(s string, suffixes []string) bool

EndsWithAny takes a string and a slice of suffixes and returns true if the string ends with any of the suffixes.

func GetJSONKeys

func GetJSONKeys(j any) ([]string, error)

GetJSONKeys returns the keys of a JSON object as a slice of strings.

func GlobAll

func GlobAll(patterns []string) ([]string, error)

GlobAll returns all files that match any of the given patterns

func Input

func Input(prompt string) (string, error)

Input prompts the user for input and returns the entered text.

func InputWithColor

func InputWithColor(prompt, cssColorCode string) (string, error)

InputWithColor prompts the user for input and returns the entered text. The prompt is displayed in the specified CSS color code.

func InsertLine added in v0.0.3

func InsertLine(code string, lineNumber int, newText string) (string, error)

InsertLine inserts a new line of text at the specified line number in the code.

func InsertLinesAtIndices added in v0.0.3

func InsertLinesAtIndices(file string, indices []int, linesToInsert []string) (string, error)

InsertLinesAtIndices inserts multiple lines of text at the specified line numbers in the code.

func LoadFile added in v0.0.2

func LoadFile(filePath string) (string, error)

LoadFile reads the contents of a file at the specified path and returns it as a string. An error is returned if the file cannot be read or if it is not valid UTF-8.

func PrintChatCompletionStream

func PrintChatCompletionStream(stream *openai.ChatCompletionStream) (string, error)

PrintChatCompletionStream prints the chat completion stream to the console

func PrintColoredText

func PrintColoredText(text, cssColorCode string)

PrintColoredText prints the given text in the specified CSS color code using fmt.Print.

func PrintColoredTextLn

func PrintColoredTextLn(text, cssColorCode string)

PrintColoredTextLn prints the given text in the specified CSS color code using fmt.Println.

func ReadStdin

func ReadStdin() ([]byte, error)

ReadStdin reads from standard input and returns the bytes read.

func RemoveQuotes

func RemoveQuotes(s string) string

RemoveQuotes removes any quotes from a string using regex.

func ReplaceLines added in v0.0.3

func ReplaceLines(code string, startLine int, endLine int, newText string) (string, error)

ReplaceLines replaces the lines between the startLine and endLine with the new text.

func ReverseSlice

func ReverseSlice[T any](s []T)

ReverseSlice reverses the order of the elements in a slice of any type.

func StartsWithAny added in v0.0.3

func StartsWithAny(s string, prefixes []string) bool

StartsWithAny takes a string and a slice of prefixes and returns true if the string starts with any of the prefixes.

func StringInSlice

func StringInSlice(s string, slice []string) bool

StringInSlice checks if a string is in a slice of strings

func StringSliceToAnySlice

func StringSliceToAnySlice(s []string) []any

StringSliceToAnySlice converts a slice of strings to a slice of any.

func WriteFile

func WriteFile(filePath string, contents string) error

WriteFile writes a string to a file at the specified path.

Types

This section is empty.

Jump to

Keyboard shortcuts

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