Nodejs Utililty Methods String to Color Convert

List of utility methods to do String to Color Convert

Description

The list of methods to do String to Color Convert are organized into topic(s).

Method

hexRgb(retarr)
String.prototype.hexRgb = function(retarr) {
    var that = this,
        hex, 
        newhex = '';
    try {
       hex = this.split('#')[1].toLocaleLowerCase();
    } catch (e) {
        return this;
    var regexps = [/^[0-9a-f]{3}$/, /^[0-9a-f]{6}$/];
    if (regexps[1].test(hex)) {
        newhex = hex;
    } else if (regexps[0].test(hex)) {
        newhex = hex.charAt(0) + hex.charAt(0) + hex.charAt(1) + hex.charAt(1) + hex.charAt(2) + hex.charAt(2);
    } else {
        return this;
    var hr, hg, hb, r, g, b;
    hr = newhex.charAt(0) + newhex.charAt(1);
    hg = newhex.charAt(2) + newhex.charAt(3);
    hb = newhex.charAt(4) + newhex.charAt(5);
    r = parseInt('0x' + hr);
    g = parseInt('0x' + hg);
    b = parseInt('0x' + hb);
    if (retarr) {
        return [r, g, b];
    return 'rgb(' + r + ', ' + g + ', ' + b + ')';
};
hexRgbFade(a)
String.prototype.hexRgbFade = function(a) {
    var rgb = this.hexRgb(true);
    if (!$.isArray(rgb)) {
        rgb = this.parseRgb();
    a = parseFloat(a);
    var r = parseInt(255 - (255 - rgb[0]) * a),
        g = parseInt(255 - (255 - rgb[1]) * a),
        b = parseInt(255 - (255 - rgb[2]) * a);
...
hexRgba(a)
String.prototype.hexRgba = function(a) {
    var rgb = this.hexRgb(true);
    if (!$.isArray(rgb)) {
        rgb = this.parseRgb();
    var r = rgb[0], g = rgb[1], b = rgb[2];
    return 'rgba(' + r + ', ' + g + ', ' + b + ', ' + a + ')';
};
hexToRGB( output )
String.prototype.hexToRGB = function( output ) {
    if ( output == undefined ) {
        output = 'css';
    var rgb = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec( this );
    if ( output.toLowerCase() == 'css' ) {
        return rgb ? 'rgb( ' + parseInt( rgb[1], 16 ) + ', ' + parseInt( rgb[2], 16 ) + ', ' + parseInt( rgb[3], 16 ) + ' )' : null;
    else {
...