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

Function parseColorWithCache

src/utils/color.ts:22–38  ·  view source on GitHub ↗
($color: string)

Source from the content-addressed store, hash-verified

20const rgbaParseCache = new Map<string, RGBA>();
21
22export function parseColorWithCache($color: string): RGBA | null {
23 $color = $color.trim();
24 if (rgbaParseCache.has($color)) {
25 return rgbaParseCache.get($color)!;
26 }
27 // We cannot _really_ parse any color which has the calc() expression,
28 // so we try our best to remove those and then parse the value.
29 if ($color.includes('calc(')) {
30 $color = lowerCalcExpression($color);
31 }
32 const color = parse($color);
33 if (color) {
34 rgbaParseCache.set($color, color);
35 return color;
36 }
37 return null;
38}
39
40export function parseToHSLWithCache(color: string): HSLA | null {
41 if (hslaParseCache.has(color)) {

Callers 15

hasBuiltInDarkThemeFunction · 0.90
getSelectionColorFunction · 0.90
getColorModifierFunction · 0.90
getGradientModifierFunction · 0.90
replaceCSSTemplatesFunction · 0.90
inspectVariableMethod · 0.90
handleRawColorValueFunction · 0.90
registerColorFunction · 0.90

Calls 5

lowerCalcExpressionFunction · 0.85
parseFunction · 0.70
hasMethod · 0.65
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected