import { tokenize } from "./tokenize"; /** * Removes all variants from head and then searches for patterns, reducing * matches after the first. */ export function patternReduce(tokens: string[], patterns: RegExp[]): string[] { if (tokens.length === 0) { return []; } let classString = tokens.map((t) => t.replace(/.*:/, "")).join(" "); for (const pattern of patterns) { const matches = classString.matchAll(pattern); let idx = 0; for (const match of matches) { if (idx !== 0) { classString = classString.replace(match[0], ""); } idx++; } } return tokenize(classString); }