funcs

package
v0.0.0-...-0132329 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Functions = make(map[string]any)

Functions

func ConstantCase

func ConstantCase(text string) string

ConstantCase converts the given string into constant case, while trimming leading and trailing whitespaces; for example CONSTANT_CASE

func ContainsRune

func ContainsRune(value string, runee rune) bool

func ContainsSubstring

func ContainsSubstring(value string, regex string) bool

ContainsSubstring checks if value matches the given regex

func Count

func Count(value, substr string) int

func DashCase

func DashCase(text string) string

DashCase converts the given string into dash case, while trimming leading and trailing whitespaces; for example dash-case

func DateAfter

func DateAfter(dateA time.Time, dateB time.Time) bool

DateAfter returns if dateB is after dateA

func DateBefore

func DateBefore(dateA time.Time, dateB time.Time) bool

DateBefore returns if dateB is before dateA

func DateDay

func DateDay(date time.Time) uint

DateDay returns the day component of the given date

func DateEqual

func DateEqual(dateA time.Time, dateB time.Time) bool

DateEqual returns if dateB is equal to dateA

func DateFormat

func DateFormat(date time.Time, format string) string

DateFormat formats the given date, using the given format

func DateFuncs

func DateFuncs() map[string]any

DateFuncs returns the map of the template functions that work on date

func DateHour

func DateHour(date time.Time) uint

DateHour returns the hour component of the given date

func DateMinute

func DateMinute(date time.Time) uint

DateMinute returns the minute component of the given date

func DateMonth

func DateMonth(date time.Time) uint

DateMonth returns the month component of the given date, as a 1 based integer

func DateMonthString

func DateMonthString(date time.Time) string

DateMonthString returns the month component of the given date as a string

func DateParse

func DateParse(value string, format string) time.Time

DateParse parse the value as a date, using the given format, or the zero value if the format is invalid

func DateSecond

func DateSecond(date time.Time) uint

DateSecond returns the second component of the given date

func DateWeekday

func DateWeekday(date time.Time) uint

DateWeekday returns the weekday component of the given date, as a 1 based integer

func DateWeekdayString

func DateWeekdayString(date time.Time) string

DateWeekdayString returns the weekday component of the given date as a string

func DateYear

func DateYear(date time.Time) uint

DateYear returns the year component of the given date

func DateZone

func DateZone(date time.Time) string

DateZone returns the zone component of the given date, as a string

func DateZoneOffset

func DateZoneOffset(date time.Time) int

DateZoneOffset returns the zone component of the given date, as a offset from UTC

func DromedaryCase

func DromedaryCase(text string) string

DromedaryCase converts the given string into dromedary case, while trimming leading and trailing whitespaces; for example dromedaryCase

func EndsWith

func EndsWith(value string, suffix string) bool

EndsWith checks if the given value has the given suffix

func FilepathAbsolute

func FilepathAbsolute(path string) string

FilepathAbsolute returns the absolute path of the given path, using the current path to resolve it

func FilepathBasename

func FilepathBasename(path string) string

FilepathBasename returns the file or directory name of the given path

func FilepathDirname

func FilepathDirname(path string) string

FilepathDirname returns the parent path of the given path, as a absolute path

func FilepathExists

func FilepathExists(path string) bool

FilepathExists checks if the given path exists

func FilepathExtension

func FilepathExtension(path string) string

FilepathExtension returns the extension of the given file path, or empty if there is no extension, note that hidden directories under Unix return empty, as they are not files

func FilepathFuncs

func FilepathFuncs() map[string]any

FilepathFuncs returns the map of the template functions that work on filepath

func FilepathIsDirectory

func FilepathIsDirectory(path string) bool

FilepathIsDirectory checks if the given path exists and is a directory

func FilepathIsFile

func FilepathIsFile(path string) bool

FilepathIsFile checks if the given path exists and is a file

func FilepathJoinPath

func FilepathJoinPath(paths ...string) string

FilepathJoinPath returns the joined path of concatenting all of the given path components with the current platform separator

func FilepathRelativise

func FilepathRelativise(path string, from string) string

FilepathRelativise returns the relative path of the given path, using the from path to resolve it, if the from path is empty, then the current path is used

func FormatFormatAny

