MCPcopy Index your code
hub / github.com/darkreader/darkreader / replaceVariablesMatches

Function replaceVariablesMatches

src/inject/dynamic-theme/variables.ts:657–675  ·  view source on GitHub ↗
(input: string, replacer: (match: string, count: number) => string | null)

Source from the content-addressed store, hash-verified

655}
656
657function replaceVariablesMatches(input: string, replacer: (match: string, count: number) => string | null) {
658 const matches = getVariablesMatches(input);
659 const matchesCount = matches.length;
660 if (matchesCount === 0) {
661 return input;
662 }
663
664 const inputLength = input.length;
665 const replacements = matches.map((m) => replacer(m.value, matches.length));
666 const parts: Array<string | null> = [];
667 parts.push(input.substring(0, matches[0].start));
668 for (let i = 0; i < matchesCount; i++) {
669 parts.push(replacements[i]);
670 const start = matches[i].end;
671 const end = i < matchesCount - 1 ? matches[i + 1].start : inputLength;
672 parts.push(input.substring(start, end));
673 }
674 return parts.join('');
675}
676
677function getVariableNameAndFallback(match: string) {
678 const commaIndex = match.indexOf(',');

Callers 2

replaceCSSVariablesNamesFunction · 0.85
insertVarValuesFunction · 0.85

Calls 1

getVariablesMatchesFunction · 0.85

Tested by

no test coverage detected