UNPKG

947 BJavaScriptView Raw
1
2import { category } from './swu-structure';
3import { parse } from './swu-parse';
4import { swu2code } from '../convert';
5
6/**
7 * Array of colors associated with the seven symbol categories.
8 * @alias swu.colors
9 * @type {array}
10 */
11const colors = ['#0000CC', '#CC0000', '#FF0099', '#006600', '#000000', '#884411', '#FF9900'];
12
13/**
14 * Function that returns the standardized color for a symbol.
15 * @function swu.colorize
16 * @param {string} swuSym - an SWU symbol character
17 * @returns {string} name of standardized color for symbol
18 * @example
19 * swu.colorize('񀀁')
20 *
21 * return '#0000CC'
22 */
23const colorize = (swuSym) => {
24 const parsed = parse.symbol(swuSym);
25 let color = '#000000';
26 if (parsed.symbol) {
27 const code = swu2code(parsed.symbol);
28 const index = category.findIndex((val) => val > code);
29 color = colors[(index < 0 ? 6 : index - 1)];
30 }
31 return color;
32}
33
34export { colors, colorize }