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

Function insertVarValues

src/inject/dynamic-theme/variables.ts:854–885  ·  view source on GitHub ↗
(source: string, varValues: Map<string, string>, fullStack = new Set<string>())

Source from the content-addressed store, hash-verified

852}
853
854function insertVarValues(source: string, varValues: Map<string, string>, fullStack = new Set<string>()) {
855 let containsUnresolvedVar = false;
856 const matchReplacer = (match: string, count: number) => {
857 const {name, fallback} = getVariableNameAndFallback(match);
858 const stack = count > 1 ? new Set(fullStack) : fullStack;
859 if (stack.has(name)) {
860 containsUnresolvedVar = true;
861 return null;
862 }
863 stack.add(name);
864 const varValue = varValues.get(name) || fallback;
865 let inserted: string | null = null;
866 if (varValue) {
867 if (isVarDependant(varValue)) {
868 inserted = insertVarValues(varValue, varValues, stack);
869 } else {
870 inserted = varValue;
871 }
872 }
873 if (!inserted) {
874 containsUnresolvedVar = true;
875 return null;
876 }
877 return inserted;
878 };
879
880 const replaced = replaceVariablesMatches(source, matchReplacer);
881 if (containsUnresolvedVar) {
882 return null;
883 }
884 return replaced;
885}

Callers 3

addModifiedValueMethod · 0.85
matchReplacerFunction · 0.85

Calls 1

replaceVariablesMatchesFunction · 0.85

Tested by

no test coverage detected