@chayns/colors
Version:
JavaScript utility functions for the calculation of colors for chayns
33 lines (26 loc) • 817 B
JavaScript
import { rgb255ToHex } from '../converter';
function getRandomRgb255Color() {
var transparency = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
var rgb = {
r: null,
g: null,
b: null
};
if (transparency) {
rgb.a = null;
}
for (var i = 0; i < Object.keys(rgb).length; i += 1) {
var component = Object.keys(rgb)[i];
rgb[component] = Math.random();
if (component !== 'a') {
rgb[component] = Math.round((rgb[component] || 0) * 255);
}
}
return rgb;
}
function getRandomHexColor() {
var transparency = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
return rgb255ToHex(getRandomRgb255Color(transparency));
}
export { getRandomHexColor, getRandomRgb255Color };
//# sourceMappingURL=randomColor.js.map