JSFiddle - React, Tailwind, and code Playground

by kiokotzu

JavaScript

var searColor = "background:rgba(0,0,0,1);",
      azul      = '#14457D';
      
function removeText(findColor, color){
          rgb2hex = function(rgb){
              rgb = rgb.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
              console.log(rgb, 'hexa')
              return (rgb && rgb.length === 4) ? "#" +
              ("0" + parseInt(rgb[1],10).toString(16)).slice(-2) +
              ("0" + parseInt(rgb[2],10).toString(16)).slice(-2) +
              ("0" + parseInt(rgb[3],10).toString(16)).slice(-2) : '';
          }
          var position = findColor === undefined ?  color : findColor.split(":"),
              //final    = position[1].indexOf(";") > -1 ? position[1].split(";") : position[1],
              hex      = findColor === undefined ?  color : rgb2hex( position[0] );
              console.log(position, hex, 'remove')
          
          return hex;
        }
        
        
        var tomalo = removeText(searColor, azul);
        
        console.log(tomalo)