{"_id":"ert","_rev":"7-20448e2da28c02518498f54d5cad3168","name":"ert","description":"Express routing templates provides a simple micro-templating syntax for building strings from a template and a `request` object.","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"ert","version":"1.0.0","description":"Express routing templates provides a simple micro-templating syntax for building strings from a template and a `request` object.","main":"index.js","scripts":{"test":"node test"},"repository":{"type":"git","url":"https://github.com/ForbesLindesay/ert.git"},"keywords":["express","routing","template","redirect","expression"],"author":{"name":"ForbesLindesay"},"license":"MIT","dependencies":{"character-parser":"~1.0.0"},"readme":"# ert\r\n\r\nExpress routing templates provides a simple micro-templating syntax for building strings from a template and a `request` object.\r\n\r\n[![Build Status](https://travis-ci.org/ForbesLindesay/ert.png?branch=master)](https://travis-ci.org/ForbesLindesay/ert)\r\n[![Dependency Status](https://gemnasium.com/ForbesLindesay/ert.png)](https://gemnasium.com/ForbesLindesay/ert)\r\n\r\n## Installation\r\n\r\n    $ npm install ert\r\n\r\n## Usage\r\n\r\n```js\r\nvar ert = require('ert');\r\nvar express = require('express');\r\nvar app = express();\r\n\r\napp.get('/:package', function (req, res) {\r\n  res.redirect(ert(req, '/package/:package'));\r\n});\r\n\r\napp.listen(3000);\r\n```\r\n\r\n## Syntax\r\n\r\n### Code Blocks\r\n\r\ne.g.\r\n\r\n```js\r\nert(req, '/foo/bar/[req.parms.x || \"default-x\"]')\r\n```\r\n\r\nCode 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:\r\n\r\n```js\r\nert(req, '/foo/bar/[:x || \"default-x\"]')\r\n```\r\n\r\n### Shortucts\r\n\r\nThere are characters that are shortucts, the defaults of these are:\r\n\r\n```js\r\nexports.shortcutMap = {\r\n  ':': 'req.params',\r\n  '$': 'req.query',\r\n  '@': 'req.body'\r\n};\r\n```\r\n\r\nThese can be used directly like:\r\n\r\n```js\r\nert(req, '/foo/bar/:x')\r\n```\r\n\r\nwhich is equivallent to:\r\n\r\n```js\r\nert(req, '/foo/bar/[req.params && req.params[\"x\"]]')\r\n```\r\n\r\n## API\r\n\r\n### ert(req, src) or ert.translate(req, src)\r\n\r\nTransforms the string with `req` and returns the resulting string.  It caches the compiled function so should be pretty good for performance.\r\n\r\n### ert.compile(src)\r\n\r\nCompiles `src` and returns a JavaScript expression as a string.  This can be used to generate client side code with something like:\r\n\r\n```js\r\nfunction client(name) {\r\n  return 'function name(req){return ' + ert.compile(src) + '}';\r\n}\r\n```\r\n\r\n### ert.compileFn(src)\r\n\r\nCompiles `src` and returns a function which expects a single argument, `request`.\r\n\r\n## License\r\n\r\nMIT\r\n","readmeFilename":"README.md","_id":"ert@1.0.0","dist":{"shasum":"087b2fc8b07c41d77b8d1026f40c6c408ccc0e3d","tarball":"https://registry.npmjs.org/ert/-/ert-1.0.0.tgz","integrity":"sha512-xM1PpdSb22VrSILu7jHAh4wPo7Y72s7ODEWOHRWiWrdcsEdyeE3PCA02Phum/qaqSMRgoSGFWcdR6wKn43NW/w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCWaAKC7gWu3bPVb3Nnd9vc8q0/928YeRRYDme2AQ1FcQIhAOAoCN4fCUh9xxByDFc3zepbLu+IiCnOfdJoJ1rMaFlM"}]},"_from":".","_npmVersion":"1.2.10","_npmUser":{"name":"forbeslindesay","email":"forbes@lindesay.co.uk"},"maintainers":[{"name":"forbeslindesay","email":"forbes@lindesay.co.uk"}]},"1.0.1":{"name":"ert","version":"1.0.1","description":"Express routing templates provides a simple micro-templating syntax for building strings from a template and a `request` object.","main":"index.js","scripts":{"test":"node test"},"repository":{"type":"git","url":"https://github.com/ForbesLindesay/ert.git"},"keywords":["express","routing","template","redirect","expression"],"author":{"name":"ForbesLindesay"},"license":"MIT","dependencies":{"character-parser":"~1.0.0"},"readme":"# ert\r\n\r\nExpress routing templates provides a simple micro-templating syntax for building strings from a template and a `request` object.\r\n\r\n[![Build Status](https://travis-ci.org/ForbesLindesay/ert.png?branch=master)](https://travis-ci.org/ForbesLindesay/ert)\r\n[![Dependency Status](https://gemnasium.com/ForbesLindesay/ert.png)](https://gemnasium.com/ForbesLindesay/ert)\r\n\r\n## Installation\r\n\r\n    $ npm install ert\r\n\r\n## Usage\r\n\r\n```js\r\nvar ert = require('ert');\r\nvar express = require('express');\r\nvar app = express();\r\n\r\napp.get('/:package', function (req, res) {\r\n  res.redirect(ert(req, '/package/:package'));\r\n});\r\n\r\napp.listen(3000);\r\n```\r\n\r\n## Syntax\r\n\r\n### Code Blocks\r\n\r\ne.g.\r\n\r\n```js\r\nert(req, '/foo/bar/[req.parms.x || \"default-x\"]')\r\n```\r\n\r\nCode 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:\r\n\r\n```js\r\nert(req, '/foo/bar/[:x || \"default-x\"]')\r\n```\r\n\r\n### Shortucts\r\n\r\nThere are characters that are shortucts, the defaults of these are:\r\n\r\n```js\r\nexports.shortcutMap = {\r\n  ':': 'req.params',\r\n  '$': 'req.query',\r\n  '@': 'req.body'\r\n};\r\n```\r\n\r\nThese can be used directly like:\r\n\r\n```js\r\nert(req, '/foo/bar/:x')\r\n```\r\n\r\nwhich is equivallent to:\r\n\r\n```js\r\nert(req, '/foo/bar/[req.params && req.params[\"x\"]]')\r\n```\r\n\r\n## API\r\n\r\n### ert(req, src) or ert.translate(req, src)\r\n\r\nTransforms the string with `req` and returns the resulting string.  It caches the compiled function so should be pretty good for performance.\r\n\r\n### ert.compile(src)\r\n\r\nCompiles `src` and returns a JavaScript expression as a string.  This can be used to generate client side code with something like:\r\n\r\n```js\r\nfunction client(name) {\r\n  return 'function name(req){return ' + ert.compile(src) + '}';\r\n}\r\n```\r\n\r\n### ert.compileFn(src)\r\n\r\nCompiles `src` and returns a function which expects a single argument, `request`.\r\n\r\n## License\r\n\r\nMIT\r\n","readmeFilename":"README.md","_id":"ert@1.0.1","dist":{"shasum":"20043c748d6783b5f6b8359163892ef310938094","tarball":"https://registry.npmjs.org/ert/-/ert-1.0.1.tgz","integrity":"sha512-boNmnWh7BiX1IV6bvetuEnr2HVHJlYmTlKT1S+TG3tb2DFGkWcytgCuHIWW5g/MEODHYMoLPN/42iWHEcliryQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCMGFU5Cmg1yoh7dLd8ayz6G3bAdtQnEeMjioyqet2dBgIhALYtexzxstFve4pzzrOuKnWKzB6ITuZw8QEcS1oE62cc"}]},"_from":".","_npmVersion":"1.2.10","_npmUser":{"name":"forbeslindesay","email":"forbes@lindesay.co.uk"},"maintainers":[{"name":"forbeslindesay","email":"forbes@lindesay.co.uk"}]}},"readme":"# ert\r\n\r\nExpress routing templates provides a simple micro-templating syntax for building strings from a template and a `request` object.\r\n\r\n[![Build Status](https://travis-ci.org/ForbesLindesay/ert.png?branch=master)](https://travis-ci.org/ForbesLindesay/ert)\r\n[![Dependency Status](https://gemnasium.com/ForbesLindesay/ert.png)](https://gemnasium.com/ForbesLindesay/ert)\r\n\r\n## Installation\r\n\r\n    $ npm install ert\r\n\r\n## Usage\r\n\r\n```js\r\nvar ert = require('ert');\r\nvar express = require('express');\r\nvar app = express();\r\n\r\napp.get('/:package', function (req, res) {\r\n  res.redirect(ert(req, '/package/:package'));\r\n});\r\n\r\napp.listen(3000);\r\n```\r\n\r\n## Syntax\r\n\r\n### Code Blocks\r\n\r\ne.g.\r\n\r\n```js\r\nert(req, '/foo/bar/[req.parms.x || \"default-x\"]')\r\n```\r\n\r\nCode 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:\r\n\r\n```js\r\nert(req, '/foo/bar/[:x || \"default-x\"]')\r\n```\r\n\r\n### Shortucts\r\n\r\nThere are characters that are shortucts, the defaults of these are:\r\n\r\n```js\r\nexports.shortcutMap = {\r\n  ':': 'req.params',\r\n  '$': 'req.query',\r\n  '@': 'req.body'\r\n};\r\n```\r\n\r\nThese can be used directly like:\r\n\r\n```js\r\nert(req, '/foo/bar/:x')\r\n```\r\n\r\nwhich is equivallent to:\r\n\r\n```js\r\nert(req, '/foo/bar/[req.params && req.params[\"x\"]]')\r\n```\r\n\r\n## API\r\n\r\n### ert(req, src) or ert.translate(req, src)\r\n\r\nTransforms the string with `req` and returns the resulting string.  It caches the compiled function so should be pretty good for performance.\r\n\r\n### ert.compile(src)\r\n\r\nCompiles `src` and returns a JavaScript expression as a string.  This can be used to generate client side code with something like:\r\n\r\n```js\r\nfunction client(name) {\r\n  return 'function name(req){return ' + ert.compile(src) + '}';\r\n}\r\n```\r\n\r\n### ert.compileFn(src)\r\n\r\nCompiles `src` and returns a function which expects a single argument, `request`.\r\n\r\n## License\r\n\r\nMIT\r\n","maintainers":[{"name":"forbeslindesay","email":"forbes@lindesay.co.uk"}],"time":{"modified":"2022-06-17T08:32:34.925Z","created":"2013-04-25T18:40:45.684Z","1.0.0":"2013-04-25T18:40:48.279Z","1.0.1":"2013-05-13T19:40:54.448Z"},"author":{"name":"ForbesLindesay"},"repository":{"type":"git","url":"https://github.com/ForbesLindesay/ert.git"}}