
Security News
New React Server Components Vulnerabilities: DoS and Source Code Exposure
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.
Simple templates for node programs.
vmplate templates depend on the vm module to create a reusable template context. They're great for command-line programs or templating files, but they don't do any escaping and they won't work in the browser, so they're a bad choice for HTML.
$ npm install vmplate
var vmplate = require('vmplate');
var render = vmplate('hello <%= name %>!')
console.log(render({ name: 'world' })); // hello world!
Compiles a new vmplate function for string.
If you pass in a locals hash, this will be used as the render function's locals hash. Otherwise, it's an empty hash that you can modify after the fact.
var render = vmplate('hello <%= name %>!', { name: 'world' });
console.log(render()); // hello world!
console.log(render({ name: 'beer' })); // hello beer!
render.locals.name = 'nasty';
console.log(render()); // hello nasty!
If you provide a filename, it will be used as the filename of the vm script and only really shows up in error messages.
vmplate uses ejs-style delimiters, but there are only two supported operations.
<%= foo %> (note the =) will add the value of foo to the buffer. The program will throw if foo is not defined.
<% var foo = "bar"; %> will evaluate the expression but will not add it to the buffer. This makes any expression that's also valid javascript usable in your template.
For example, here's how to iterate over an array:
var render = subject('<% for(var i = 0; i < arr.length; i++){ %><%= arr[i] %><% } %>');
console.log(render({ arr: [1, 2, 3] })); // 123
The program will throw if there is a syntax error in your javascript.
There are four ways to provide locals to your vmplate:
The locals hash on vmplate itself:
var vmplate = require('vmplate');
var render = vmplate('<%= foo %>');
vmplate.locals.foo = 'yay';
console.log(render()); // yay
The locals hash on the vmplate instance:
var render = vmplate('<%= foo %>');
render.locals.foo = 'yay';
console.log(render()); // yay
The locals hash passed to the vmplate factory:
var render = vmplate('<%= foo %>', { foo: 'yay' });
console.log(render()); // yay
Or the locals hash passed to the render function:
var render = vmplate('<%= foo %>');
console.log(render({ foo: 'yay' })); // yay
Render locals inherit from instance locals, which in turn inherit from the vmplate factory locals.
FAQs
Simple templates for node programs
We found that vmplate 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
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.

Security News
GitHub has revoked npm classic tokens for publishing; maintainers must migrate, but OpenJS warns OIDC trusted publishing still has risky gaps for critical projects.