UNPKG

react-native-web

Version:
30 lines (29 loc) 839 B
/** * 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. * * */ import isWebColor from '../isWebColor'; import processColor from '../../exports/processColor'; var normalizeColor = function normalizeColor(color, opacity) { if (opacity === void 0) { opacity = 1; } if (color == null) return; if (typeof color === 'string' && isWebColor(color)) { return color; } var colorInt = processColor(color); if (colorInt != null) { var r = colorInt >> 16 & 255; var g = colorInt >> 8 & 255; var b = colorInt & 255; var a = (colorInt >> 24 & 255) / 255; var alpha = (a * opacity).toFixed(2); return "rgba(" + r + "," + g + "," + b + "," + alpha + ")"; } }; export default normalizeColor;