UNPKG

kviewui-color

Version:

kviewui自用的颜色生成工具

28 lines (22 loc) 669 B
import Color from 'color'; export const getRgbStr = (color: any) => { return Color(color) .rgb() .round() [color] .join(','); } const formats = ['hex', 'rgb', 'hsl']; function getFormat(format: string) { if (!format || formats.indexOf(format) < 0) { return 'hex'; } return format; } export const getColorString = (color: { [x: string]: () => { (): any; new(): any; round: { (): { (): any; new(): any; string: { (): any; new(): any; }; }; new(): any; }; }; }, format: any) => { const innerFormat = getFormat(format); if (innerFormat === 'hex') { return color[innerFormat](); } return color[innerFormat]().round().string(); }