Skip to content

Instantly share code, notes, and snippets.

@nasser
Created January 7, 2021 18:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nasser/6a33fe2cad266c45c55bc8fa819209ec to your computer and use it in GitHub Desktop.
Save nasser/6a33fe2cad266c45c55bc8fa819209ec to your computer and use it in GitHub Desktop.
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'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment