template string

PHOTO EMBED

Mon Jan 11 2021 06:22:04 GMT+0000 (Coordinated Universal Time)

Saved by @salitha.pathi #typescript #mongoshell

String.prototype.interpolate = function(params) {
  const names = Object.keys(params);
  const vals = Object.values(params);
  return new Function(...names, `return \`${this}\`;`)(...vals);
}

const template = 'Example text: ${text}';
const result = template.interpolate({
  text: 'Foo Boo'
});
console.log(result);
content_copyCOPY