# ert

> Express routing templates provides a simple micro-templating syntax for building strings from a template and a `request` object.

Latest version **1.0.1** (published 2013-05-13) · MIT license · 0 weekly downloads

## Install

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

## 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.1 |
| Published | 2013-05-13 |
| First published | 2013-04-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | ForbesLindesay |
| Maintainers | forbeslindesay |
| Keywords | express, routing, template, redirect, expression |

## Links

- npm: https://www.npmjs.com/package/ert
- Repository: https://github.com/ForbesLindesay/ert
- npm.io page: https://npm.io/package/ert

## Dependencies (1)

- [character-parser](https://npm.io/package/character-parser.md) ~1.0.0

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2013-05-13
- 1.0.0 — 2013-04-25

## README

# ert

Express routing templates provides a simple micro-templating syntax for building strings from a template and a `request` object.

[![Build Status](https://travis-ci.org/ForbesLindesay/ert.png?branch=master)](https://travis-ci.org/ForbesLindesay/ert)
[![Dependency Status](https://gemnasium.com/ForbesLindesay/ert.png)](https://gemnasium.com/ForbesLindesay/ert)

## Installation

    $ npm install ert

## Usage

```js
var ert = require('ert');
var express = require('express');
var app = express();

app.get('/:package', function (req, res) {
  res.redirect(ert(req, '/package/:package'));
});

app.listen(3000);
```

## Syntax

### Code Blocks

e.g.

```js
ert(req, '/foo/bar/[req.parms.x || "default-x"]')
```

Code in squre brackets (`[` and `]`) is evalutated as a JavaScript expression.  It has `req` available as an object.  It also supports shortcuts, so you could write the above as:

```js
ert(req, '/foo/bar/[:x || "default-x"]')
```

### Shortucts

There are characters that are shortucts, the defaults of these are:

```js
exports.shortcutMap = {
  ':': 'req.params',
  '$': 'req.query',
  '@': 'req.body'
};
```

These can be used directly like:

```js
ert(req, '/foo/bar/:x')
```

which is equivallent to:

```js
ert(req, '/foo/bar/[req.params && req.params["x"]]')
```

## API

### ert(req, src) or ert.translate(req, src)

Transforms the string with `req` and returns the resulting string.  It caches the compiled function so should be pretty good for performance.

### ert.compile(src)

Compiles `src` and returns a JavaScript expression as a string.  This can be used to generate client side code with something like:

```js
function client(name) {
  return 'function name(req){return ' + ert.compile(src) + '}';
}
```

### ert.compileFn(src)

Compiles `src` and returns a function which expects a single argument, `request`.

## License

MIT

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