On This Page
Template Helpers
Template helpers are special utilities that are available across all templates and provide utilities like classMap
, formatDate
, concat
stringify
that can be used to format values for output.
Helper Example
In this example formatDate
is used to format the display of a date set in the components state.
Helpers Functions
Logical
exists
Checks if a value is not empty.
isEmpty
Checks if a value is empty.
hasAny
Checks if an array has any elements.
both
Checks if both a and b are truthy.
either
Checks if either a or b is truthy.
maybe
Returns trueExpr if expr is truthy, falseExpr otherwise.
String
stringify
Converts a value to JSON string.
concat
Concatenates all arguments.
capitalize
Capitalizes the first letter of text.
titleCase
Converts text to title case.
tokenize
Tokenizes a string.
Array and Object
join
Joins array elements with a delimiter.
joinComma
Joins array elements with commas.
arrayFromObject
Converts an object to an array for use with {#each}
object
Can be used to pass arbitary data as an object to other functions.
range
Returns an array with range
CSS
classes
Joins CSS classes, the second param spaceAfter
adds a space after the final class name.
classIf
Conditionally applies a CSS class.
classMap
Applies multiple CSS classes based on conditions.
activeIf
Adds ‘active’ class if expression is truthy.
selectedIf
Adds ‘selected’ class if expression is truthy.
disabledIf
Adds ‘disabled’ class if expression is truthy.
checkedIf
Adds ‘checked’ class if expression is truthy.
Comparison
is
Checks equality (==).
not
Checks inequality (!=).
isEqual
Checks strict equality (===).
isNotEqual
Checks strict inequality (!==).
greaterThan
Checks if a > b.
lessThan
Checks if a < b.
greaterThanEquals
Checks if a is greater than or equal to b.
lessThanEquals
Checks if a is less than or equal to b.
Numeric and Date
numberFromIndex
Returns a + 1.
maybePlural
Adds plural suffix if value is not 1.
formatDate
Formats a date.
formatDateTime
Formats a date with time.
formatDateTimeSeconds
Formats a date with time and seconds.
Debug
log
Logs arguments to console.
debugger
Triggers debugger.
debugReactivity
Debugs reactivity.