Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
e61682b24c
|
|||
5dc9e98f6b
|
@@ -3,6 +3,6 @@ BFB goext library
|
|||||||
|
|
||||||
A collection of general & useful library methods
|
A collection of general & useful library methods
|
||||||
|
|
||||||
Every subfolder is a seperate dependency and can be imported individually
|
This should not have any heavy dependencies (gin, mongo, etc) and add missing basic language features...
|
||||||
|
|
||||||
Potentially needs `export GOPRIVATE="gogs.mikescher.com"`
|
Potentially needs `export GOPRIVATE="gogs.mikescher.com"`
|
@@ -142,6 +142,27 @@ func ArrAnyErr(arr interface{}, fn func(int) (bool, error)) (bool, error) {
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ArrFirst[T comparable](arr []T, comp func(v T) bool) (T, bool) {
|
||||||
|
for _, v := range arr {
|
||||||
|
if comp(v) {
|
||||||
|
return v, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return *new(T), false
|
||||||
|
}
|
||||||
|
|
||||||
|
func ArrLast[T comparable](arr []T, comp func(v T) bool) (T, bool) {
|
||||||
|
found := false
|
||||||
|
result := *new(T)
|
||||||
|
for _, v := range arr {
|
||||||
|
if comp(v) {
|
||||||
|
found = true
|
||||||
|
result = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result, found
|
||||||
|
}
|
||||||
|
|
||||||
func AddToSet[T comparable](set []T, add T) []T {
|
func AddToSet[T comparable](set []T, add T) []T {
|
||||||
for _, v := range set {
|
for _, v := range set {
|
||||||
if v == add {
|
if v == add {
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
package termext
|
package termext
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
colorReset = "\033[0m"
|
colorReset = "\033[0m"
|
||||||
colorRed = "\033[31m"
|
colorRed = "\033[31m"
|
||||||
@@ -43,3 +45,17 @@ func Gray(v string) string {
|
|||||||
func White(v string) string {
|
func White(v string) string {
|
||||||
return colorWhite + v + colorReset
|
return colorWhite + v + colorReset
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CleanString(v string) string {
|
||||||
|
v = strings.ReplaceAll(v, colorReset, "")
|
||||||
|
v = strings.ReplaceAll(v, colorRed, "")
|
||||||
|
v = strings.ReplaceAll(v, colorGreen, "")
|
||||||
|
v = strings.ReplaceAll(v, colorYellow, "")
|
||||||
|
v = strings.ReplaceAll(v, colorBlue, "")
|
||||||
|
v = strings.ReplaceAll(v, colorPurple, "")
|
||||||
|
v = strings.ReplaceAll(v, colorCyan, "")
|
||||||
|
v = strings.ReplaceAll(v, colorGray, "")
|
||||||
|
v = strings.ReplaceAll(v, colorWhite, "")
|
||||||
|
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user