func FormatFormatAny(format string, args ...any) string

FormatFormatAny formats the given string, using the standard fmt.Sprintf

func FormatFormatBytesIEC

func FormatFormatBytesIEC(num any) string

FormatFormatBytesIEC formats the given number as a IEC byte string, eg. 7896759 as 7.531 MB

func FormatFormatBytesSI

func FormatFormatBytesSI(num any) string

FormatFormatBytesSI formats the given number as a SI byte string, eg. 7896759 as 7,897 MB

func FormatFormatFloat

func FormatFormatFloat(num any, format string) string

FormatFormatFloat formats the given float as a string, using the given format

func FormatFormatInteger

func FormatFormatInteger(num any, format string) string

FormatFormatInteger formats the given integer as a string, using the given format

func FormatFormatOrdinal

func FormatFormatOrdinal(num int) string

FormatFormatOrdinal formats the given integer as an ordinal, eg. 3 as 3rd

func FormatFuncs

func FormatFuncs() map[string]any

FormatFuncs returns the map of the template functions that work on format

func HTTPHeaderCase

func HTTPHeaderCase(text string) string

HTTPHeaderCase converts the given string into http header case, while trimming leading and trailing whitespaces; for example Http-Header-Case

func Index

func Index(value, substr string) int

func IndexRune

func IndexRune(value string, runee rune) int

func JoinText

func JoinText(separator string, slice []string) string

JoinWords joins the given string array, using separator as a separator

func LastIndex

func LastIndex(value, substr string) int

func LowerCase

func LowerCase(text string) string

LowerCase converts the given string into lower case, for example LOWERCASE

func MathAbs

func MathAbs(num any) any

MathAbs return the magnitude of num or NaN if the argument is not a number

func MathAcos

func MathAcos(num any) any

MathAcos returns the arccosine, in radians

func MathAcosh

func MathAcosh(num any) any

MathAcosh returns the inverse hyperbolic cosine

func MathAsin

func MathAsin(num any) any

MathAsin returns the arcsine, in radians

func MathAsinh

func MathAsinh(num any) any

MathAsinh returns the inverse hyperbolic sine

func MathAtan

func MathAtan(num any) any

MathAtan teturns the arctangent, in radians

func MathAtanh

func MathAtanh(num any) any

MathAtanh returns the inverse hyperbolic tangent

func MathAvg

func MathAvg(nums []any) float64

MathAvg return the average of all numbers in the given array nums

func MathCeil

func MathCeil(num any) any

MathCeil return the mathematical ceil of the given num or NaN if the argument is not a number

func MathCos

func MathCos(num any) any

MathCos returns the cosine of the radian argument

func MathCosh

func MathCosh(num any) any

MathCosh returns the hyperbolic cosine

func MathCubicRoot

func MathCubicRoot(num any) float64

MathCubicRoot returns the cubic root

func MathFloor

func MathFloor(num any) any

MathFloor return the mathematical floor of the given num or NaN if the argument is not a number

func MathFuncs

func MathFuncs() map[string]any

MathFuncs returns the map of the template functions that work on math

func MathGamma

func MathGamma(num any) any

MathGamma returns the Gamma function of num

func MathIsInf

func MathIsInf(num any, sign int) bool

MathIsInf Reports whether num is an infinity, according to sign;

func MathIsNaN

func MathIsNaN(num any) bool

MathIsNaN Reports whether num is an IEEE 754 “not-a-any” value;

func MathLog

func MathLog(num any) any

MathLog returns the natural logarithm

func MathLog10

func MathLog10(num any) any

MathLog10 Returns the decimal logarithm;

func MathLog2

func MathLog2(num any) any

MathLog2 Returns the binary logarithm;

func MathMax

func MathMax(a any, b any) any

MathMax returns the larger of a or b

func MathMin

func MathMin(a any, b any) any

MathMin returns the smaller of a or b

func MathPower

func MathPower(num any, exp any) float64

MathPower returns num**exp, the base-num exponential of exp

func MathRandom

func MathRandom(minimum, maximum any) any

MathRandom generates a random value between the given minimum and maximum or NaN if: - The arguments are not the same type - Maximum is less or equal to zero - Minimum is less than zero - Maximum is less or equal to minimum

func MathRound

