{"_id":"@amundsan/literal-engine","_rev":"9-e6bef8a6dcda3de678017ebf7c3a63ea","name":"@amundsan/literal-engine","dist-tags":{"latest":"0.10.7"},"versions":{"0.9.0":{"name":"@amundsan/literal-engine","version":"0.9.0","description":"Node template engine based on template literals, with no dependencies.","keywords":[],"type":"module","main":"index.js","engine":{"node":">=20.1"},"scripts":{"test":"mocha","dev":"mocha --watch --parallel --reporter min"},"repository":{"type":"git","url":"git+https://github.com/Amund/literal-engine.git"},"author":{"name":"Dimitri Avenel"},"license":"MIT","bugs":{"url":"https://github.com/Amund/literal-engine/issues"},"homepage":"https://github.com/Amund/literal-engine#readme","devDependencies":{"mocha":"^10.2.0"},"_id":"@amundsan/literal-engine@0.9.0","gitHead":"44164dc926aeb951b9a41aa8fb1bc7c374e3ca99","_nodeVersion":"20.10.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-GXDWE1QtU3nTmtywpZIgHEFY1NnjN22QtHzZag7JAMIgPScNpxXJhWzULUTJy+u/v1lN4ewuLT8WI87XKlXEcw==","shasum":"2f8e0ef6fc1bc812fd3c1fe1afa5bd2788767d80","tarball":"https://registry.npmjs.org/@amundsan/literal-engine/-/literal-engine-0.9.0.tgz","fileCount":4,"unpackedSize":4390,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDRYc+EfuiFcNz8Una4BJJTujt/wOt/NZIKvbFyqY2T2AiEAjIO9ZFjeQHe9A5NBeFRXgsZAP0JwTYsySjO1eKHjm5w="}]},"_npmUser":{"name":"amundsan","email":"mailamund@gmail.com"},"directories":{},"maintainers":[{"name":"amundsan","email":"mailamund@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/literal-engine_0.9.0_1707220231296_0.9322850362560924"},"_hasShrinkwrap":false},"0.9.1":{"name":"@amundsan/literal-engine","version":"0.9.1","description":"Node template engine based on template literals, with no dependencies.","keywords":[],"type":"module","main":"index.js","engine":{"node":">=20.1"},"scripts":{"test":"mocha","dev":"mocha --watch --parallel --reporter min"},"repository":{"type":"git","url":"git+https://github.com/Amund/literal-engine.git"},"author":{"name":"Dimitri Avenel"},"license":"MIT","bugs":{"url":"https://github.com/Amund/literal-engine/issues"},"homepage":"https://github.com/Amund/literal-engine#readme","devDependencies":{"mocha":"^10.2.0"},"_id":"@amundsan/literal-engine@0.9.1","gitHead":"ca173d6e016409b33d1a7a68e3b6caea7629ed65","_nodeVersion":"20.10.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-d9RQctWnLgLWhxapA/RGDXVo8wS3UiI1dOoaFyEZTIzunjrJWFPxOJksZVLRph7kHb3jJSJQQ7st1d9SXVVt1g==","shasum":"2af3adb6e6fa5714a4f01fe66d18661fc97f1dc5","tarball":"https://registry.npmjs.org/@amundsan/literal-engine/-/literal-engine-0.9.1.tgz","fileCount":4,"unpackedSize":4531,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAY8C/qRpgMfyyzjkdSNY7GT0XHpVs4kglhUDMKOP0NMAiBdP2bRhgb6ifnVJvyPrGyYndGc30ajivD1dWAHDS0xDQ=="}]},"_npmUser":{"name":"amundsan","email":"mailamund@gmail.com"},"directories":{},"maintainers":[{"name":"amundsan","email":"mailamund@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/literal-engine_0.9.1_1707222779979_0.31381470977104287"},"_hasShrinkwrap":false},"0.10.0":{"name":"@amundsan/literal-engine","version":"0.10.0","description":"Node template engine based on template literals, with no dependencies.","keywords":["template","literal","engine"],"type":"module","main":"index.js","engine":{"node":">=20.1"},"scripts":{"test":"mocha","test-watch":"mocha --watch --parallel --reporter min"},"repository":{"type":"git","url":"git+https://github.com/Amund/literal-engine.git"},"author":{"name":"Dimitri Avenel"},"license":"MIT","bugs":{"url":"https://github.com/Amund/literal-engine/issues"},"homepage":"https://github.com/Amund/literal-engine#readme","devDependencies":{"mocha":"^10.2.0"},"_id":"@amundsan/literal-engine@0.10.0","gitHead":"52c9a7f94dcf7413e54892dd155f99830a009b12","_nodeVersion":"20.10.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-zpul/GA/fSNwfQt5ifVpzg6x3i6AI4mq17r62L+D9sfOYvI7I4qZYXbLHqMJvfkftwr73u1YdAm0ht2wxhtw/Q==","shasum":"8b949f005bb87ce5883413c1d5c5c71299785333","tarball":"https://registry.npmjs.org/@amundsan/literal-engine/-/literal-engine-0.10.0.tgz","fileCount":4,"unpackedSize":7959,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEqRlM+hgKYCXYNRpuudtKcm+R7bj1SDqrE5LnwJzQubAiB/KPMr3474r+fgG8/jQ2CnNabAs6sJlBY+pqUczVZAGw=="}]},"_npmUser":{"name":"amundsan","email":"mailamund@gmail.com"},"directories":{},"maintainers":[{"name":"amundsan","email":"mailamund@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/literal-engine_0.10.0_1707435157312_0.098245964033705"},"_hasShrinkwrap":false},"0.10.1":{"name":"@amundsan/literal-engine","version":"0.10.1","description":"Node template engine based on template literals, with no dependencies.","keywords":["template","literal","engine"],"type":"module","main":"index.js","engine":{"node":">=20.1"},"scripts":{"test":"mocha","test-watch":"mocha --watch --parallel --reporter min"},"repository":{"type":"git","url":"git+https://github.com/Amund/literal-engine.git"},"author":{"name":"Dimitri Avenel"},"license":"MIT","bugs":{"url":"https://github.com/Amund/literal-engine/issues"},"homepage":"https://github.com/Amund/literal-engine#readme","devDependencies":{"mocha":"^10.2.0"},"_id":"@amundsan/literal-engine@0.10.1","gitHead":"89fa70257acda9874e11b34c4215e2ed82024ed4","_nodeVersion":"20.10.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-Zze/8zFQ4OZK2Pacw3zgvChCl8wNaW2LM1i2sXvtPpBQqh2X+yVBxF+Rbgmm32OnV0Wk35tp7xnTnML9IRIIjw==","shasum":"1400143abdbcead4f37dcf718d92aac4fd4d653f","tarball":"https://registry.npmjs.org/@amundsan/literal-engine/-/literal-engine-0.10.1.tgz","fileCount":4,"unpackedSize":9341,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIA3YCqcd3fQE4KaJAQVXl9T98lgSVP4C8N3BJi5nqe2CAiEAxx4wmbSCcsGuS/O8zChugydRlnNwQ0fY+1SPPysKwLk="}]},"_npmUser":{"name":"amundsan","email":"mailamund@gmail.com"},"directories":{},"maintainers":[{"name":"amundsan","email":"mailamund@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/literal-engine_0.10.1_1707520062435_0.5537815070768781"},"_hasShrinkwrap":false},"0.10.2":{"name":"@amundsan/literal-engine","version":"0.10.2","description":"Node template engine based on template literals, with no dependencies.","keywords":["template","literal","engine"],"type":"module","main":"index.js","engine":{"node":">=20.1"},"scripts":{"test":"mocha","test-watch":"mocha --watch --parallel --reporter min"},"repository":{"type":"git","url":"git+https://github.com/Amund/literal-engine.git"},"author":{"name":"Dimitri Avenel"},"license":"MIT","bugs":{"url":"https://github.com/Amund/literal-engine/issues"},"homepage":"https://github.com/Amund/literal-engine#readme","devDependencies":{"mocha":"^10.2.0"},"_id":"@amundsan/literal-engine@0.10.2","gitHead":"3948f10edacf519a03db3c4c6e4b99f2d4b71fea","_nodeVersion":"20.10.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-sqWtIQKofbh4Y08mOvwJqhIphwm+a8e/H2NVgJllxjfX2iB8BvTPmZMxo9p0bLw13cXIDWnFlhkdKvFHvbMvZw==","shasum":"7a023426ca11dcfb35125487fe138354cd95215d","tarball":"https://registry.npmjs.org/@amundsan/literal-engine/-/literal-engine-0.10.2.tgz","fileCount":4,"unpackedSize":11237,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEp7U1v8BRTXWrGF8ZFz+w6J4SssKJR2yNm8BrelTr3nAiEA8SlT5MVX0YQMlFHXBFzhqi5lkTneBUpQCmmufbCbz8c="}]},"_npmUser":{"name":"amundsan","email":"mailamund@gmail.com"},"directories":{},"maintainers":[{"name":"amundsan","email":"mailamund@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/literal-engine_0.10.2_1707594977534_0.7849670508674524"},"_hasShrinkwrap":false},"0.10.3":{"name":"@amundsan/literal-engine","version":"0.10.3","description":"Node template engine based on template literals, with no dependencies.","keywords":["template","literal","engine"],"type":"module","main":"index.js","engine":{"node":">=20.1"},"scripts":{"test":"mocha","test-watch":"mocha --watch --parallel --reporter min"},"repository":{"type":"git","url":"git+https://github.com/Amund/literal-engine.git"},"author":{"name":"Dimitri Avenel"},"license":"MIT","bugs":{"url":"https://github.com/Amund/literal-engine/issues"},"homepage":"https://github.com/Amund/literal-engine#readme","devDependencies":{"mocha":"^10.2.0"},"_id":"@amundsan/literal-engine@0.10.3","gitHead":"1c5407bce31ab5450778190f0ab406135e66ea10","_nodeVersion":"20.10.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-QR6CvBAmoMaoaCYVpavx5LRbxioIAiKWeIF+FCgikGkzXXmBVYDtRxPwMnygOFC9zK19XeIHLHcAFD8bNrKdHA==","shasum":"6e94fcd5bce77b70f9ccd534bd79dbd1facdd913","tarball":"https://registry.npmjs.org/@amundsan/literal-engine/-/literal-engine-0.10.3.tgz","fileCount":4,"unpackedSize":11278,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHtFakr68uq1NlpxBfSv61sd6wzxARHTwurS40P1KVCeAiAiPI4O03Zq7P8ErbnEt80y/RASgUC9dlC+QCcKF6QuOQ=="}]},"_npmUser":{"name":"amundsan","email":"mailamund@gmail.com"},"directories":{},"maintainers":[{"name":"amundsan","email":"mailamund@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/literal-engine_0.10.3_1707645136834_0.7382644717599103"},"_hasShrinkwrap":false},"0.10.4":{"name":"@amundsan/literal-engine","version":"0.10.4","description":"Node template engine based on template literals, with no dependencies.","keywords":["node","template","engine","literal","include","extend","autoescape","helpers","no-dependencies"],"type":"module","main":"index.js","engine":{"node":">=20.1"},"scripts":{"test":"mocha","test-watch":"mocha --watch --parallel --reporter min"},"repository":{"type":"git","url":"git+https://github.com/Amund/literal-engine.git"},"author":{"name":"Dimitri Avenel"},"license":"MIT","bugs":{"url":"https://github.com/Amund/literal-engine/issues"},"homepage":"https://github.com/Amund/literal-engine#readme","devDependencies":{"mocha":"^10.2.0"},"_id":"@amundsan/literal-engine@0.10.4","gitHead":"61bcaf28224dc8710e42111aec47e959620e9e4e","_nodeVersion":"20.10.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-mnbquFpw80fUwvl4KwcjFt37/GBQ1hktxB+GVlieOcKrcZYfSCB7DOiljhG1T21pm61emlKKFupJNAzttihtlA==","shasum":"669fc178fcbebac7b466c26260d3d29833d609e0","tarball":"https://registry.npmjs.org/@amundsan/literal-engine/-/literal-engine-0.10.4.tgz","fileCount":4,"unpackedSize":11399,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCeXweel0gfdNrGUSQIgCDoOxJUJhokmfD8riLFERSq/AIhAOH4uRx9bxYLR9Pcj/VtdtnHu37KsKvkLxgUm9tOqzLf"}]},"_npmUser":{"name":"amundsan","email":"mailamund@gmail.com"},"directories":{},"maintainers":[{"name":"amundsan","email":"mailamund@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/literal-engine_0.10.4_1707645568916_0.854592437387167"},"_hasShrinkwrap":false},"0.10.5":{"name":"@amundsan/literal-engine","version":"0.10.5","description":"Node template engine based on template literals, with no dependencies.","keywords":["node","template","engine","literal","include","extend","autoescape","helpers","no-dependencies"],"type":"module","main":"index.js","engine":{"node":">=20.1"},"scripts":{"test":"mocha","test-watch":"mocha --watch --parallel --reporter min"},"repository":{"type":"git","url":"git+https://github.com/Amund/literal-engine.git"},"author":{"name":"Dimitri Avenel"},"license":"MIT","bugs":{"url":"https://github.com/Amund/literal-engine/issues"},"homepage":"https://github.com/Amund/literal-engine#readme","devDependencies":{"mocha":"^10.2.0"},"_id":"@amundsan/literal-engine@0.10.5","gitHead":"23786d56bc1a5216b3503316485f0f57ccdcb95f","_nodeVersion":"20.10.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-+ZYYE2mo8Qw920NwBjdGUarWQaIDOImeH6sWJ1bnZlj9yU4YYxgwLp2+YQvQ2YTJ3HvyOOqroTMz0X1CBEa69g==","shasum":"789d026daf0dbf3c41cb7295fe15a779f38b8c3a","tarball":"https://registry.npmjs.org/@amundsan/literal-engine/-/literal-engine-0.10.5.tgz","fileCount":4,"unpackedSize":12856,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGPImo1BcVMoKx6LimvoK4jUE3Qz/oQlcOp9zm+DoNbzAiEA3nbOSSjhWXGanhUPTWwySL+q9EWA46MUnLTx8lKHqmM="}]},"_npmUser":{"name":"amundsan","email":"mailamund@gmail.com"},"directories":{},"maintainers":[{"name":"amundsan","email":"mailamund@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/literal-engine_0.10.5_1707652625603_0.5944089378793169"},"_hasShrinkwrap":false},"0.10.6":{"name":"@amundsan/literal-engine","version":"0.10.6","description":"Node template engine based on template literals, with no dependencies.","keywords":["node","template","engine","literal","include","extend","autoescape","helpers","no-dependencies"],"type":"module","main":"index.js","engine":{"node":">=20.1"},"scripts":{"test":"mocha","test-watch":"mocha --watch --parallel --reporter min"},"repository":{"type":"git","url":"git+https://github.com/Amund/literal-engine.git"},"author":{"name":"Dimitri Avenel"},"license":"MIT","bugs":{"url":"https://github.com/Amund/literal-engine/issues"},"homepage":"https://github.com/Amund/literal-engine#readme","devDependencies":{"mocha":"^10.2.0"},"_id":"@amundsan/literal-engine@0.10.6","gitHead":"4ecee40e5f0a2fa7f72e575f6d2c659874bb772c","_nodeVersion":"20.10.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-1teO9i0b41h+FPWTvYpAU5ctVHZp19PIb5ydaNvfgovcdeEwjf8dvqDP7oMHoaXGJzKnMSowyn8PRbmZ6OYumw==","shasum":"71710cc62a0340f1f9bee538402ec29f138d9f6f","tarball":"https://registry.npmjs.org/@amundsan/literal-engine/-/literal-engine-0.10.6.tgz","fileCount":4,"unpackedSize":14092,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIChneIfvyQ8lhRqT11h59uib90T7PeGlEyVJA5M97ikJAiB0f+l/BRldF+mybp0SXWSpXko15W6dAMDvae186pfqXQ=="}]},"_npmUser":{"name":"amundsan","email":"mailamund@gmail.com"},"directories":{},"maintainers":[{"name":"amundsan","email":"mailamund@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/literal-engine_0.10.6_1707654848125_0.14571313455658363"},"_hasShrinkwrap":false},"0.10.7":{"name":"@amundsan/literal-engine","version":"0.10.7","description":"Node template engine based on template literals, with no dependencies.","keywords":["node","template","engine","literal","include","extend","autoescape","helpers","no-dependencies"],"type":"module","main":"index.js","engine":{"node":">=20.1"},"scripts":{"test":"mocha","test-watch":"mocha --watch --parallel --reporter min"},"repository":{"type":"git","url":"git+https://github.com/Amund/literal-engine.git"},"author":{"name":"Dimitri Avenel"},"license":"MIT","bugs":{"url":"https://github.com/Amund/literal-engine/issues"},"homepage":"https://github.com/Amund/literal-engine#readme","devDependencies":{"mocha":"^10.2.0"},"_id":"@amundsan/literal-engine@0.10.7","gitHead":"8971374aac1af361c644d69ab8cecca41099c75e","_nodeVersion":"20.10.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-MVmD2cT8Fw3/w5Thl/GzOnHAXfw1hxJ3wd09rXQFuc3fEGUhG+pZODiWx8LOe9SlpUA+V7dsU21LirjVOchAFA==","shasum":"d002ba2c8a957bc04b723ee124025ddb70efec02","tarball":"https://registry.npmjs.org/@amundsan/literal-engine/-/literal-engine-0.10.7.tgz","fileCount":4,"unpackedSize":14030,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHQUbRxGypSFtMk4Rv4yddnvPCHzsXEZRU7Tg/yRzbJ5AiAV0IHgfAuC+o6Fdn5zctDWUlzxBMxesaMw26qx0pZC4g=="}]},"_npmUser":{"name":"amundsan","email":"mailamund@gmail.com"},"directories":{},"maintainers":[{"name":"amundsan","email":"mailamund@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/literal-engine_0.10.7_1707655112182_0.3942242188486007"},"_hasShrinkwrap":false}},"time":{"created":"2024-02-06T11:50:31.203Z","0.9.0":"2024-02-06T11:50:31.430Z","modified":"2024-02-11T12:38:32.517Z","0.9.1":"2024-02-06T12:33:00.136Z","0.10.0":"2024-02-08T23:32:37.477Z","0.10.1":"2024-02-09T23:07:42.590Z","0.10.2":"2024-02-10T19:56:17.697Z","0.10.3":"2024-02-11T09:52:17.000Z","0.10.4":"2024-02-11T09:59:29.048Z","0.10.5":"2024-02-11T11:57:05.742Z","0.10.6":"2024-02-11T12:34:08.282Z","0.10.7":"2024-02-11T12:38:32.333Z"},"maintainers":[{"name":"amundsan","email":"mailamund@gmail.com"}],"description":"Node template engine based on template literals, with no dependencies.","homepage":"https://github.com/Amund/literal-engine#readme","keywords":["node","template","engine","literal","include","extend","autoescape","helpers","no-dependencies"],"repository":{"type":"git","url":"git+https://github.com/Amund/literal-engine.git"},"author":{"name":"Dimitri Avenel"},"bugs":{"url":"https://github.com/Amund/literal-engine/issues"},"license":"MIT","readme":"# literal-engine\n\nNode template engine based on template literals, with no dependencies.\n\n-   No custom syntax, just template literals (or template strings), `${...}`\n-   Support for include\n-   Support for extend\n-   Autoescaping by default (locally or globally deactivatable)\n-   Builtin template helpers (include, escape)\n-   Support adding custom template helpers\n-   [TODO] Benchmark\n\n## Install\n\n```\n$ npm i @amundsan/literal-engine\n```\n\n## Import\n\n```js\nimport Engine from '@amundsan/literal-engine'\n```\n\n## Usage\n\n### Templates from strings\n\nAll templates in literal-engine must be registered before using them. String-based template are registered with the `template(name,str)` method, then compiled with `render(name, data, extend)`\n\n```js\nconst engine = new Engine()\nengine.template('test', 'Hello ${who}')\nconsole.log(engine.render('test', { who: 'world' }))\n// => 'Hello world'\n\nengine.template('test2', '${what} ${who}!')\nconsole.log(\n    engine.render('test2', { what: 'Hello', who: 'world' }),\n    engine.render('test2', { what: 'Hi', who: 'universe' })\n)\n// => 'Hello world!' 'Hi universe!'\n```\n\n### Templates from files\n\nAll files-based templates must be loaded with `prepare()` method, which load them recursively from root folder, and store them in the templates registry, as strings. The name used to store, and to recall when rendering, is the path of the file relative to its root folder, and without its extension (`html` by default). `prepare()` is the only promised method in the api.\n\n```html\n<!-- page.html -->\n<body>\n    <h1>${title}</h1>\n    <p>${content}</p>\n</body>\n```\n\n```js\nconst engine = new Engine({\n    root: 'path/to/templates',\n    extension: 'html', // by default, can be omitted\n})\nawait engine.prepare()\nconsole.log(engine.render('page', { title: 'My page', content: 'My content' }))\n/*\n<body>\n    <h1>My page</h1>\n    <p>My content</p>\n</body>\n*/\n```\n\nAt any time, you can consult the list of all available templates (loaded from a file or a string) by dumping `engine.templates`, which is a plain object.\n\n### Autoescape\n\nBy default, autoescape is active. This means that all variables and expressions passed into `${...}` in templates will be automatically escaped, replacing any dangerous characters by HTML entities. This feature can be globally disabled if required, by setting the `autoescape` constructor option to false.\n\n```js\nconst engine = new Engine({ autoescape: false })\n```\n\nIf this option is **globally disabled**, you can still perform this task manually, using the \"escape\" helper in your templates.\n\n```html\n<p>${ escape('<div>') }</p>\n<!-- <p>&lt;div&gt;</p> -->\n```\n\nIf this option is **globally enabled**, you can still locally disable autoescape by placing an additional dollar sign in front of a variable: `$${...}`. This is particularly useful when using the include function, or when you want to use an extend.\n\n```html\n<p>$${ '<div>' }</p>\n<!-- <p><div></p> -->\n```\n\n### Helpers\n\nYou can make generic functions available in your templates by adding them to the list of helpers. They can also be added from the engine constructor.\n\n```js\nconst engine = new Engine({\n    helpers: {\n        oddCase: (str) =>\n            str\n                .toLowerCase()\n                .split('')\n                .map((s, i) => (i % 2 == 0 ? s.toUpperCase() : s))\n                .join(''),\n    },\n})\nengine.template('content', '<p>${ oddCase(sentence) }</p>')\nconsole.log(\n    engine.render('content', { sentence: 'Oh my God! They killed Kenny!' })\n)\n// <p>Oh mY GoD! tHeY KiLlEd kEnNy!</p>\n```\n\nYou can also add a new helper at any time using the `helper(name, func)` function.\n\n```js\nconst engine = new Engine()\nengine.helper('evenCase', (str) =>\n    str\n        .toLowerCase()\n        .split('')\n        .map((s, i) => (i % 2 != 0 ? s.toUpperCase() : s))\n        .join('')\n)\nengine.template('content', '<p>${evenCase(sentence)}</p>')\nconsole.log(\n    engine.render('content', { sentence: 'Oh my God! They killed Kenny!' })\n)\n// <p>oH My gOd! ThEy kIlLeD KeNnY!</p>\n```\n\n### Include\n\n`include` is one of the helpers functions usable inside your templates. As it sounds, it includes a template into another template. It shares its signature with the `render` method (in fact... it IS the `render` method, internally) : `include(name, data, extend)`\n\nNOTE: As autoescape is active by default, it must be deactivated when using the include function, which legitimately injects html code. This can be done using the `$${...}` syntax.\n\n```html\n<!--head.html-->\n<head>\n    <title>${title} - Blog</title>\n</head>\n```\n\n```html\n<!-- page.html -->\n<html>\n    $${ include('head', { title }) }\n    <body>\n        <h1>${title}</h1>\n        <p>${content}</p>\n    </body>\n</html>\n```\n\n```js\nconst engine = new Engine({ root: 'path/to/templates' })\nawait engine.prepare()\nconsole.log(engine.render('page', { title: 'My page', content: 'My content' }))\n/*\n<html>\n    <head>\n        <title>My page - Blog</title>\n    </head>\n    <body>\n        <h1>My page</h1>\n        <p>My content</p>\n    </body>\n</html>\n*/\n```\n\n### Extend\n\nExtending a template is the opposite of including: it \"wrap\" a template around another one. It can be done only with `include` function like this :\n\n```js\nconst data = { title: 'My page', content: 'My content' }\nengine.render('base', { ...data, extend: engine.render('page', data) })\n```\n\nBut there's a more convenient way of doing this, using the third argument of the `render` and `include` functions to specify the template to be extended. Technically, an \"extend\" template is just a regular template with a special variable `${extend}`, where child template will be injected. As with the `include` function, autoescape must be disabled with the syntax `$${extend}`.\n\n```html\n<!--base.html-->\n<body>\n    $${extend}\n</body>\n```\n\n```html\n<!-- page.html -->\n<h1>${title}</h1>\n<p>${content}</p>\n```\n\n```js\nconst engine = new Engine({ root: 'path/to/templates' })\nawait engine.prepare()\nconst data = { title: 'My page', content: 'My content' }\nconsole.log(engine.render('page', data, 'base'))\n/*\n<body>\n    <h1>My page</h1>\n    <p>My content</p>\n</body>\n*/\n```\n\n### Condition\n\nConditional display of variables can easily be done with a ternary structure.\n\n```js\nconst engine = new Engine()\nengine.template('content', '<p>${ isAlive ? \"Kenny\" : \"Ghost\" }</p>')\nconst result = engine.render('content', { isAlive: true })\n// <p>Kenny</p>\n```\n\nFor cases that are more complicated or too verbose to be written directly into the template, it is still possible to use a function, added as a helper to the engine.\n\n```js\nconst engine = new Engine({\n    helpers: {\n        showKenny: (isAlive) => (isAlive ? 'Kenny' : 'Ghost'),\n    },\n})\nengine.template('content', '<p>${ showKenny(isAlive) }</p>')\nconsole.log(engine.render('content', { isAlive: false }))\n// <p>Ghost</p>\n```\n\n### Loop\n\nAnother important point in using a model engine is the ability to loop. You can do this very simply, once again using one of javascript's native functions, `map`.\n\n```js\nconst engine = new Engine()\nengine.template('li', \"<li>${ alive ? '😐' : '🫥' } ${name}</li>\")\nengine.template('ul', '<ul>${ list.map((li)=>include(\"li\", { ...li })) }</ul>')\nconst list = [\n    { name: 'Eric Cartman', alive: true },\n    { name: 'Kyle Broflovski', alive: true },\n    { name: 'Kenny McCormick', alive: false },\n    { name: 'Stan Marsh', alive: true },\n]\nconsole.log(engine.render('ul', { list }))\n/*\n<ul>\n    <li>😐 Eric Cartman</li>\n    <li>😐 Kyle Broflovski</li>\n    <li>🫥 Kenny McCormick</li>\n    <li>😐 Stan Marsh</li>\n</ul>\n*/\n```\n\n### Debugging\n\nThere's an engine constructor option for displaying errors directly in templates during the development phase, the `debug` option, which is a boolean set to `false` by default. All templates errors are logged to `process.stderr`, but it can be more convenient to have them directly in the rendered page.\n\n```js\nconst engine = new Engine({ debug: true })\n```\n\nYou can of course `${console.log(myvar)}` in a template to dump `myvar` in server console, and see what you can do with it.\n\nBut it can be sometimes difficult to know exactly what are the variables available in a template or a sub-template, and you can't do a `console.log()` without an effective variable name. In this case, you can print a special variable, named... `${variables}`, which print a sorted and coma's separated list of actual variable names.\n\n## Credits\n\nFreely adapted from brilliants [template-literals-engine](https://github.com/ahmadnassri/node-template-literals-engine) and [escape-html](https://github.com/component/escape-html)\n","readmeFilename":"README.md"}