Sprig Functions

Sprig functions are provided by the jhelm-gotemplate-sprig module. They are auto-discovered via ServiceLoader when the module is on the classpath (priority 100).

1. Categories

1.1. Strings

Function Description

trim, trimAll, trimPrefix, trimSuffix

Whitespace and prefix/suffix trimming

upper, lower, title, untitle

Case conversion

repeat, substr, trunc, abbrev

String manipulation

quote, squote, cat

Quoting and concatenation

indent, nindent

Indentation (nindent prepends a newline)

snakecase, camelcase, kebabcase

Naming convention conversion

replace, split, splitList, join

Split/join/replace operations

regexMatch, regexFind, regexFindAll, regexReplaceAll, regexReplaceAllLiteral, regexSplit

Regular expressions (with must* variants that throw on error)

contains, hasPrefix, hasSuffix

String predicates

nospace, initials, wrap, wrapWith, plural, swapcase, shuffle

Additional string utilities

1.2. Collections

Function Description

list, tuple

Create new lists

first, last, rest, initial

Access list elements

append, prepend, concat

Extend lists

reverse, sortAlpha, uniq, compact, without

List transformations

has, contains

List predicates

dict

Create a new map from key-value pairs

set, unset

Modify maps

hasKey, get, pluck

Map access

keys, values

Map introspection

merge, mustMerge, mergeOverwrite, mustMergeOverwrite

Deep map merging

pick, omit

Map filtering

dig

Deep nested map access

chunk, slice

List slicing (Sprig’s slice overrides Go built-in with additional features)

1.3. Logic

Function Description

default

Returns the first non-empty value

empty

Returns true if value is empty/zero/nil

coalesce

Returns first non-empty argument

ternary

ternary trueVal falseVal condition — conditional value

fail

Unconditionally fails template execution with message

required

Validates value is present and non-empty (actually a Helm function, see Helm Functions)

1.4. Math

Function Description

add, add1, sub, mul, div, mod

Basic arithmetic

floor, ceil, round

Rounding

min, max

Min/max selection

int, int64, float64

Numeric type conversion

1.5. Encoding

Function Description

b64enc, b64dec

Base64 encoding/decoding

b32enc, b32dec

Base32 encoding/decoding

sha1sum, sha256sum, adler32sum

Hash functions

1.6. Crypto

Function Description

uuidv4

Generate UUID v4

randAlphaNum, randAlpha, randNumeric, randAscii

Random string generation

htpasswd

BCrypt password hash (Apache htpasswd format)

encryptAES, decryptAES

AES encryption/decryption

genPrivateKey

Generate RSA/ECDSA private key

genCA

Generate self-signed CA certificate

genSelfSignedCert, genSignedCert

Generate certificates

derivePassword

Master Password algorithm

1.7. Date

Function Description

now

Current time

date, dateInZone

Format date to string

dateModify, mustDateModify

Add duration to date

unixEpoch

Convert to Unix timestamp

toDate, mustToDate

Parse string to date

htmlDate, htmlDateInZone

Format for HTML date input

1.8. Reflection

Function Description

typeOf, kindOf

Get Java type/kind name

typeIs, kindIs

Check type/kind

deepEqual

Deep equality comparison

deepCopy

Deep copy of value

1.9. Network

Function Description

getHostByName

DNS lookup returning IP address

urlParse

Parse URL into map (scheme, host, path, etc.)

1.10. Semver

Function Description

semver

Parse semantic version string into object with .Major, .Minor, .Patch

semverCompare

Compare version against constraint (e.g., >=1.2.0)