color-parse
Advanced tools
Comparing version 1.2.1 to 1.3.0
19
index.js
@@ -36,3 +36,3 @@ /** | ||
function parse (cstr) { | ||
var m, parts = [0,0,0], alpha = 1, space = 'rgb'; | ||
var m, parts = [], alpha = 1, space; | ||
@@ -43,2 +43,3 @@ if (typeof cstr === 'string') { | ||
parts = names[cstr].slice(); | ||
space = 'rgb' | ||
} | ||
@@ -49,2 +50,4 @@ | ||
alpha = 0; | ||
space = 'rgb' | ||
parts = [0,0,0] | ||
} | ||
@@ -76,2 +79,3 @@ | ||
if (!parts[2]) parts[2] = 0; | ||
space = 'rgb' | ||
} | ||
@@ -123,6 +127,2 @@ | ||
} | ||
else { | ||
throw Error('Unable to parse ' + cstr); | ||
} | ||
} | ||
@@ -132,2 +132,3 @@ | ||
else if (typeof cstr === 'number') { | ||
space = 'rgb' | ||
parts = [cstr >>> 16, (cstr & 0x00ff00) >>> 8, cstr & 0x0000ff]; | ||
@@ -140,5 +141,7 @@ } | ||
parts = [cstr.r, cstr.g, cstr.b]; | ||
space = 'rgb' | ||
} | ||
else if (cstr.red != null) { | ||
parts = [cstr.red, cstr.green, cstr.blue]; | ||
space = 'rgb' | ||
} | ||
@@ -162,10 +165,6 @@ else if (cstr.h != null) { | ||
parts = [cstr[0], cstr[1], cstr[2]]; | ||
space = 'rgb' | ||
alpha = cstr.length === 4 ? cstr[3] : 1; | ||
} | ||
else { | ||
throw Error('Unable to parse ' + cstr); | ||
} | ||
return { | ||
@@ -172,0 +171,0 @@ space: space, |
{ | ||
"name": "color-parse", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "Color string parser", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
7661
144