colorguard
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -19,3 +19,3 @@ var visit = require('rework-visit'); | ||
function rgbToHex(r, g, b) { | ||
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b); | ||
return ("#" + componentToHex(parseInt(r,10)) + componentToHex(parseInt(g,10)) + componentToHex(parseInt(b))).toUpperCase(); | ||
} | ||
@@ -57,3 +57,4 @@ | ||
return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)]; | ||
var out = [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)]; | ||
return out; | ||
} | ||
@@ -63,2 +64,11 @@ | ||
rgb: function(r, g, b) { | ||
if (r.indexOf && r.indexOf('%') > 0) { | ||
r = 255 * (parseInt(r, 10) / 100); | ||
} | ||
if (g.indexOf && g.indexOf('%') > 0) { | ||
g = 255 * (parseInt(g, 10) / 100); | ||
} | ||
if (b.indexOf && b.indexOf('%') > 0) { | ||
b = 255 * (parseInt(b, 10) / 100); | ||
} | ||
var normalizedColor = rgbToHex(r, g, b); | ||
@@ -72,6 +82,13 @@ // Add it to the color hash | ||
rgba: function(r, g, b, a) { | ||
functions.rgb.call(this, r, g, b); | ||
functions.rgb.call(this, r, g, b); | ||
return ident('rgba', [].slice.call(arguments)); | ||
}, | ||
hsl: function(h, s, l) { | ||
h = (h % 360)/360; | ||
if (s.indexOf && s.indexOf('%') > 0) { | ||
s = parseInt(s, 10) / 100; | ||
} | ||
if (l.indexOf && l.indexOf('%') > 0) { | ||
l = parseInt(l, 10) / 100; | ||
} | ||
functions.rgb.apply(this, hslToRgb(h, s, l)); | ||
@@ -81,3 +98,3 @@ return ident('hsl', [].slice.call(arguments)); | ||
hsla: function(h, s, l, a) { | ||
functions.rgb.apply(this, hslToRgb(h, s, l)); | ||
functions.hsl.call(this, h, s, l); | ||
return ident('hsla', [].slice.call(arguments)); | ||
@@ -99,5 +116,5 @@ } | ||
if (color.length === 4) { | ||
return '#' + color[1] + color[1] + color[2] + color[2] + color[3] + color[3]; | ||
color = '#' + color[1] + color[1] + color[2] + color[2] + color[3] + color[3]; | ||
} | ||
return color; | ||
return color.toUpperCase(); | ||
} | ||
@@ -104,0 +121,0 @@ |
{ | ||
"name": "colorguard", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Keep a watchful eye on your css colors", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
20173
305