New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

tiny-template-engine

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tiny-template-engine

a weak template engine, and we can use it to render some simple text;

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

Tiny template engine

a weak template engine, and we can use it to render some simple text 😆

only use for study! 😅

tmplate expression

support get var:

    <p>{{data}}</p>

support js expression in html, for example to render an array list:

<ul>
    {% [1,2,3,4].forEach((item) => {%}
        {% if(item === 1 || item === 3) { %}
            {% return %}
        {% } else { %}
            <li>{{item}}</li>
        {% } %}
    {% }) %}
</ul>

use example:

const { readFileSync } = require('fs');
const { resolve } = require('path');
const { render } = require('src/index.js');
const http = require('http');
const mime = require('mime');

http.createServer(function (request, response) {
    const tmplPath = resolve(__dirname, '/src/tmpl.html');
    const tmpl = readFileSync(tmplPath, 'utf8');
    const data = { arr: [1, 2, 3, 4] };
    response.writeHead(200, { 'Content-Type': mime.getType(tmplPath) });
    response.end(render(tmpl, data));
}).listen(8081);

console.log('Server running at http://127.0.0.1:8081/');

FAQs

Package last updated on 27 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts