Package Exports
- typo
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (typo) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
typo
typo is an extendable template engine designed for the future:
- featured with
Promiseandasync/await. - powerful custom sync/async helpers.
Install
$ npm install typo --saveUsage
const typo = require('typo')()
typo.template('Hello, {{user.name}}!', {
user: {
name: 'Steve'
}
}).then(console.log)
// Hello, Steve!typo with chalk
const typo = require('typo')()
const chalk = require('typo-chalk')
typo.use(chalk)
typo.template('Once in a {{blue blue}} moon').then(console.log)
// Then it will print a blue word "blue"Custom helpers
Basic:
typo.use('upper', word => word.toUpperCase())
typo.template('{{upper foo}} bar').then(console.log)
// FOO barAsychronous helpers
typo.use('fullname', async name => await getFullNameFromServer(name))
typo.template('{{fullname name}}', {name: 'Steve'}).then(console.log)
// Steve Jobs
typo.template('{{fullname Steve}}').then(console.log)
// Steve JobsCompile the template and use it Later
const template = typo.compile(`Once in a {{blue color}} moon`)
template({color: 'blue'})
.then(console.log)
// Once in a blue moontypo({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=truewhether should be compiled into an asynchronous function, defaults totrue - concurrency
Number=Number.POSITIVE_INFINITYIf compiled as an asynchronous function, the number of max concurrently pending helper functions. - value_not_defined
enum.<print|ignore|throw>=printSuppose 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.
- async
Returns function(data)
async: false
const result = typo.compile(template)(data)
console.log(result)async: true (default)
typo.compile(template)(data).then(console.log)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
{{<helper-name>[:<helper-params>][|<helper-name¶ms>] <expression>}}
{{<expression>}}License
MIT