Skip to content

Instantly share code, notes, and snippets.

View panr's full-sized avatar
🤔
Boy, I hate being right all the time...

Radek Kozieł panr

🤔
Boy, I hate being right all the time...
View GitHub Profile
@nasser
nasser / render.js
Created January 7, 2021 18:10
Flat template rendering in node.js in two lines of code
const render = (template, values) =>
template.replace(/\{\{([^}]+)\}\}/g, (_, key) => values[key]);
render("hello {{place}}", { place: "world" })
// => "hello world"
render("shell='{{SHELL}}', term='{{TERM}}'", process.env)
// => "shell='/bin/bash', term='xterm-256color'"