@bee-design/ui
Version:
Bee Design React UI Library.
24 lines (18 loc) • 525 B
JavaScript
const Color = require('color');
exports.getRgbStr = function (color) {
return Color(color).rgb().round().color.join(',');
};
const formats = ['hex', 'rgb', 'hsl'];
function getFormat(format) {
if (!format || formats.indexOf(format) < 0) {
return 'hex';
}
return format;
}
exports.getColorString = function (color, format) {
const innerFormat = getFormat(format);
if (innerFormat === 'hex') {
return color[innerFormat]();
}
return color[innerFormat]().round().string();
};