Created
May 20, 2018 15:55
-
-
Save ryanlaws/81d26b67d4295677026a7b65bd2fa1c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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