All files / core/src/utilities convertColorArrayToRgbString.ts

100% Statements 2/2
50% Branches 1/2
100% Functions 2/2
100% Lines 2/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15                    1216x 3648x      
/**
 * Converts a color array [r, g, b] (values 0-1) to an RGB string.
 * If the input is already a string, it returns it as-is.
 *
 * @param colorArr - Color as array [r, g, b] or RGB string
 * @returns RGB string in format "rgb(r, g, b)"
 */
export function convertColorArrayToRgbString(
  colorArr: number[] | string
): string {
  return Array.isArray(colorArr)
    ? `rgb(${colorArr.map((v) => Math.round(v * 255)).join(',')})`
    : colorArr;
}