Skip to content

Instantly share code, notes, and snippets.

@jgermade
Last active January 19, 2017 23:57
Show Gist options
  • Save jgermade/fc7aaee0f5868491eebda06019aff2ce to your computer and use it in GitHub Desktop.
Save jgermade/fc7aaee0f5868491eebda06019aff2ce to your computer and use it in GitHub Desktop.
function compileMessage (message) {
return new Function('obj', 'with(obj){ return \'' +
message.replace(/\n/g, '\\n').split(/{{([^{}]+)}}/g).map(function (expression, i) {
return i%2 ? ( '\'+(' + expression.trim() + ')+\'' ) : expression;
}).join('') +
'\'; }');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment