Documentation
¶
Index ¶
- func All(t *template.Template) template.FuncMap
- func Bracket(s interface{}) string
- func BracketWith(b string, s interface{}) (string, error)
- func Contains(list interface{}, item interface{}) (bool, error)
- func Filter(list interface{}, item interface{}) (interface{}, error)
- func First(list interface{}) (interface{}, error)
- func FormatJSON(indent string, j string) (string, error)
- func FromBase64(s string) (string, error)
- func GenerateIncludeFn(t *template.Template) func(string, interface{}) (string, error)
- func Indent(t int, content string) string
- func IsZero(val interface{}) bool
- func Join(list interface{}) (string, error)
- func JoinWith(glue string, list interface{}) (string, error)
- func Last(list interface{}) (interface{}, error)
- func List(s ...interface{}) (interface{}, error)
- func Newline(c ...int) string
- func Now() string
- func PadLeft(n int, s string) string
- func PadRight(n int, s string) string
- func Pop(list interface{}) (interface{}, error)
- func Prefix(prefix string, t int, content string) string
- func Push(list interface{}, item interface{}) (interface{}, error)
- func Rep(n int, s ...string) string
- func Rest(list interface{}) (interface{}, error)
- func Slice(i, j int, list interface{}) (interface{}, error)
- func Space(n int) string
- func SplitOn(glue string, s string) []string
- func Suffix(suffix string, t int, content string) string
- func Tab(n int) string
- func TerminalWidth() int
- func TitleCaseWithAbbr(abbrv interface{}, word string) (string, error)
- func ToBase64(s string) string
- func ToColumn(w int, s string) string
- func ToJSON(val interface{}) (string, error)
- func ToYAML(val interface{}) (string, error)
- func TypeKind(val interface{}) string
- func TypeName(val interface{}) string
- func Unshift(list interface{}, item interface{}) (interface{}, error)
- func UppercaseFirst(s string) string
- func WhenEmpty(d, s interface{}) interface{}
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bracket ¶ added in v0.6.3
func Bracket(s interface{}) string
Bracket adds brackets around the given string
func BracketWith ¶ added in v0.6.3
BracketWith adds brackets of a given type around the given string
func Contains ¶ added in v0.7.2
Contains returns true if the item is present in the list
Example ¶
helperApplyAndRenderTemplate(contains, a)
Output: {{.a}} = [a b c d e] {{contains .a "x"}} = false {{contains .a "d"}} = true {{contains .a 3}} = false
func Filter ¶ added in v0.7.2
func Filter(list interface{}, item interface{}) (interface{}, error)
Filter returns list with all instances of item removed
Example ¶
helperApplyAndRenderTemplate(filter, a)
Output: {{.a}} = [a b c d e] {{filter .a "x"}} = [a b c d e] {{filter .a 3}} = [a b c d e] {{filter .a "c"}} = [a b d e] {{.b}} = [f o o b a r] {{filter .b "o"}} = [f b a r]
func First ¶
func First(list interface{}) (interface{}, error)
First returns the head of a list
Example ¶
helperApplyAndRenderTemplate(first, a)
Output: {{.a}} = [a b c d e] {{first .a}} = a
func FormatJSON ¶ added in v0.7.0
FormatJSON returns the given json string, formatted with the given indent string
func FromBase64 ¶ added in v0.8.1
FromBase64 decodes the given encoded string to plain
func GenerateIncludeFn ¶
GenerateIncludeFn creates a function to be used as an "include" function in templates
func Indent ¶
Indent prints the given string with the given number of spaces prepended before each line
func IsZero ¶ added in v0.6.3
func IsZero(val interface{}) bool
IsZero returns true if the value given corresponds to it's types zero value, points to something zero valued, or if it's a type with a length which is 0
func JoinWith ¶ added in v0.7.0
JoinWith joins the given strings together using the given string as glue
func Last ¶
func Last(list interface{}) (interface{}, error)
Last returns the last item of a list
Example ¶
helperApplyAndRenderTemplate(last, a)
Output: {{.a}} = [a b c d e] {{last .a}} = e
func List ¶ added in v0.7.2
func List(s ...interface{}) (interface{}, error)
List returns a new list comprised of the given elements
Example ¶
helperApplyAndRenderTemplate(list, a)
Output: {{list "a" "b" "c"}} = [a b c] {{list "a" 5 false}} = [a 5 false] {{range list 1 2 3}}{{bracket .}}{{end}} = (1)(2)(3)
func Pop ¶ added in v0.7.2
func Pop(list interface{}) (interface{}, error)
Pop removes the first element of the list, returning the list
Example ¶
helperApplyAndRenderTemplate(pop, a)
Output: {{.a}} = [a b c d e] {{pop .a}} = [a b c d]
func Prefix ¶ added in v0.8.0
Prefix prints the given string with the given number of 'prefix' prepended before each line
func Push ¶ added in v0.7.2
func Push(list interface{}, item interface{}) (interface{}, error)
Push returns the list with item appended
Example ¶
helperApplyAndRenderTemplate(push, a)
Output: {{.a}} = [a b c d e] {{push .a "x"}} = [a b c d e x]
func Rest ¶
func Rest(list interface{}) (interface{}, error)
Rest / Shift returns the tail of a list
Example ¶
helperApplyAndRenderTemplate(rest, a)
Output: {{.a}} = [a b c d e] {{rest .a}} = [b c d e]
func Slice ¶ added in v0.7.2
Slice returns a slice of a list where i is the lower index (inclusive) and j is the upper index (exclusive) to extract
Example ¶
helperApplyAndRenderTemplate(slice, a)
Output: {{.a}} = [a b c d e] {{slice 1 3 .a}} = [b c]
func SplitOn ¶ added in v0.7.0
SplitOn creates an array from the given string by separating it by the glue string
func Suffix ¶ added in v0.8.0
Suffix prints the given string with the given number of 'suffix' appended to each line
func TerminalWidth ¶ added in v0.9.0
func TerminalWidth() int
TerminalWidth returns the number of columns that the terminal currently has, or 0 if the program isn't run in one, or it can't otherwise be determined
func TitleCaseWithAbbr ¶ added in v0.9.1
TitleCaseWithAbbr uppercases the first letter of each word, or the whole word if it matches a given abbreviation
func ToColumn ¶ added in v0.9.0
ToColumn formats the given text to not take more than 'w' characters per line, splitting on the space before the word that would take the line over. If no space can be found, the line isn't split (ie words bigger than the line size are printed unsplit)
Example ¶
ExampleToColumn
w := 40 s := "Lorem ipsum dolor\nsit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." got := ToColumn(w, s) fmt.Println(got)
Output: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
func TypeKind ¶ added in v0.9.2
func TypeKind(val interface{}) string
TypeKind returns the 'kind” of the given value as a string
func TypeName ¶ added in v0.7.0
func TypeName(val interface{}) string
TypeName returns the type of the given value as a string
func Unshift ¶ added in v0.7.2
func Unshift(list interface{}, item interface{}) (interface{}, error)
Unshift returns the list with item prepended
Example ¶
helperApplyAndRenderTemplate(unshift, a)
Output: {{.a}} = [a b c d e] {{unshift .a "x"}} = [x a b c d e]
func UppercaseFirst ¶
UppercaseFirst converts the first character in a string to uppercase
Types ¶
This section is empty.