Last active
April 25, 2020 04:21
-
-
Save thecrypticace/79084be1b2fe38a09756734a20545421 to your computer and use it in GitHub Desktop.
Prefix All Tailwind UI classes
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
// Prefix all Tailwind UI classes with "tw-" | |
// Works as of 2020-04-25 | |
// Examples: | |
// mx-4 -> tw-mx-4 | |
// -mx-4 -> tw--mx-4 | |
// lg:mx-4 -> lg:tw-mx-4 | |
// lg:-mx-4 -> lg:tw--mx-4 | |
const prefix = "tw-" | |
Array | |
.from(document.querySelectorAll("code .token.attr-name")) | |
.filter(el => el.textContent === "class") | |
.map(el => el.nextElementSibling) | |
.flatMap(el => [...el.childNodes]) | |
.filter(n => n.nodeType === 3) | |
.map(n => (n.parentNode.dataset.value = n.parentNode.dataset.value || n.textContent, n)) | |
.forEach(n => { | |
n.textContent = n.parentNode.dataset.value | |
.split(/\s+/g) | |
.map(c => c.replace(/^(?!.*:)|(:)/g, `$1${prefix}`)) | |
.join(" ") | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment