Socket
Socket
Sign inDemoInstall

typo

Package Overview
Dependencies
16
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    typo

typo


Version published
Weekly downloads
560
decreased by-10.69%
Maintainers
1
Install size
289 kB
Created
Weekly downloads
 

Readme

Source

Build Status

typo

typo is an extendable template engine designed for the future:

  • featured with Promise and async/await.
  • powerful custom sync/async helpers.

Install

$ npm install typo --save

Usage

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 bar

Asychronous 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 Jobs

Compile 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 moon

compile(template, compile_options)

Returns function(data)

  • template String
  • compile_options Object
    • async Boolean=true whether should be compiled into an asynchronous function, defualts to true
    • concurrency Number=Number.POSITIVE_INFINITY If compiled as an asynchronous function, the number of max concurrently pending helper functions.
    • value_not_defined enum.<print|ignore|throw> Suppose the value of an expression is not found in data, then it will print the expression directly if print, or print nothing if ignore, or throw an error if throw.

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&params>] <expression>}}
{{<expression>}}

License

MIT

Keywords

FAQs

Last updated on 25 Feb 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc