sub()
Substitute values into strings where the corresponding placeholders have been entered.
This function is valid in v2.0.0 to v2.24.3. This function has been downloaded 78 times.opt_subs
and its name must be surrounded in curly braces (eg. "Hello {name}!"
contains the name
placeholder). If a placeholder refers to a number, a ternary operator can be used (eg. "You have {apples} apple{apples?s:}"
). What appears between the ?
and the :
will replace the placeholder if the variable before the ?
is not 1
. What appears after the :
will replace the placeholder if the variable before the ?
is 1
. A 4-ary (AKA quaterary) operator can also be used if a placeholder refers to a number (eg. "You have {apples?{apples}:one:no} apple{apples?s:}"
). When using a 4-ary operator, whatever appears after the second :
will replace the placeholder if the variable before the ?
is 0
. If a placeholder is not ternary or 4-ary but ends with #
, opt_funcs
will be called on the value and the return value will be used. If a placeholder is not ternary or 4-ary but ends with #
followed by a name (eg. #ordinalize
), the function with that property name under opt_funcs
will be called for the value and the return value will replace the placeholder. If a placeholder evaluates to a function the function will be called all of the ternary or 4-ary values as arguments. Nested expressions are supported.global
template
.YourJS
template
. If this is an object or an array its properties or array items can be referenced to modify the values filled in within template
.template
with all of the valid placeholders filled in with their substitutions as found in opt_subs
.This function directly requires the following function which is included automatically:
has()