Squiggly

Strings

upper, lower, trim, replace, split, join, printf and friends.

The string builtins. Most are callable as a function, a pipe target, or (where the arity allows) a method. The standard squiggly convention is data-last: in pipe form s | trim becomes trim s, in s | replace 'a' 'b' it becomes replace 'a' 'b' s. The tables below list the function-call signature in left-to-right order; pipe form threads the piped value in as the last argument.

Case & whitespace

FunctionAritySignatureWhat
upper1upper sUppercase
lower1lower sLowercase
capitalize1capitalize sUppercase the first letter
trim1trim sStrip leading + trailing whitespace
ltrim1ltrim sStrip leading whitespace only
rtrim1rtrim sStrip trailing whitespace only
newline_to_br1newline_to_br sReplace \n with <br />
FunctionAritySignatureWhat
length1length sNumber of characters (works on lists / maps too)
isEmpty1isEmpty sTrue iff length is zero
nonEmpty1nonEmpty sTrue iff length is non-zero
startsWith2startsWith prefix sTrue iff s starts with prefix
endsWith2endsWith suffix sTrue iff s ends with suffix
contains2contains needle sTrue iff s contains needle

Slicing & shaping

FunctionAritySignatureWhat
reverse1reverse sReverse the string
substring2/3substring from s / substring from until sHalf-open slice; from/until are character indices
truncate2/3truncate n s / truncate n ellipsis sTruncate to n words; appends ellipsis (default ) when shortened
split2split sep sSplit on a literal separator; returns a list

Editing

FunctionAritySignatureWhat
replace3replace old new sReplace every occurrence of old with new
remove2remove substr sDrop every occurrence of substr
removeFirst2removeFirst substr sDrop only the first occurrence of substr
htmlEscape1htmlEscape sEscape &<>'" for safe HTML embedding

Formatted output

FunctionAritySignatureWhat
printf1+printf fmt args...Format-string output (Java Formatter rules: %d / %05d / %,d / %.2f / %-10s / %x / %%)

Examples

{{ .title | upper }}                              CSS HOOK
{{ .author | trim | lower | replace ' ' '-' }}    "ed-maxedon"
{{ .body | split '\n' | length }}                 number of lines

{{ if .filename | endsWith '.md' }}               markdown file
{{ if .body | contains '<!--more-->' }}           has a manual summary cut

{{ split ',' .csv | join ' / ' }}                 reformat

{{ printf '%05d' .count }}                        zero-padded
{{ printf '%,d' .revenue }}                       1,234,567
{{ printf '%-10s|%s' .key .value }}               left-pad first column

Search

Esc
to navigate to open Esc to close