String Notes

1 min read

Standard string transformations. All notes are infallible — they return a safe zero value for empty input and never error.

Reference

NoteSignatureReturns
toLowerstringstring
toUpperstringstring
trimSpacestringstring
trims, cutset stringstring
trimPrefixs, prefix stringstring
trimSuffixs, suffix stringstring
hasPrefixs, prefix stringbool
hasSuffixs, suffix stringbool
containss, substr stringbool
replaces, old, new stringstring (all occurrences)
splits, sep string[]string — empty slice for empty input
join[]string, sep stringstring
repeats string, n intstring
camelToKebabstringstring
truncates string, n intstring — appends ... if truncated

Examples

# Derive names
name: "{{ trimPrefix .spec.image \"myorg/\" }}"    # "nginx" from "myorg/nginx"
name: "{{ camelToKebab .spec.type }}"              # "web-server" from "WebServer"

# Safe display truncation (appends "...")
label: "{{ truncate .metadata.name 63 }}"

# Extract first element of a comma-separated list
image: "{{ index (split .spec.images \",\") 0 }}"

# Conditional suffix
host: "{{ toLower .spec.name }}.{{ .spec.domain }}"

For Kubernetes resource names (DNS labels), use truncateName from data notes — it hard-cuts without appending ..., which is not a valid character in resource names.