azure-devops-ui
Version:
React components for building web UI in Azure DevOps
1 lines • 1.25 kB
JavaScript
function darken(r,e){e=1-e;return{red:r.red*e,green:r.green*e,blue:r.blue*e}}function getColorString(r){return"rgb(".concat(r.red,", ").concat(r.green,", ").concat(r.blue,")")}function isDark(r){return.299*r.red+.587*r.green+.114*r.blue<=128}function rgbToHex(r){return"#".concat(rgbValueToString(r.red)).concat(rgbValueToString(r.green)).concat(rgbValueToString(r.blue)).toUpperCase()}function hexToRgb(r){if(7!==r.length||"#"!==r[0])throw new Error("Expected color in format #AABBCC");return{red:parseInt(r.substr(1,2),16),green:parseInt(r.substr(3,2),16),blue:parseInt(r.substr(5,2),16)}}function generateRandomColor(){var r=Math.floor(256*Math.random()),e=Math.floor(256*Math.random());return{red:Math.floor(256*Math.random()),blue:r,green:e}}function generateRandomColorHex(){return rgbToHex(generateRandomColor())}function parseColor(r){if(r){var e=void 0;if(7===r.length)try{e=hexToRgb(r)}catch(r){console.log(r)}return e}}var hexRegex=new RegExp("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$");function testForHexString(r){return r.match(hexRegex)}function rgbValueToString(r){r=r.toString(16);return r=1===r.length?"0"+r:r}export{darken,getColorString,isDark,rgbToHex,hexToRgb,generateRandomColor,generateRandomColorHex,parseColor,testForHexString};