packages/regex/src
@cssdoc/regex
Type-safe, ArkRegex-based pattern library for cssdoc. Centralizes CSS, grammar-driven, and cssdoc-specific regex patterns with modern named capture groups.
Overview
This package provides a unified library of regex patterns used throughout cssdoc:
- Tier 1 (W3C CSS): Standard CSS patterns from W3C formal grammar
- Identifiers, keywords, colors, functions, properties, units
- Tier 2 (CssDoc Grammar): Patterns from CssDoc.grammarkdown specification
- Record names, modifiers, tags, structure references, cardinality
- Tier 3 (cssdoc-Specific): Local implementation patterns
- BEM conventions, ARIA attributes, configuration globbing
Benefits
- Type Safety: All patterns use named capture groups with TypeScript inference
- IDE Completion: Auto-complete shows all available capture groups
- Single Source of Truth: Each pattern defined once, used everywhere
- Maintainability: Patterns traceable to specs and documentation
- Security: ArkRegex prevents ReDoS vulnerabilities
- Zero Runtime Overhead: Types-only, compile-time inference only
Usage
import { CssPatterns, CssDocPatterns, ModifierPatterns } from "@cssdoc/regex";
// Tier 1: W3C CSS patterns
const colorMatch = CssPatterns.CSS_HASH_COLOR.exec("#ffffff");
const color = colorMatch?.groups?.color; // "ffffff"
// Tier 2: Grammar patterns
const tagMatch = CssDocPatterns.CSSDOC_TAG.exec("@component");
const tag = tagMatch?.groups?.tag; // "component"
// Tier 3: cssdoc-specific patterns
const bemMatch = ModifierPatterns.BEM_MODIFIER.exec(".button--primary");
const { base, mod } = bemMatch?.groups ?? {}; // "button", "primary"Namespaces
Interfaces
- AttributeCapture
- BemCapture
- CardinalityCapture
- CombinatorCapture
- CssDimensionCapture
- CssIdentifierCapture
- CssNumberCapture
- ModifierCapture
- PseudoCapture
- Regex
- TagCapture
Type Aliases
Variables
References
ARIA_STATE
Re-exports ARIA_STATE
ATTRIBUTE_SELECTOR
Re-exports ATTRIBUTE_SELECTOR
BEM_BLOCK
Re-exports BEM_BLOCK
BEM_ELEMENT
Re-exports BEM_ELEMENT
BEM_MODIFIER
Re-exports BEM_MODIFIER
CLASS_REF
Re-exports CLASS_REF
COMBINATOR
Re-exports COMBINATOR
CSS_DIMENSION
Re-exports CSS_DIMENSION
CSS_FUNCTION
Re-exports CSS_FUNCTION
CSS_HASH_COLOR
Re-exports CSS_HASH_COLOR
CSS_IDENTIFIER
Re-exports CSS_IDENTIFIER
CSS_KEYWORD
Re-exports CSS_KEYWORD
CSS_NAME
Re-exports CSS_NAME
CSS_NUMBER
Re-exports CSS_NUMBER
CSS_PERCENTAGE
Re-exports CSS_PERCENTAGE
CSS_PROPERTY_NAME
Re-exports CSS_PROPERTY_NAME
CSS_UNICODE_RANGE
Re-exports CSS_UNICODE_RANGE
CSSDOC_CARDINALITY
Re-exports CSSDOC_CARDINALITY
CSSDOC_CUSTOM_PROPERTY
Re-exports CSSDOC_CUSTOM_PROPERTY
CSSDOC_IDENTIFIER
Re-exports CSSDOC_IDENTIFIER
CSSDOC_INLINE_REF
Re-exports CSSDOC_INLINE_REF
CSSDOC_MODIFIER_ATTRIBUTE
Re-exports CSSDOC_MODIFIER_ATTRIBUTE
CSSDOC_MODIFIER_CHAINED
Re-exports CSSDOC_MODIFIER_CHAINED
CSSDOC_MODIFIER_SUFFIX
Re-exports CSSDOC_MODIFIER_SUFFIX
CSSDOC_RECORD_NAME
Re-exports CSSDOC_RECORD_NAME
CSSDOC_STRUCTURE_REF
Re-exports CSSDOC_STRUCTURE_REF
CSSDOC_TAG
Re-exports CSSDOC_TAG
CSSDOC_TAG_ARG
Re-exports CSSDOC_TAG_ARG
GLOB_PATTERN
Re-exports GLOB_PATTERN
MODIFIER_CHAIN
Re-exports MODIFIER_CHAIN
PSEUDO_CLASS
Re-exports PSEUDO_CLASS
PSEUDO_ELEMENT
Re-exports PSEUDO_ELEMENT
RSCSS_COMPONENT
Re-exports RSCSS_COMPONENT
RSCSS_ELEMENT
Re-exports RSCSS_ELEMENT
RSCSS_HELPER
Re-exports RSCSS_HELPER
RSCSS_VARIANT
Re-exports RSCSS_VARIANT
SCOPE_PRELUDE_BASE
Re-exports SCOPE_PRELUDE_BASE
SINGLE_CLASS
Re-exports SINGLE_CLASS
VAR_REFERENCE
Re-exports VAR_REFERENCE