Created
January 7, 2021 18:10
-
-
Save nasser/6a33fe2cad266c45c55bc8fa819209ec to your computer and use it in GitHub Desktop.
Flat template rendering in node.js in two lines of code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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