gohelp

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2023 License: BSD-2-Clause Imports: 7 Imported by: 9

README

gohelp

helper functions

Documentation

Index

Constants

View Source
const (
	AnsiReset = "\x1b[0m"

	AnsiBlack   = "\x1b[30;1m"
	AnsiRed     = "\x1b[31;1m"
	AnsiGreen   = "\x1b[32;1m"
	AnsiYellow  = "\x1b[33;1m"
	AnsiBlue    = "\x1b[34;1m"
	AnsiMagenta = "\x1b[35;1m"
	AnsiCyan    = "\x1b[36;1m"
	AnsiWhite   = "\x1b[37;1m"

	AnsiCustom     = "\x1b[38;5;%vm"
	AnsiCustomCode = "\x1b[38;5;"

	AnsiBackgroundBlack   = "\x1b[40;1m"
	AnsiBackgroundRed     = "\x1b[42;1m"
	AnsiBackgroundGreen   = "\x1b[42;1m"
	AnsiBackgroundYellow  = "\x1b[43;1m"
	AnsiBackgroundBlue    = "\x1b[44;1m"
	AnsiBackgroundMagenta = "\x1b[45;1m"
	AnsiBackgroundCyan    = "\x1b[46;1m"
	AnsiBackgroundWhite   = "\x1b[47;1m"

	AnsiBackgroundCustom = "\x1b[48;5;%vm"

	AnsiBold      = "\x1b[1m"
	AnsiUnderline = "\x1b[4m"
	AnsiReversed  = "\x1b[7m"

	AnsiCursorUp    = "\x1b[%vA"
	AnsiCursorDown  = "\x1b[%vB"
	AnsiCursorRight = "\x1b[%vC"
	AnsiCursorLeft  = "\x1b[%vD"
)
View Source
const Charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

Variables

View Source
var (
	// AnsiRainbowCodes color code for rainbow words
	// 1 - red
	// 208 - orange
	// 11 - yellow
	// 40 - green
	// 45 - blue
	// 27 - blue
	// 93 - purple
	AnsiRainbowCodes = []string{"1", "208", "11", "40", "45", "27", "93"}
)

Functions

func AppendUnique added in v1.0.0

func AppendUnique[T comparable](slice []T, values ...T) []T

AppendUnique append unique value to array

func ArrayIntersect added in v1.0.0

func ArrayIntersect[T comparable](target []T, destination []T) (intersect []T, removedTargets int32)

ArrayIntersect shows duplicated elements in both slices

func BeforeString

func BeforeString(source string, substr string) string

BeforeString get string in source before substring

func Blue added in v1.0.0

func Blue(v interface{}) string

Blue wrap into blue color

func CheckBracers added in v1.1.2

func CheckBracers(source string, stack Stack[byte]) error

CheckBracers check if bracers is corrects

func Convert added in v1.1.1

func Convert[S, T any](source S) T

Convert unsafe convert. Use carefully

func Cyan added in v1.0.0

func Cyan(v interface{}) string

Cyan wrap into cyan color

func Each added in v1.0.0

func Each[S any](s []S, callback func(S))

Each iterate thought []S and apply on each item collback

func ExistsInArray added in v1.0.0

func ExistsInArray[T comparable](value T, slice []T) bool

ExistsInArray Check if item exists in slice

func Filter added in v1.0.0

func Filter[S any](s []S, callback func(S) bool) []S

Filter argument source via callback

func GetRndDateTime

func GetRndDateTime() time.Time

func GetRndId

func GetRndId() int

func GetRndNumber

func GetRndNumber(min int, max int) int

func GetRndPhone

func GetRndPhone() int

func Green added in v1.0.0

func Green(v interface{}) string

Green wrap into green color

func Implode

func Implode[T comparable](values []T, sep string) string

Implode join values via separator

func Index added in v1.0.0

func Index[T comparable](value T, slice []T) int

Index return index of item if exists. -1 if not

func Magenta added in v1.0.0

func Magenta(v interface{}) string

Magenta wrap into magenta color

func Map added in v1.0.0

func Map[S, D any](s []S, callback func(S) D) []D

Map argument source and result destination

func NewUUID

func NewUUID() string

NewUUID uuid constructor

func Ptr added in v1.1.1

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

Ptr get pointer of value

func Rainbow added in v1.0.0

func Rainbow(str string, sep rune) string

Rainbow crete rainbow string str - string for transformation sep - string separator

func RandString

func RandString(length int) string

RandString create random string

func Red added in v1.0.0

func Red(v interface{}) string

Red wrap into red color

func Reduce added in v1.0.0

func Reduce[S, D any](init D, s []S, callback func(D, S) D) D

Reduce implementation

func ToCamelCase

func ToCamelCase(str string, isFirstTitle bool) string

ToCamelCase transform to camelCase

func ToUnderscore

func ToUnderscore(str string) string

ToUnderscore transform string to underscore case

func Underline added in v1.0.0

func Underline(v interface{}) string

Underline wrap into underline text

func Unique added in v1.0.0

func Unique[T comparable](left []T, right []T) []T

Unique create unique slice between left and right slices

func UniqueLeft added in v1.0.0

func UniqueLeft[T comparable](left []T, right []T) []T

UniqueLeft create unique slice from left and right slices

func Yellow added in v1.0.0

func Yellow(v interface{}) string

Yellow wrap into yellow color

Types

type Iterator added in v1.0.0

type Iterator struct {
	// contains filtered or unexported fields
}

Iterator struct

func NewIterator added in v1.0.0

func NewIterator(len int) *Iterator

NewIterator Iterator constructor

func (*Iterator) Count added in v1.0.0

func (c *Iterator) Count() int

Count Iterator Get count of items

func (*Iterator) Cursor added in v1.0.0

func (c *Iterator) Cursor() int

Cursor Iterator Get cursor

func (*Iterator) Next added in v1.0.0

func (c *Iterator) Next() bool

Next Iterator next iteration

func (*Iterator) Reset added in v1.0.0

func (c *Iterator) Reset() *Iterator

Reset cursor

func (*Iterator) SetCount added in v1.0.0

func (c *Iterator) SetCount(count int) *Iterator

SetCount Iterator Set count

type Stack added in v1.0.0

type Stack[T any] []T

Stack of any type

func (Stack[T]) Pop added in v1.0.0

func (s Stack[T]) Pop() (T, bool, Stack[T])

Pop value

func (Stack[T]) Push added in v1.0.0

func (s Stack[T]) Push(v T) Stack[T]

Push value

type UUID

type UUID struct {
	// contains filtered or unexported fields
}

UUID type

func ParseUUID added in v0.3.2

func ParseUUID(data string) *UUID

ParseUUID uuid parser

func (*UUID) Generate

func (u *UUID) Generate() *UUID

Generate uuid

func (*UUID) Get

func (u *UUID) Get() *string

Get uuid

func (*UUID) IsValid

func (u *UUID) IsValid() bool

IsValid is uuid valid

func (*UUID) Reset

func (u *UUID) Reset() *UUID

Reset uuid

Jump to

Keyboard shortcuts

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