Elegant way to generate string from tagged template?
curvedmark at gmail.com
Mon Dec 22 22:55:57 PST 2014
When a template is passed to a function, what’s the quickest way to return a string with additional arguments being interpolated into the template?
In this case`minify` will return the minified html, but what’s the quickest way to get the unminified string interpolated from the template? What I can think of is to loop over the additional arguments, and interspersedly join the elements in template object with the arguments, and then append the dangling element in template object. Sounds very tedious. Does es6 have an array method to ease this transformation?
What such method does basically, should be the following:
Given an array of [1,2,3] and other array of [“a”,”b”], it should return [1,”a”,2,“b”,3]. (probably a lot of edge cases to cover, but just ignore them for now).
But maybe I overthink this? Is there already an easy way to do this?
More information about the es-discuss