# typo

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

Latest version **1.0.6** (published 2017-03-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install typo
pnpm add typo
yarn add typo
bun add typo
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2017-03-19 |
| First published | 2013-06-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=7.2 |
| Dependencies | 7 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | kaelzhang |
| Maintainers | kael |
| Keywords | typo, template, engine, template engine, helpers, scalable, custom helpers |

## Links

- npm: https://www.npmjs.com/package/typo
- Repository: https://github.com/kaelzhang/node-typo
- Homepage: https://github.com/kaelzhang/node-typo#readme
- Issues: https://github.com/kaelzhang/node-typo/issues
- npm.io page: https://npm.io/package/typo

## Dependencies (7)

- [p-map](https://npm.io/package/p-map.md) ^1.1.1
- [p-reduce](https://npm.io/package/p-reduce.md) ^1.0.0
- [split-string](https://npm.io/package/split-string.md) ^1.0.0
- [babel-runtime](https://npm.io/package/babel-runtime.md) ^6.23.0
- [object-access](https://npm.io/package/object-access.md) ^1.1.4
- [babel-code-frame](https://npm.io/package/babel-code-frame.md) ^6.22.0
- [escape-string-regexp](https://npm.io/package/escape-string-regexp.md) ^1.0.5

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 1.0.6 (latest) — 2017-03-19
- 1.0.5 — 2017-03-17
- 1.0.4 — 2017-02-25
- 1.0.3 — 2017-02-25
- 1.0.2 — 2017-02-25
- 1.0.1 — 2017-02-25
- 1.0.0 — 2017-02-25
- 0.2.11 — 2013-10-29
- 0.1.14 — 2013-09-26
- 0.1.13 — 2013-08-03
- 0.1.12 — 2013-08-03
- 0.1.11 — 2013-07-30
- 0.1.10 — 2013-06-18
- 0.1.9 — 2013-06-18
- 0.1.8 — 2013-06-18
- … 3 more at https://npm.io/package/typo/versions

## README

[![Build Status](https://travis-ci.org/kaelzhang/node-typo.svg?branch=master)](https://travis-ci.org/kaelzhang/node-typo)
<!-- optional appveyor tst
[![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/kaelzhang/node-typo?branch=master&svg=true)](https://ci.appveyor.com/project/kaelzhang/node-typo)
-->
<!-- optional npm version
[![NPM version](https://badge.fury.io/js/typo.svg)](http://badge.fury.io/js/typo)
-->
<!-- optional npm downloads
[![npm module downloads per month](http://img.shields.io/npm/dm/typo.svg)](https://www.npmjs.org/package/typo)
-->
<!-- optional dependency status
[![Dependency Status](https://david-dm.org/kaelzhang/node-typo.svg)](https://david-dm.org/kaelzhang/node-typo)
-->

# typo

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

- featured with `Promise` and `async/await`.
- powerful custom sync/async directives(helpers).

## Install

```sh
$ npm install typo --save
```

## Usage

```js
const typo = require('typo')()
typo.template('Hello, {{user.name}}!', {
  user: {
    name: 'Steve'
  }
}).then(console.log)
// Hello, Steve!
```

### `typo` with chalk

```js
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:

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

### Asychronous directives

```js
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

```js
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`

```js
// 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

```js
const result = typo.compile(template)(data)
console.log(result)
```

async: true (default)

```js
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

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


## License

MIT

---
_Source: https://npm.io/package/typo · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
