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

Function replaceCSSVariablesNames

src/inject/dynamic-theme/variables.ts:691–719  ·  view source on GitHub ↗
(
    value: string,
    nameReplacer: (varName: string) => string,
    fallbackReplacer?: (fallbackValue: string) => string,
    finalFallback?: string,
)

Source from the content-addressed store, hash-verified

689}
690
691export function replaceCSSVariablesNames(
692 value: string,
693 nameReplacer: (varName: string) => string,
694 fallbackReplacer?: (fallbackValue: string) => string,
695 finalFallback?: string,
696): string {
697 const matchReplacer = (match: string) => {
698 const {name, fallback} = getVariableNameAndFallback(match);
699 const newName = nameReplacer(name);
700 if (!fallback) {
701 if (finalFallback) {
702 return `var(${newName}, ${finalFallback})`;
703 }
704 return `var(${newName})`;
705 }
706
707 let newFallback: string;
708 if (isVarDependant(fallback)) {
709 newFallback = replaceCSSVariablesNames(fallback, nameReplacer, fallbackReplacer);
710 } else if (fallbackReplacer) {
711 newFallback = fallbackReplacer(fallback);
712 } else {
713 newFallback = fallback;
714 }
715 return `var(${newName}, ${newFallback})`;
716 };
717
718 return replaceVariablesMatches(value, matchReplacer);
719}
720
721function iterateVarDependencies(value: string, iterator: (varName: string) => void) {
722 replaceCSSVariablesNames(value, (varName) => {

Callers 6

addModifiedValueMethod · 0.85
getDeclarationsMethod · 0.85
modifyMethod · 0.85
matchReplacerFunction · 0.85
iterateVarDependenciesFunction · 0.85

Calls 1

replaceVariablesMatchesFunction · 0.85

Tested by

no test coverage detected