colorformat
Advanced tools
Comparing version 1.2.1 to 1.2.2
16
index.js
@@ -10,9 +10,15 @@ (function (root, factory) { | ||
}(this, function () { | ||
function hexToDec(n) { | ||
function decToHex(n) { | ||
return n.toString(16); | ||
} | ||
function decToHex(n) { | ||
function hexToDec(n) { | ||
return parseInt(n, 16); | ||
} | ||
function fixDigits(s){ | ||
if(s.length != 2) return '0' + s; | ||
else return s; | ||
} | ||
return { | ||
@@ -31,3 +37,3 @@ rgbToHex: function(r, g, b) { | ||
throw new Error('Expected arguments to be between 0 and 255'); | ||
return '#' + hexToDec(r) + hexToDec(g) + hexToDec(b); | ||
return '#' + fixDigits(decToHex(r)) + fixDigits(decToHex(g)) + fixDigits(decToHex(b)); | ||
}, | ||
@@ -45,7 +51,7 @@ | ||
if(options && options.styling) | ||
return 'rgb(' + decToHex(h[0]+h[1]) + ', ' + decToHex(h[2]+h[3]) + ', ' + decToHex(h[4]+h[5]) + ')'; | ||
return 'rgb(' + hexToDec(h[0]+h[1]) + ', ' + hexToDec(h[2]+h[3]) + ', ' + hexToDec(h[4]+h[5]) + ')'; | ||
else | ||
return [decToHex(h[0]+h[1]), decToHex(h[2]+h[3]), decToHex(h[4]+h[5])]; | ||
return [hexToDec(h[0]+h[1]), hexToDec(h[2]+h[3]), hexToDec(h[4]+h[5])]; | ||
} | ||
}; | ||
})); |
{ | ||
"name": "colorformat", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "Convert color format from RGB to HEX and vice versa", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
2914
46