MCPcopy Index your code
hub / github.com/tailwindlabs/tailwindcss / parseModifier

Function parseModifier

packages/tailwindcss/src/candidate.ts:615–660  ·  view source on GitHub ↗
(modifier: string)

Source from the content-addressed store, hash-verified

613}
614
615function parseModifier(modifier: string): CandidateModifier | null {
616 if (modifier[0] === '[' && modifier[modifier.length - 1] === ']') {
617 let arbitraryValue = decodeArbitraryValue(modifier.slice(1, -1))
618
619 // Values can't contain `;` or `}` characters at the top-level.
620 if (!isValidArbitrary(arbitraryValue)) return null
621
622 // Empty arbitrary values are invalid. E.g.: `data-[]:`
623 // ^^
624 if (arbitraryValue.length === 0 || arbitraryValue.trim().length === 0) return null
625
626 return {
627 kind: 'arbitrary',
628 value: arbitraryValue,
629 }
630 }
631
632 if (modifier[0] === '(' && modifier[modifier.length - 1] === ')') {
633 // Drop the `(` and `)` characters
634 modifier = modifier.slice(1, -1)
635
636 // A modifier with `(…)` should always start with `--` since it
637 // represents a CSS variable.
638 if (modifier[0] !== '-' || modifier[1] !== '-') return null
639
640 // Values can't contain `;` or `}` characters at the top-level.
641 if (!isValidArbitrary(modifier)) return null
642
643 // Wrap the value in `var(…)` to ensure that it is a valid CSS variable.
644 modifier = `var(${modifier})`
645
646 let arbitraryValue = decodeArbitraryValue(modifier)
647
648 return {
649 kind: 'arbitrary',
650 value: arbitraryValue,
651 }
652 }
653
654 if (!IS_VALID_NAMED_VALUE.test(modifier)) return null
655
656 return {
657 kind: 'named',
658 value: modifier,
659 }
660}
661
662export function parseVariant(variant: string, designSystem: DesignSystem): Variant | null {
663 // Arbitrary variants

Callers 2

parseCandidateFunction · 0.85
parseVariantFunction · 0.85

Calls 2

decodeArbitraryValueFunction · 0.90
isValidArbitraryFunction · 0.90

Tested by

no test coverage detected