hyogen.md

0.14.0

Methods

Method calls in {{ }} and @hg expressions are restricted to a small whitelist. Arbitrary chaining (.map, .trim, etc.) is not allowed.

toLocaleString

The only permitted method is .toLocaleString(...). Arguments follow JavaScript conventions — the library does not validate them.

<!--
@hg
const population = 2825000
@endhg
-->

Population: {{ population.toLocaleString('en-US') }}

Output:

Population: 2,825,000

Works on component props too:

{{ population.toLocaleString('ja-JP') }}

Allowed property: .length

.length is an allowed property (not a method). It returns the element count for arrays and the character count for strings.

<!--
@hg
const items = [1, 2, 3]
const label = "abcd"
@endhg
-->

{{ items.length }} / {{ label.length }}

Output:

3 / 4

length() with parentheses is not allowed (parse_error).

Template literals

.toLocaleString and .length are also allowed inside `${…}` in @hg blocks:

<!--
@hg
const n = 1000
const label = `count: ${n.toLocaleString()}`
@endhg
-->

Function calls

The only callable functions are registered components (component … as name):

{{ cityItem({ city: "Osaka", population: 2825000 }) }}

There are no built-in functions beyond registered components.

Not allowed

{{ items.map(x => x.name) }}   <!-- parse_error -->
{{ text.trim() }}              <!-- parse_error -->
{{ items.slice(0) }}           <!-- parse_error -->
{{ items.length() }}           <!-- parse_error -->
{{ Math.max(a, b) }}           <!-- parse_error -->

Use @hg declarations, echo, or component templates to prepare values instead.