User:Killr833/ColorScript.js

/* ColorScript JavaScript Library * * Published under GNU GPL */

function cs.decimalToHex(decimal) { return decimal.toString(16); }

function cs.hexToDecimal(hex) { var unpadded = parseInt(hex, 16); if (unpadded.length == 1) { var padded = '0' + unpadded; }		else { var padded = unpadded; }	return padded; }

function cs.shorthandHex(hexcolor) { if ((hexcolor.substring(1, 2) == hexcolor.substring(2, 3)) && (hexcolor.substring(3, 4) == hexcolor.substring(4, 5)) && (hexcolor.substring(5, 6) == hexcolor.substring(6, 7)) {		var finished = '#' + hexcolor.substring(1, 2) + hexcolor.substring(3, 4) + hexcolor.substring(5, 6);	}	else {		var finished = hexcolor;	}	return finished; }

/* WIP function cs.convert(from, input, short) { switch (from) { case 'rgb': var rgb = input.split(' '); var r = rgb[ 0]; var g = rgb[ 1]; var b = rgb[ 2]; var rh = cs.hexToDecimal(r); var gh = cs.hexToDecimal(g); var bh = cs.hexToDecimal(b); var hex = '#' + rh + gh + bh; if ((short == 'yes') || (short == 'y')) { var result = cs.shorthandHex(hex); }				else { var result = hex; }