pure-color
Version:
Pure functions for color conversion and parsing
36 lines (29 loc) • 636 B
JavaScript
var hsl = require("./hsl");
var hex = require("./hex");
var rgb = require("./rgb");
var hsl2rgb = require("../convert/hsl2rgb");
function hsl2rgbParse(color) {
var h = hsl(color);
var r = hsl2rgb(h);
// handle alpha since hsl2rgb doesn't know (or care!) about it
if(h.length === 4) {
r.push(h[3]);
}
return r;
}
var space2parser = {
"#" : hex,
"hsl" : hsl2rgbParse,
"rgb" : rgb
};
function parse(color) {
for(var scheme in space2parser) {
if(color.indexOf(scheme) === 0) {
return space2parser[scheme](color);
}
}
}
parse.rgb = rgb;
parse.hsl = hsl;
parse.hex = hex;
module.exports = parse;