node-azuki
A string template engine for NodeJs, treating everything as pure strings thus templates are included but not limited to HTML!
NodeJs VM is used to evaluate expressions in templates; therefore, it currently has no browser support!
Example
javascript
const Azuki parseFile = // dictionaryconst dict = test: 't_e_s_t' nested: 'test' // other js variables are allowed num: 1 const parser = dict // Using Nodejs Stream APIfs // Or using `parseFile` utility function
template
This is a {% test %}!
Nested case: "{% {% nested %} %}"
Conditional case: {% num === 1 ? '1' : '2' %}
output
This is a t_e_s_t!
Nested case: "t_e_s_t"
Conditional case: 1
Caveat
Avoid using preserved words as dictionary keys. Preserved words are e.g. built-in objects and functions any standard global object has. Also see vm.createContext() in the Nodejs official document.
JSON
this
console
toString
(Which also means that you can utilize such functions like JSON.parse
and JSON.stringify
in the template.)
API
WIP
new Azuki()
new AzukiParser()
parseFile()
- Overloads
- (
src
,dict
,parserOptions
?,encoding
?): Promise<string> - (
src
,dest
,dict
,parserOptions
?,encoding
?): Promise<void>
- (
- Parameters
src
stringdest
stringdict
{[key: string]: string}parserOptions
ParserOptionsencoding
string (Default:"utf8"
)
ParserOptions