package compare

import "github.com/gohugoio/hugo/tpl/compare"

Package compare provides template functions for comparing values.

Index

Package Files

compare.go init.go

type Namespace

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

Namespace provides template functions for the "compare" namespace.

func New

func New(loc *time.Location, caseInsensitive bool) *Namespace

New returns a new instance of the compare-namespaced template functions.

func (*Namespace) Conditional

func (n *Namespace) Conditional(condition bool, a, b any) any

Conditional can be used as a ternary operator. It returns a if condition, else b.

func (*Namespace) Default

func (*Namespace) Default(dflt any, given ...any) (any, error)

Default checks whether a given value is set and returns a default value if it is not. "Set" in this context means non-zero for numeric types and times; non-zero length for strings, arrays, slices, and maps; any boolean or struct value; or non-nil for any other types.

func (*Namespace) Eq

func (n *Namespace) Eq(first any, others ...any) bool

Eq returns the boolean truth of arg1 == arg2 || arg1 == arg3 || arg1 == arg4.

func (*Namespace) Ge

func (n *Namespace) Ge(first any, others ...any) bool

Ge returns the boolean truth of arg1 >= arg2 && arg1 >= arg3 && arg1 >= arg4.

func (*Namespace) Gt

func (n *Namespace) Gt(first any, others ...any) bool

Gt returns the boolean truth of arg1 > arg2 && arg1 > arg3 && arg1 > arg4.

func (*Namespace) Le

func (n *Namespace) Le(first any, others ...any) bool

Le returns the boolean truth of arg1 <= arg2 && arg1 <= arg3 && arg1 <= arg4.

func (*Namespace) Lt

func (n *Namespace) Lt(first any, others ...any) bool

Lt returns the boolean truth of arg1 < arg2 && arg1 < arg3 && arg1 < arg4.

func (*Namespace) LtCollate

func (n *Namespace) LtCollate(collator *langs.Collator, first any, others ...any) bool

Lt returns the boolean truth of arg1 < arg2 && arg1 < arg3 && arg1 < arg4. The provided collator will be used for string comparisons. This is for internal use.

func (*Namespace) Ne

func (n *Namespace) Ne(first any, others ...any) bool

Ne returns the boolean truth of arg1 != arg2 && arg1 != arg3 && arg1 != arg4.

Version
v0.101.0 (latest)
Published
Jun 16, 2022
Platform
linux/amd64
Imports
11 packages (graph)
Last checked
2 hours ago

Tools for package owners.