Built-in Helpers
There are many helper functions available for the scaffdog template engine.
Helpers#
camel
#
Conversion to a camel case.
Signature:
camel(value)
Paramters:
Parameter | Type | Description |
---|---|---|
value | string | Input value. |
snake
#
Conversion to a snake case.
Signature:
snake(value)
Paramters:
Parameter | Type | Description |
---|---|---|
value | string | Input value. |
pascal
#
Conversion to a pascal case.
Signature:
pascal(value)
Paramters:
Parameter | Type | Description |
---|---|---|
value | string | Input value. |
kebab
#
Conversion to a kebab case.
Signature:
kebab(value)
Paramters:
Parameter | Type | Description |
---|---|---|
value | string | Input value. |
constant
#
Conversion to a constant case.
Signature:
constant(value)
Paramters:
Parameter | Type | Description |
---|---|---|
value | string | Input value. |
upper
#
Conversion to a upper case.
Signature:
upper(value)
Paramters:
Parameter | Type | Description |
---|---|---|
value | string | Input value. |
lower
#
Conversion to a lower case.
Signature:
lower(value)
Paramters:
Parameter | Type | Description |
---|---|---|
value | string | Input value. |
plur
#
Pluralize a word. See the plur documentation for details.
Signature:
plur(value, count?)
Paramters:
Parameter | Type | Description |
---|---|---|
value | string | Input value. |
count | number | The count to determine whether to use singular or plural. If omitted, defaults to plural. |
replace
#
Replace pattern
with replacement
. pattern
is specified as a string, but it is treated as a regular expression.
Signature:
replace(value, pattern, replacement)
Paramters:
Parameter | Type | Description |
---|---|---|
value | string | Input value. |
pattern | string | Pattern string to search. |
replacement | string | String to overwrite found string |
trim
#
Alias for String.prototype.trim
.
Signature:
trim(value)
Paramters:
Parameter | Type | Description |
---|---|---|
value | string | Input value. |
ltrim
#
Alias for String.prototype.trimStart
.
Signature:
ltrim(value)
Paramters:
Parameter | Type | Description |
---|---|---|
value | string | Input value. |
rtrim
#
Alias for String.prototype.trimEnd
.
Signature:
rtrim(value)
Paramters:
Parameter | Type | Description |
---|---|---|
value | string | Input value. |
seq
#
Generates a numeric array for the specified range. Similar signature to the seq
command.
Signature:
seq(first, increment?, last?)
Paramters:
Parameter | Type | Description |
---|---|---|
first | number | Start numeric value. |
increment | number | Numeric value to be added repeatedly. |
last | number | Last numeric value. |
append
#
Appends elements to an array and returns the resulting array. The array received as an argument is not modified, and immutable operations are performed.
Signature:
append(value, ...args)
Paramters:
Parameter | Type | Description |
---|---|---|
value | any[] | Input value. |
args | any[] | Elements to be added to the array. |
uniq
#
Takes duplicates from array elements and returns the resulting array. The array received as an argument is not modified, and immutable operations are performed.
Signature:
uniq(value)
Paramters:
Parameter | Type | Description |
---|---|---|
value | any[] | Input value. |
{{ arr := seq 2 | append 1 | append 2 | append 3 }}{{ arr }}--> 1,2,1,2,3{{ arr | uniq }}--> 1,2,3
split
#
Alias for String.prototype.split
.
Signature:
split(value, sep)
Paramters:
Parameter | Type | Description |
---|---|---|
value | string | Input value. |
sep | string | Delimiter string value to split. |
join
#
Alias for Array.prototype.join
.
Signature:
join(value, sep)
Paramters:
Parameter | Type | Description |
---|---|---|
value | string | Input value. |
sep | string | Delimiter string value to join. |
len
#
Returns the length of the value. If the length cannot be determined, returns 0.
Signature:
len(value)
Paramters:
Parameter | Type | Description |
---|---|---|
value | any | Input value. |
slice
#
Returns portion of an array. Similar signature to String.prototype.slice
.
Signature:
slice(value, start, end?)
Paramters:
Parameter | Type | Description |
---|---|---|
value | string | any[] | Input value. |
start | number | The first index to include in the return value. |
end | number | The index to include at the end of the return value. |
contains
#
Searches for an item in a string or array and returns a boolean value.
Signature:
contains(search, item)
Paramters:
Parameter | Type | Description |
---|---|---|
search | string | any[] | A string or array to search for. |
item | any | Item to search for. |
{{ contains("foo", "o") ? "true" : "false" }}--> true{{ contains("foo", "b") ? "true" : "false" }}--> false{{ contains(seq(3), 2) ? "true" : "false" }}--> true{{ contains(seq(3), 4) ? "true" : "false" }}--> false
s2n
#
Converts a string to a number.
Signature:
s2n(value)
Paramters:
Parameter | Type | Description |
---|---|---|
value | string | Input value. |
n2s
#
Converts a number to a string.
Signature:
n2s(value)
Paramters:
Parameter | Type | Description |
---|---|---|
value | number | Input value. |
before
#
Returns string before the position by n
. If n
is a number, it is the specified line; if it is a string, it is the first matched line.
See the Injection section for more information on how to make use of it.
Signature:
before(value, n, offset?)
Paramters:
Parameter | Type | Description |
---|---|---|
value | string | Input value. |
n | string | number | Pattern string to search. or number of lines. |
offset | number | Offset from search result position. |
after
#
Returns string after the position by n
. If n
is a number, it is the specified line; if it is a string, it is the first matched line.
See the Injection section for more information on how to make use of it.
Signature:
after(value, n, offset?)
Paramters:
Parameter | Type | Description |
---|---|---|
value | string | Input value. |
n | string | number | Pattern string to search. or number of lines. |
offset | number | Offset from search result position. |
eval
#
Executes the specified code as JavaScript and returns the result.
Signature:
eval(code)
Paramters:
Parameter | Type | Description |
---|---|---|
code | string | Source code. |
date
#
See the dayjs documentation for format details.
Signature:
date(format?)
Paramters:
Parameter | Type | Description |
---|---|---|
format | string | Date format. |
noop
#
Returns an empty string.
Signature:
noop()
define
#
Defines a local variable in the template scope.
Signature:
define(value, key)
Paramters:
Parameter | Type | Description |
---|---|---|
value | string | Input value. |
key | string | Variable key name. |
relative
#
Convert the path from the template file to the path from the destination file.
Signature:
relative(path)
Paramters:
Parameter | Type | Description |
---|---|---|
path | string | The file path to search. |
Example:
{{ relative "../src/utils" }}
resolve
#
Resolves a sequence of paths or path segments into an absolute path.
Signature:
resolve(...paths)
Paramters:
Parameter | Type | Description |
---|---|---|
paths | string[] | File path segments. |
Example:
{{ resolve "../src" "common" }}
read
#
Read the specified file. The contents of the loaded file are also expanded as a template.
Signature:
read(path)
Paramters:
Parameter | Type | Description |
---|---|---|
path | string | Relative path to the file to be read. |
Example:
{{ resolve "../src" "common" }}
Last edited on