Functions and types for BajoTemplate.buildCompileImports

With these functions now your templates can use all listed functions below. The imports are automatically injected into the template's scope during compilation.

Example
// In your template file (e.g., template.html)
<p><%= _t('Hello, %s!', user.name) %></p>
<p><%= _format(user.birthDate, 'date') %></p>
<p><%= _routePath('home:/user/{id}/profile', { id: user.id }) %></p>

Methods

(inner) FnDump(value)

Dump a value to console.

Parameters:
NameTypeDescription
value*

Value to be dumped.

(inner) FnExcerpt(text, maxWordsopt, trailCharsopt) → {string}

Get excerpt of a string.

Parameters:
NameTypeAttributesDefaultDescription
textstring

String to be excerpted.

maxWordsnumber<optional>
50

Max number of words.

trailCharsstring<optional>
'...'

Characters to append if truncated.

Returns:

Excerpted string.

Type: 
string

(inner) FnFindRoute(name, methodopt) → {object|null}

Find route by name. Only available when Waibu plugin is installed & loaded.

See Waibu.findRoute for more details.

Parameters:
NameTypeAttributesDefaultDescription
namestring

Route name.

methodstring<optional>
'GET'

HTTP method (e.g., 'GET', 'POST').

Returns:

Route object or null if not found.

Type: 
object | null

(inner) FnFormat(val, type, optsopt) → {string}

Format text with optional parameters.

See Bajo.format for more details.

Parameters:
NameTypeAttributesDescription
val*

Value to be formatted.

typestring

Value type (e.g., 'string', 'number', 'date').

optsobject<optional>

Optional formatting options.

Returns:

Formatted text.

Type: 
string

(inner) FnGetSetting(key) → {*}

Get a setting value by key. Only available when Waibu plugin is installed & loaded.

See Waibu.getSetting for more details.

Parameters:
NameTypeDescription
keystring

Setting key.

Returns:

Setting value.

Type: 
*

(inner) FnHasPlugin(nameOrAlias) → {boolean}

Check if a plugin is loaded by its name or alias.

Parameters:
NameTypeDescription
nameOrAliasstring

Plugin name or alias.

Returns:

True if the plugin is loaded, false otherwise.

Type: 
boolean

(inner) FnJsonStringify(value, replaceropt, spaceopt) → {string}

JSON stringify a value. Only available when WaibuMpa plugin is installed & loaded.

See WaibuMpa.jsonStringify for more details.

Parameters:
NameTypeAttributesDescription
value*

Value to be stringified.

replacerobject<optional>

Optional replacer function or array.

spacestring | number<optional>

Optional space for indentation.

Returns:

JSON stringified value.

Type: 
string

(inner) FnParseMarkdown(value) → {string}

Parse markdown text. Only available when BajoMarkdown plugin is installed & loaded. See BajoMarkdown.parse for more details.

Parameters:
NameTypeDescription
valuestring

Markdown text to be parsed.

Returns:

Parsed HTML string.

Type: 
string

(inner) FnRoutePath(name, optionsopt) → {string|null}

Get route path by name. Only available when Waibu plugin is installed & loaded.

See Waibu.routePath for more details.

Parameters:
NameTypeAttributesDefaultDescription
namestring

Route name.

optionsobject<optional>
{}

Options object.

Returns:

Route path or null if not found.

Type: 
string | null

(inner) FnTitleize(str) → {string}

Get titleized version of a string.

Parameters:
NameTypeDescription
strstring

String to be titleized.

Returns:

Titleized string.

Type: 
string

(inner) FnTranslate(text, …args) → {string}

Translate text with optional parameters.

Parameters:
NameTypeAttributesDescription
textstring

Text to be translated.

args*<repeatable>

Optional parameters for translation.

Returns:

Translated text.

Type: 
string