![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
leopard-template
Advanced tools
A simple HTML template engine, currently a parser. Basically implements ejs syntax.
You can simply run the examples here with
$ npm run serve:examples
var Leopard = require('leopard-template')
var leo = new Leopard()
var tpl = '<p>I am <%= name %>!</p>'
var data = {
name: 'Leopard'
}
var html = leo.compile(tpl, data) // '<p>I am Leopard!</p>'
Or just render a file:
var path = require('path')
var app = require('connect')()
var Leopard = require('leopard-template')
var leo = new Leopard()
app.use('/test', function(req, res) {
leo.compileFile(
path.resolve(__dirname, './test.tpl'),
data,
function(err, html) {
req.write(html, 'utf-8')
req.end()
})
})
Install leopard-template via npm
$ npm install leopard-template
Then import leopard-template in whatever way you want
// ES6 import
import Leopard from 'leopard-template'
// CommonJS require
var Leopard = require('leopard-template')
// and then you can start render your templates
// var leo = new Leopard()
Or load it with html script
tag
<script src="./node_modules/leopard-template/dist/leopard.browser.min.js"></script>
Note:
compileFile
is only available at server side, so we build two versions, if you want to use Leopard directly in browsers, useleopard.browser.js
, otherwise you'll have to useleopard.server.js
.
var leo = new Leopard(config)
Leopard simply implements ejs syntax.
Wrap statements like for
or if
in <% ... %>
, expressions in <%= ... %>
, and raw HTML in <%- ... %>
var data = {
name: 'Leopard'
}
var text = '<p>I am <%= name %>!</p>'
var data = {
name: '<em>Leopard</em>'
}
var text = '<p>I am <%- name %>!</p>'
var data = {
isOk: false,
nickname: 'leo',
realname: 'leopard'
}
var conditions_1 = '<p>I am Leopard<%= \', AKA \' + (isOk ? nickname : realname) + \'!\' %></p>'
var conditions_2 = '<% if (isOk) { %>' +
'<span class=\"nickname\"><%= nickname %></span>' +
'<% } else { %>' +
'<span class=\"realname\"><%= realname %></span>' +
'<% } %>'
var loops = 'Now I repeat: ' +
'<ul>' +
'<% for (var i = 0; i < 3; i++) { %>' +
'<li>I am Leopard!</li>' +
'<% } %>' +
'</ul>'
Filters are now supported in Leopard, you can customize a filter with Leopard.filter
:
var Leopard = require('leopard-template')
Leopard.filter('toUpperCase', function(string) {
return string.toUpperCase()
})
var text = '<p><%= 'leopard' | toUpperCase %></p>' // <p>LEOPARD</p>
And also, filters can be chained:
// `reverse` is a preset filter
var text = '<p><%= 'leopard' | toUpperCase | reverse %></p>' // <p>DRAPOEL</p>
$ npm run test
FAQs
a simple HTML template engine
We found that leopard-template demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.