typo
typo
is an extendable template engine designed for the future:
- featured with
Promise
andasync/await
. - powerful custom sync/async directives(helpers).
Install
$ npm install typo --save
Usage
const typo = typo// Hello, Steve!
typo
with chalk
const typo = const chalk = typo typo// Then it will print a blue word "blue"
Custom directives
Basic:
typotypo// FOO bar
Asychronous directives
typotypo// Steve Jobs typo// Steve Jobs
Compile the template and use it Later
const template = typo // Once in a blue moon
typo({open, close})
Creates the typo
instance.
- open
String={{
The beginning of each directive. - close
String=}}
The end of each directive.
compile(template, compile_options)
Compiles a template into a function.
- template
String
- compile_options
Object
- async
Boolean=true
whether should be compiled into an asynchronous function, defaults totrue
- concurrency
Number=Number.POSITIVE_INFINITY
If compiled as an asynchronous function, the number of max concurrently pending directive functions. - value_not_defined
enum.<print|ignore|throw>=print
Suppose the value of an expression is not found indata
, then it will print the expression directly ifprint
(as default), or print nothing ifignore
, or throw an error ifthrow
. - directive_value_not_defined
enum.<print|ignore|throw>=value_not_defined
Tellstypo
what to do if the parameter expression of a directive is not found indata
. And this option is default to the value ofvalue_not_defined
- async
// default optionstypo// prints a blue letter, "color" // value_not_defined: throwtypo typo adjective: 'beautiful'// prints "beautiful color", and the letter color is blue
Returns function(data)
async: false
const result = typodataconsole
async: true (default)
typodata
template(template, data, compile_options)
- template
String
- data
Object=
- compile_options
Object=
Returns Promise
if compile_options.async
is true
(default), or String
the substituted result if is not.
Syntax
{{<directive>[:<directive-params>][|<directive¶ms>] <expression>}}{{<expression>}}
License
MIT