cheat-sheet.md

April 11, 2026 · View on GitHub

{% raw %}

Quick reference for all 55+ templjs built-in functions. Use pipe syntax in templates: {{ value | functionName(args) }}.

String Functions (20)

FunctionSignatureExample
upperupper()"hello" | upper"HELLO"
lowerlower()"HELLO" | lower"hello"
capitalizecapitalize()"hello" | capitalize"Hello"
trimtrim()" hi " | trim"hi"
ltrimltrim()" hi " | ltrim"hi "
rtrimrtrim()" hi " | rtrim" hi"
replacereplace(search, replacement)"hello" | replace("l", "r")"herro"
sliceslice(start[, end])"hello" | slice(0, 3)"hel"
splitsplit(delimiter)"a,b" | split(",")["a","b"]
joinjoin(separator)["a","b"] | join(",")"a,b"
startsWithstartsWith(prefix)"hello" | startsWith("he")true
endsWithendsWith(suffix)"hello" | endsWith("lo")true
includesincludes(substring)"hello world" | includes("world")true
indexOfindexOf(substring)"hello" | indexOf("ll")2
padStartpadStart(length[, char])"5" | padStart(3, "0")"005"
padEndpadEnd(length[, char])"5" | padEnd(3, "0")"500"
repeatrepeat(count)"ab" | repeat(3)"ababab"
reversereverse()"hello" | reverse"olleh"
escapeescape()"<b>" | escape"&lt;b&gt;"
truncatetruncate(length[, suffix])"hello world" | truncate(5)"hello..."

Number Functions (23)

FunctionSignatureExample
roundround([decimals])3.14159 | round(2)3.14
floorfloor()3.7 | floor3
ceilceil()3.2 | ceil4
absabs()-5 | abs5
minmin(b[, ...]) or min(array)min(5, 2, 8)2
maxmax(b[, ...]) or max(array)max(5, 2, 8)8
clampclamp(min, max)5 | clamp(1, 3)3
sqrtsqrt()16 | sqrt4
powpow(exponent)2 | pow(3)8
loglog([base])8 | log(2)3
expexp()1 | exp2.718...
sinsin()0 | sin0
coscos()0 | cos1
tantan()0 | tan0
signsign()-5 | sign-1
toFixedtoFixed(decimals)3.14159 | toFixed(2)"3.14"
parseIntparseInt([radix])"42" | parseInt42
parseFloatparseFloat()"3.14" | parseFloat3.14
isNaNisNaN()NaN | isNaNtrue
isFiniteisFinite()42 | isFinitetrue
sumsum(array)[1,2,3] | sum6
avgavg(array)[2,4,6] | avg4
productproduct(array)[2,3,4] | product24

Datetime Functions (15)

FunctionSignatureExample
nownow()now() → Unix ms timestamp
formatformat(pattern[, tz])ts | format("YYYY-MM-DD")"2024-02-18"
parseparse(string, pattern)"2024-02-18" | parse("YYYY-MM-DD") → timestamp
timestamptimestamp(isoString)"2024-02-18T12:00:00Z" | timestamp → ms
toISOtoISO()ts | toISO"2024-02-18T12:00:00.000Z"
fromISOfromISO()"2024-02-18T12:00:00.000Z" | fromISO → ms
addDaysaddDays(n)ts | addDays(5) → ts+5days
addHoursaddHours(n)ts | addHours(3) → ts+3hrs
addMinutesaddMinutes(n)ts | addMinutes(30) → ts+30min
diffdiff(other)ts | diff(ts2) → ms difference
getYeargetYear()ts | getYear2024
getMonthgetMonth()ts | getMonth1 (0-indexed)
getDay / getDategetDay()ts | getDay18
getHourgetHour()ts | getHour12
getDayOfWeekgetDayOfWeek()ts | getDayOfWeek0 (0=Sun)
timezonetimezone(tz)ts | timezone("America/New_York") → formatted string

Array Functions (19)

FunctionSignatureExample
lengthlength()[1,2,3] | length3
sizesize()[1,2,3] | size3 (alias)
firstfirst()[1,2,3] | first1
lastlast()[1,2,3] | last3
nthnth(index)["a","b","c"] | nth(1)"b"
reversereverse()[1,2,3] | reverse[3,2,1]
sortsort([key])[3,1,2] | sort[1,2,3]
uniqueunique()[1,2,2,3] | unique[1,2,3]
filterfilter(predicate)items | filter("active")
mapmap(fn|key)users | map("name") → names array
reducereduce(fn, initial)[1,2,3] | reduce("+", 0)6
findfind(predicate)users | find("id == 1") → first match
includesincludes(value)[1,2,3] | includes(2)true
indexOfindexOf(value)[1,2,3] | indexOf(2)1
sliceslice(start[, end])[1,2,3,4] | slice(1, 3)[2,3]
concatconcat(other)[1,2] | concat([3,4])[1,2,3,4]
flattenflatten([depth])[[1,2],[3]] | flatten[1,2,3]
wherewhere(key)items | where("published") → truthy items
joinjoin(separator)[1,2,3] | join(",")"1,2,3"

Object Functions (11)

FunctionSignatureExample
keyskeys(){a:1,b:2} | keys["a","b"]
valuesvalues(){a:1,b:2} | values[1,2]
entriesentries(){a:1} | entries[["a",1]]
hashas(key){a:1} | has("a")true
getget(path[, default])obj | get("a.b", 0) → value or 0
mergemerge(other){a:1} | merge({b:2}){a:1,b:2}
assignassign(other){a:1} | assign({b:2}){a:1,b:2}
pickpick(keys)obj | pick(["a","c"]) → subset
omitomit(keys)obj | omit(["b"]) → obj without b
lengthlength(){a:1,b:2} | length2
isEmptyisEmpty(){} | isEmptytrue

Utility Functions (6)

FunctionSignatureExample
defaultdefault(fallback)null | default("Guest")"Guest"
fallbackfallback(value)alias for default
typeoftypeof()123 | typeof"number"
stringstring()123 | string"123"
numbernumber([default])"42" | number42
jsonjson(){a:1} | json'{"a":1}'

Filter Pipe Syntax

{{ value | filter }}
{{ value | filter(arg1, arg2) }}
{{ value | filter1 | filter2(arg) }}

Expression Predicates

filter, find, and where accept expression strings:

{{ scores | filter("> 90") }}
{{ users | find("active == true") }}
{{ items | where("published") }}

Quick Path Reference

{{ user.name }}          {{/* dot notation */}}
{{ items[0] }}           {{/* array index */}}
{{ items[idx] }}         {{/* variable index */}}
{{ map["key name"] }}    {{/* quoted key */}}

See Also

{% endraw %}