{"id":3694,"date":"2023-01-31T10:36:37","date_gmt":"2023-01-31T16:36:37","guid":{"rendered":"https:\/\/bililite.com\/blog\/?p=3694"},"modified":"2023-01-31T10:36:37","modified_gmt":"2023-01-31T16:36:37","slug":"using-tagged-template-literals-revisted","status":"publish","type":"post","link":"https:\/\/bililite.com\/blog\/2023\/01\/31\/using-tagged-template-literals-revisted\/","title":{"rendered":"Using tagged template literals, revisted"},"content":{"rendered":"<p>I thought I had a clever way of using <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Template_literals\">tagged template literals<\/a> with <a href=\"https:\/\/bililite.com\/blog\/2022\/09\/09\/using-tagged-template-literals\/\">Array.prototype.reduce<\/a>, but it turns out that <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/String\/raw\">String.raw<\/a> does this already.<\/p>\n<p>So my <code>template<\/code> function should be:<\/p>\n<pre><code class=\"language-javascript\" >function template(strings, ...keys) {\r\n  return (data) => String.raw( {raw: strings, ...keys.map (key => data[key]) );\r\n}<\/code><\/pre>\n<p>Which is much simpler<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I thought I had a clever way of using tagged template literals with Array.prototype.reduce, but it turns out that String.raw does this already. So my template function should be: function template(strings, ...keys) { return (data) => String.raw( {raw: strings, ...keys.map (key => data[key]) ); } Which is much simpler<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"_links":{"self":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts\/3694"}],"collection":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/comments?post=3694"}],"version-history":[{"count":2,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts\/3694\/revisions"}],"predecessor-version":[{"id":3696,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts\/3694\/revisions\/3696"}],"wp:attachment":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/media?parent=3694"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/categories?post=3694"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/tags?post=3694"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}