* Check whether a class string matches a given Tailwind prefix. * E.g. prefix "p" matches "p-4", "p-[13px]", but not "px-4" or "pl-2".
(cls: string, prefix: string)
| 288 | * E.g. prefix "p" matches "p-4", "p-[13px]", but not "px-4" or "pl-2". |
| 289 | */ |
| 290 | function classMatchesPrefix(cls: string, prefix: string): boolean { |
| 291 | // Skip variant-prefixed classes (e.g. hover:bg-blue-700, dark:bg-gray-900). |
| 292 | // These are intentional state/responsive overrides and should not be |
| 293 | // matched when replacing the base utility class. |
| 294 | if (cls.includes(":")) return false; |
| 295 | // Exact match for standalone classes like "rounded" |
| 296 | if (cls === prefix) return true; |
| 297 | // prefix- followed by something |
| 298 | return cls.startsWith(`${prefix}-`); |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * Apply a single update to an array of class strings. |
no outgoing calls
no test coverage detected