[][src]Module sprig::strings

Functions

abbrev

Truncate a string with ellipses. abbrev 5 "hello world" yields "he..."

abbrevboth

Abbreviate from both sides, yielding "...lo wo..."

base32decode

Base 32 decode a string.

base32encode

Base 32 encode a string.

base64decode

Base 64 decode a string.

base64encode

Base 64 encode a string.

contains

Golang's strings.Contains, but with the arguments switched: contains substr str.

has_prefix

Golang's strings.hasPrefix, but with the arguments switched

has_suffix

Golang's strings.hasSuffix, but with the arguments switched

indent

Indent every line in a given string to the specified indent width. This is useful when aligning multi-line strings.

initials

Given a multi-word string, return the initials. initials "Matt Butcher" returns "MB"

join

Golang's strings.Join, but as join SEP SLICE

lower

Golang's strings.ToLower

nindent

Same as the indent function, but prepends a new line to the beginning of the string.

nospace

Remove all space characters from a string. nospace "h e l l o" becomes "hello"

plural
rand_alpha

Given a length, generate an alphabetic string

rand_alpha_numeric

Given a length, generate a random alphanumeric sequence

rand_ascii

Given a length, generate a random ASCII string (symbols included)

rand_numeric

Given a length, generate a string of digits.

repeat

strings.Repeat, but with the arguments switched: repeat count str. (This simplifies common pipelines)

replace
split

Golang's strings.Split, but as split SEP STRING. The results are returned as a map with the indexes set to _N, where N is an integer starting from 0. Use it like this: {{$v := "foo/bar/baz" | split "/"}}{{$v._0}} (Prints foo)

substring

Given string, start, and length, return a substr.

trim

Golang's strings.TrimSpace

trim_all

Golang's strings.Trim, but with the argument order reversed trimAll "$" "$5.00" or `"$5.00 | trimAll "$"

trim_prefix

Golang's strings.TrimPrefix, but with the argument order reversed trimPrefix "$" "$5"

trim_suffix

Golang's strings.TrimSuffix, but with the argument order reversed: trimSuffix "-" "ends-with-"

trunc

Truncate a string (no suffix). trunc 5 "Hello World" yields "hello".

untitle

Remove title casing

upper

Golang's strings.ToUpper