npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

typo

v1.0.6

Published

`typo` is an extendable template engine designed for the future

Downloads

4,003

Readme

Build Status

typo

typo is an extendable template engine designed for the future:

  • featured with Promise and async/await.
  • powerful custom sync/async directives(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 directives

Basic:

typo.use('upper', word => word.toUpperCase())
typo.template('{{upper foo}} bar').then(console.log)
// FOO bar

Asychronous directives

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

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 to true
    • 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 in data, then it will print the expression directly if print(as default), or print nothing if ignore, or throw an error if throw.
    • directive_value_not_defined enum.<print|ignore|throw>=value_not_defined Tells typo what to do if the parameter expression of a directive is not found in data. And this option is default to the value of value_not_defined
// default options
typo.compile('{{blue color}}')()
// prints a blue letter, "color"
.then(console.log) => {

// value_not_defined: throw
typo.compile('{{blue color}}', {
  value_not_defined: 'throw'
})()
.catch((e) => {
  // code frame and
  // 'value not found for key "color"''
  console.error(e.message)
})

typo.compile('{{adjective}} {{blue color}}', {
  value_not_defined: 'throw',
  directive_value_not_defined: 'print'
})({
  adjective: 'beautiful'
})
// prints "beautiful color", and the letter color is blue
.then(console.log)

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

{{<directive>[:<directive-params>][|<directive&params>] <expression>}}
{{<expression>}}

License

MIT