-
Notifications
You must be signed in to change notification settings - Fork 1
/
funcs.go
45 lines (42 loc) · 1.24 KB
/
funcs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package templit
import (
"strings"
"text/template"
)
// DefaultFuncMap is the default function map for templates.
var DefaultFuncMap = template.FuncMap{
"lower": strings.ToLower,
"upper": strings.ToUpper,
"trim": strings.TrimSpace,
"split": strings.Split,
"join": strings.Join,
"replace": strings.ReplaceAll,
"contains": strings.Contains,
"hasPrefix": strings.HasPrefix,
"hasSuffix": strings.HasSuffix,
"trimPrefix": strings.TrimPrefix,
"trimSuffix": strings.TrimSuffix,
"trimSpace": strings.TrimSpace,
"trimLeft": strings.TrimLeft,
"trimRight": strings.TrimRight,
"count": strings.Count,
"repeat": strings.Repeat,
"equalFold": strings.EqualFold,
"splitN": strings.SplitN,
"splitAfter": strings.SplitAfter,
"splitAfterN": strings.SplitAfterN,
"fields": strings.Fields,
"toTitle": strings.ToTitle,
"toSnakeCase": ToSnakeCase,
"toCamelCase": ToCamelCase,
"toKebabCase": ToKebabCase,
"toPascalCase": ToPascalCase,
"default": defaultVal,
}
// defaultVal returns defaultValue if value is nil, otherwise value.
func defaultVal(value, defaultValue interface{}) interface{} {
if value == nil {
return defaultValue
}
return value
}