MCPcopy
hub / github.com/danvk/dygraphs / parseRGBA

Function parseRGBA

src/dygraph-utils.js:1026–1045  ·  view source on GitHub ↗

* Helper for toRGB_ which parses strings of the form: * #RRGGBB (hex) * #RRGGBBAA (hex) * rgb(123, 45, 67) * rgba(123, 45, 67, 0.5) * @return parsed {r,g,b,a?} tuple or null.

(rgbStr)

Source from the content-addressed store, hash-verified

1024 * @return parsed {r,g,b,a?} tuple or null.
1025 */
1026function parseRGBA(rgbStr) {
1027 var bits, r, g, b, a = null;
1028 if ((bits = RGBAxRE.exec(rgbStr))) {
1029 r = parseInt(bits[1], 16);
1030 g = parseInt(bits[2], 16);
1031 b = parseInt(bits[3], 16);
1032 if (bits[4])
1033 a = parseInt(bits[4], 16);
1034 } else if ((bits = RGBA_RE.exec(rgbStr))) {
1035 r = parseInt(bits[1], 10);
1036 g = parseInt(bits[2], 10);
1037 b = parseInt(bits[3], 10);
1038 if (bits[4])
1039 a = parseFloat(bits[4]);
1040 } else
1041 return null;
1042 if (a !== null)
1043 return { "r": r, "g": g, "b": b, "a": a };
1044 return { "r": r, "g": g, "b": b };
1045}
1046
1047/**
1048 * Converts any valid CSS color (hex, rgb(), named color) to an RGB tuple.

Callers 1

toRGB_Function · 0.85

Calls 1

parseFloatFunction · 0.85

Tested by

no test coverage detected