MCPcopy Create free account
hub / github.com/donghaxkim/react-rewrite / classMatchesPrefix

Function classMatchesPrefix

packages/cli/src/transform.ts:290–299  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

288 * E.g. prefix "p" matches "p-4", "p-[13px]", but not "px-4" or "pl-2".
289 */
290function 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.

Callers 3

applyUpdateFunction · 0.70
mutateClassNameFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected