Skip to content

Instantly share code, notes, and snippets.

@protomorph
Last active October 4, 2023 01:12
Show Gist options
  • Select an option

  • Save protomorph/06e0230691ad2a2ffed908cece6fade4 to your computer and use it in GitHub Desktop.

Select an option

Save protomorph/06e0230691ad2a2ffed908cece6fade4 to your computer and use it in GitHub Desktop.
import tagged from 'tagged.js'
const css = tagged(function (str) {
const css = new CSSStyleSheet()
return css.replace(str.trim())
})
export default css
import tagged from 'tagged.js'
const html = tagged(function (str) {
const fragment = document.createRange()
return fragment.createContextualFragment(str.trim())
})
export default html
// https://github.com/ryanmorr/tagged
export default function tagged (callback, mutator = val => val) {
return (strings, ...values) => callback(
strings.raw.reduce((acc, str, i) => acc + (mutator(values[i - 1])) + str)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment