hyper/app/utils/colors.ts

35 lines
598 B
TypeScript
Raw Normal View History

const colorList = [
'black',
'red',
'green',
'yellow',
'blue',
'magenta',
'cyan',
'white',
'lightBlack',
'lightRed',
'lightGreen',
'lightYellow',
'lightBlue',
'lightMagenta',
'lightCyan',
'lightWhite',
'colorCubes',
'grayscale'
];
export const getColorMap: {
2019-10-03 01:54:25 -08:00
<T>(colors: T): T extends (infer U)[] ? {[k: string]: U} : T;
2020-03-25 02:15:08 -08:00
} = (colors) => {
if (!Array.isArray(colors)) {
return colors;
}
return colors.reduce((result, color, index) => {
if (index < colorList.length) {
result[colorList[index]] = color;
}
return result;
}, {});
};