Skip to content

Instantly share code, notes, and snippets.

@artemdemo
Created July 1, 2016 20:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artemdemo/ae2be23fd8b92badeaf959f7de70bb42 to your computer and use it in GitHub Desktop.
Save artemdemo/ae2be23fd8b92badeaf959f7de70bb42 to your computer and use it in GitHub Desktop.
/* Nano Templates - https://github.com/trix/nano */
function nano(template, data) {
return template.replace(/\{([\w\.]*)\}/g, function(str, key) {
var keys = key.split("."), v = data[keys.shift()];
for (var i = 0, l = keys.length; i < l; i++) v = v[keys[i]];
return (typeof v !== "undefined" && v !== null) ? v : "";
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment