Skip to content

Class: ModifierMatcher ​

Defined in: packages/core/src/modifier.ts:174

The single owner of modifier recognition for one convention: finds modifiers on selectors, derives prop/value, renders a modifier name back to a selector fragment, and answers "does this host-doc token look like a modifier usage?". Constructed once per parse from the resolved convention.

Constructors ​

Constructor ​

ts
new ModifierMatcher(convention): ModifierMatcher;

Defined in: packages/core/src/modifier.ts:191

Parameters ​

convention ​

ModifierConvention

Returns ​

ModifierMatcher

Properties ​

convention ​

ts
readonly convention: ModifierConvention;

Defined in: packages/core/src/modifier.ts:175

Methods ​

analyze() ​

ts
analyze(name): object;

Defined in: packages/core/src/modifier.ts:414

Derive prop/value for a modifier name (as returned by modifiersIn or authored).

Parameters ​

name ​

string

Returns ​

object

prop ​
ts
prop: string;
value? ​
ts
value?: string;

elementsIn() ​

ts
elementsIn(selector, baseNoDot): object[];

Defined in: packages/core/src/modifier.ts:316

Every BEM-style element attached to baseNoDot within one selector (.base<elementSep><name>), as parts, each with any element-scoped modifiers (.base__element--mod → element base__element with modifier mod). Only meaningful for suffix conventions with an elementSeparator.

Parameters ​

selector ​

string

baseNoDot ​

string

Returns ​

object[]


looksLikeUsage() ​

ts
looksLikeUsage(token, baseNoDot?): boolean;

Defined in: packages/core/src/modifier.ts:471

Does a token/expression seen in a host document (an HTML class token, or an attribute expression) look like a modifier usage of baseNoDot? Replaces the old startsWith("-") gate.

Parameters ​

token ​

string

baseNoDot? ​

string

Returns ​

boolean


matchesModifier() ​

ts
matchesModifier(name, used): boolean;

Defined in: packages/core/src/modifier.ts:452

Whether a used class used is an instance of the documented modifier name — an exact match, or, when name is a * family (e.g. -icon-*), a glob match (* → any [\w-] run). Used consumer-side so -icon-arrow resolves to the documented -icon-* family.

Parameters ​

name ​

string

used ​

string

Returns ​

boolean


modifiersIn() ​

ts
modifiersIn(selector, baseNoDot): ModifierHit[];

Defined in: packages/core/src/modifier.ts:237

Every modifier attached to baseNoDot within one selector. selector should have its pseudos already dropped (as parse.ts/index.ts do); the base is given without its leading dot.

Parameters ​

selector ​

string

baseNoDot ​

string

Returns ​

ModifierHit[]


normalizeMember() ​

ts
normalizeMember(token): string;

Defined in: packages/core/src/modifier.ts:459

Normalize a member token/expression to its canonical name key (the inverse of authoring noise).

Parameters ​

token ​

string

Returns ​

string


pseudoElementsIn() ​

ts
pseudoElementsIn(selector): object[];

Defined in: packages/core/src/modifier.ts:399

Every native pseudo-element on the selector recognized for documentation — a ::name whose name is in the convention's ModifierConvention.pseudoElements (e.g. .alert::before → before). ::part()/::slotted() and pseudo-elements not in the set are ignored.

Parameters ​

selector ​

string

Returns ​

object[]


pseudoStatesIn() ​

ts
pseudoStatesIn(selector): object[];

Defined in: packages/core/src/modifier.ts:380

Every native pseudo-class on the selector recognized as a state — a :name whose name is in the convention's ModifierConvention.statePseudoClasses (e.g. .tab:disabled → disabled). Pseudo-elements (::part) and pseudos not in the set are ignored.

Parameters ​

selector ​

string

Returns ​

object[]


selectorFor() ​

ts
selectorFor(name): string;

Defined in: packages/core/src/modifier.ts:443

Render a modifier name as the selector fragment it denotes (.name or [name]).

Parameters ​

name ​

string

Returns ​

string


statesIn() ​

ts
statesIn(selector, baseNoDot): object[];

Defined in: packages/core/src/modifier.ts:356

Every state class chained to baseNoDot within one selector — a class whose name starts with one of the convention's ModifierConvention.statePrefixes (e.g. .tabs.is-open → is-open). Empty when the convention sets no state prefixes.

Parameters ​

selector ​

string

baseNoDot ​

string

Returns ​

object[]


usageKind() ​

ts
usageKind(token, baseNoDot?): "element" | "modifier" | "state" | undefined;

Defined in: packages/core/src/modifier.ts:492

Classify a host-document class token relative to baseNoDot: a modifier usage, a state class (a statePrefixes prefix), a BEM element class (base<elementSep>…), or undefined if it's none of those. Consumer-side linting routes each kind to the right "unknown-…" check.

Parameters ​

token ​

string

baseNoDot? ​

string

Returns ​

"element" | "modifier" | "state" | undefined

Released under the MIT License