All files / react-native-web/src/modules/normalizeColor index.js

100% Statements 13/13
88.89% Branches 8/9
100% Functions 1/1
100% Lines 12/12

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 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32                        24x 284x   282x 24x     258x 258x 258x 258x 258x 258x 258x 258x          
/**
 * Copyright (c) Nicolas Gallagher.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow
 */
 
import isWebColor from '../isWebColor';
import processColor from '../../exports/processColor';
 
const normalizeColor = (color?: number | string, opacity?: number = 1): void | string => {
  if (color == null) return;
 
  if (typeof color === 'string' && isWebColor(color)) {
    return color;
  }
 
  const colorInt = processColor(color);
  Eif (colorInt != null) {
    const r = (colorInt >> 16) & 255;
    const g = (colorInt >> 8) & 255;
    const b = colorInt & 255;
    const a = ((colorInt >> 24) & 255) / 255;
    const alpha = (a * opacity).toFixed(2);
    return `rgba(${r},${g},${b},${alpha})`;
  }
};
 
export default normalizeColor;