func MathRound(num any) any

MathRound rounds the given num

func MathSin

func MathSin(num any) any

MathSin returns the sine of the radian argument

func MathSinh

func MathSinh(num any) any

MathSinh returns the hyperbolic sine

func MathSquareRoot

func MathSquareRoot(num any) any

MathSquareRoot returns the square root

func MathSum

func MathSum(nums []any) float64

MathSum returns the sum of all numbers in nums

func MathTan

func MathTan(num any) any

MathTan returns the tangent of the radian argument

func MathTanh

func MathTanh(num any) any

MathTanh returns the hyperbolic tangent

func MathTrunc

func MathTrunc(num any) any

MathTrunc returns the integer value, truncating it

func MiscFuncs

func MiscFuncs() map[string]any

MiscFuncs returns the map of the template functions that work on misc

func MiscIsBool

func MiscIsBool(a any) bool

MiscIsBool checks if the argument has a boolean type

func MiscIsFloat

func MiscIsFloat(a any) bool

MiscIsFloat checks if the argument has a float type

func MiscIsInteger

func MiscIsInteger(a any) bool

MiscIsInteger checks if the argument has an integer type

func MiscIsMap

func MiscIsMap(a any) bool

MiscIsMap checks if the argument has a map type

func MiscIsRune

func MiscIsRune(a any) bool

MiscIsRune checks if the argument has a rune type

func MiscIsSigned

func MiscIsSigned(a any) bool

MiscIsSigned checks if the number is signed or not

func MiscIsSlice

func MiscIsSlice(a any) bool

MiscIsSlice checks if the argument has a slice type

func MiscIsString

func MiscIsString(a any) bool

MiscIsString checks if the argument has a string type

func MiscTypeOf

func MiscTypeOf(a any) string

MiscTypeOf returns a string corresponding to the type of a, either bool, integer, float, string, rune, slice or map

func PascalCase

func PascalCase(text string) string

PascalCase converts the given string into pascal case, while trimming leading and trailing whitespaces; for example PascalCase. Note that if you have something like "this ,string" the result will be "This,string", only spaces, dashes and underscores will be removed!

func Repeat

func Repeat(value string, count int) string

func ReplaceAll

func ReplaceAll(value, old, news string) string

func SentenceCase

func SentenceCase(text string) string

SentenceCase converts the given string into sentence case, while trimming leading and trailing whitespaces; for example Sentence case

func SlicesAfter

func SlicesAfter(value []any, index uint) []any

SlicesAfter returns all of the items in an slices after the specified index

func SlicesBefore

func SlicesBefore(value []any, index uint) []any

SlicesBefore returns all of the items in the collection before the specified count

func SlicesExists

func SlicesExists(value []any, element any) bool

SlicesExists returns if an slices has the given element

func SlicesFirst

func SlicesFirst(value []any) any

SlicesFirst returns the first item or nil if it does not exist

func SlicesFuncs

func SlicesFuncs() map[string]any

SlicesFuncs returns the map of the template functions that work on slices

func SlicesGet

func SlicesGet(value []any, index uint) any

SlicesGet returns the item from slices at index index

func SlicesLast

func SlicesLast(value []any) any

SlicesLast returns the last item

func SlicesLength

func SlicesLength(value []any) uint

SlicesLength returns the size of the slices

func SlicesReverse

func SlicesReverse(value []any) []any

SlicesReverse reverses the elements in an slices

func SlicesSort

func SlicesSort(value []any, sortFunc func(any, any) int) []any

SlicesSort sort the given slices, using the given sort function

func SlicesUnique

func SlicesUnique(value []any) []any

SlicesUnique returns an slices without any duplicates

func SnailCase

func SnailCase(text string) string

SnailCase converts the given string into snail case, while trimming leading and trailing whitespaces; for example snail_case

func SplitWords

func SplitWords(value string) []string

SplitWords splits the given value by its words aka by spaces, while trimming leading and trailing whitespaces.

func StartCase

func StartCase(text string) string

StartCase converts the given string into start case, while trimming leading and trailing whitespaces; for example Start Case

func StartsWith

func StartsWith(value string, prefix string) bool

StartsWith checks if the given value has the given prefix

func StickyCase

func StickyCase(text string) string

