Skip to content

Instantly share code, notes, and snippets.

@ryanlaws
Created May 20, 2018 15:55
Show Gist options
  • Save ryanlaws/81d26b67d4295677026a7b65bd2fa1c3 to your computer and use it in GitHub Desktop.
Save ryanlaws/81d26b67d4295677026a7b65bd2fa1c3 to your computer and use it in GitHub Desktop.
// Usage:
// -----
// import html from './html-tagged-temp-lit.js'
// html`<div>${"Hello World"}</div>`
const joinIfArray = (maybeArray) =>
Array.isArray(maybeArray) ? maybeArray.join('') : maybeArray
const html = (literals, ...vars) => {
return Array.from(literals).reduce((output, literal, i) => {
if (i >= vars.length)
return output + literal
return output + literal + joinIfArray(vars[i])
}, "");
}
export default html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment