Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added trim functions #1558

Merged
merged 10 commits into from
Apr 12, 2022
Next Next commit
Added trim, trimPrefix, trimSuffix functions
jsanant committed Mar 28, 2022
commit 0895d3daf5ad6f19c147f3c7390bc7f4308e0d50
15 changes: 15 additions & 0 deletions template/funcs.go
Original file line number Diff line number Diff line change
@@ -950,6 +950,21 @@ func join(sep string, a []string) (string, error) {
return strings.Join(a, sep), nil
}

// trim is a version of strings.Trim that can be piped
func trim(cutset string, s string) (string, error) {
return strings.Trim(s, cutset), nil
}

// trimPrefix is a version of strings.TrimPrefix that can be piped
func trimPrefix(prefix string, s string) (string, error) {
return strings.TrimPrefix(s, prefix), nil
}

// trimSuffix is a version of strings.TrimSuffix that can be piped
func trimSuffix(suffix string, s string) (string, error) {
return strings.TrimSuffix(s, suffix), nil
}

// TrimSpace is a version of strings.TrimSpace that can be piped
func trimSpace(s string) (string, error) {
return strings.TrimSpace(s), nil
3 changes: 3 additions & 0 deletions template/template.go
Original file line number Diff line number Diff line change
@@ -284,6 +284,9 @@ func funcMap(i *funcMapInput) template.FuncMap {
"indent": indent,
"loop": loop,
"join": join,
"trim": trim,
"trimPrefix": trimPrefix,
"trimSuffix": trimSuffix,
"trimSpace": trimSpace,
"parseBool": parseBool,
"parseFloat": parseFloat,