StickyCase converts the given string into sticky case, while trimming leading and trailing whitespaces; for example StIcKyCaSe

func StringFuncs

func StringFuncs() map[string]any

StringFuncs returns the map of the template functions that work on strings

func TrainCase

func TrainCase(text string) string

TrainCase converts the given string into train case, while trimming leading and trailing whitespaces; for example TRAIN-CASE

func Trim

func Trim(value string, chars []rune) string

Trim trims the runes in the chars slice, from the leading and trailing value string

func TrimPrefix

func TrimPrefix(value string, prefix string) string

TrimPrefix trims the leading prefix from the value string

func TrimSpace

func TrimSpace(value string) string

TrimSpace trims the leading and trailing spaces

func TrimSuffix

func TrimSuffix(value string, suffix string) string

TrimSuffix trims the trailing suffix from the value string

func URLDecodeQuery

func URLDecodeQuery(query string) url.Values

URLDecodeQuery decodes the given url query, to a Values object which is map[string][]string

func URLDecodeURI

func URLDecodeURI(name string) string

URLDecodeURI URI decodes the argument name

func URLEncodeQuery

func URLEncodeQuery(params url.Values) string

URLEncodeQuery encodes the given Values object which is map[string][]string, using URL query encoding

func URLEncodeURI

func URLEncodeURI(name string) string

URLEncodeURI URI encodes the argument name;

func URLFragment

func URLFragment(name string) string

URLFragment returns the fragment of the given url, or empty if the URL is invalid or missing the fragment

func URLFuncs

func URLFuncs() map[string]any

URLFuncs returns the map of the template functions that work on url

func URLHTMLEscape

func URLHTMLEscape(name string) string

URLHTMLEscape escapes the argument name, according to HTML rules;

func URLHTMLUnescape

func URLHTMLUnescape(name string) string

URLHTMLUnescape unescapes the argument name, according to HTML rules

func URLHost

func URLHost(name string) string

URLHost returns the host of the given url, or empty if the URL is invalid or missing the host

func URLIsURL

func URLIsURL(name string) bool

URLIsURL checks if the given argument is a valid URL

func URLJSONEscape

func URLJSONEscape(name string) string

URLJSONEscape escapes the argument name, according to JSON rules;

func URLJSONUnescape

func URLJSONUnescape(name string) string

URLJSONUnescape unescapes the argument name, according to ecmascript rules

func URLPath

func URLPath(name string) string

URLPath returns the path of the given url, or empty if the URL is invalid or missing the path

func URLPathComponents

func URLPathComponents(name string) []string

URLPathComponents returns a slice with all path components of the given url, or an empty slice if the URL is invalid or missing the scheme

func URLPort

func URLPort(name string) int

URLPort returns the port of the given url, or -1 if the URL is invalid or missing the port

func URLQuery

func URLQuery(name string) string

URLQuery returns the query of the given url, or empty if the URL is invalid or missing the query

func URLScheme

func URLScheme(name string) string

URLScheme returns the scheme of the given url, or empty if the URL is invalid or missing the scheme

func URLUserInfo

func URLUserInfo(name string) string

URLUserInfo returns the user info of the given url, or empty if the URL is invalid or missing the user info

func URLXMLEscape

func URLXMLEscape(name string) string

URLXMLEscape escapes the argument name, according to XML rules

func UpperCase

func UpperCase(text string) string

UpperCase converts the given string into upper case, for example UPPERCASE

Types

type CutResult

type CutResult struct {
	Before string
	After  string
	Found  bool
}

func Cut

func Cut(value, sep string) CutResult

func CutPrefix

func CutPrefix(value, prefix string) CutResult

func CutSuffix

func CutSuffix(value, suffix string) CutResult

type Float

type Float interface {
	~float32 | ~float64
}

type Integer

type Integer interface {
	Signed | Unsigned
}

type Number

type Number interface {
	Float | Integer
}

type Signed

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Sizes

type Sizes uint
const (
	Size8 Sizes = iota
	Size16
	Size32
	Size64
	SizeUnknown
)

func MiscSizeof

func MiscSizeof(a any) Sizes

MiscSizeof returns the size of the number, either 8, 16, 32 or 64

type Unsigned

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

Jump to

Keyboard shortcuts

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