UserColors.js 385 B

12345678910111213141516171819
  1. class UserColors {
  2. constructor() {
  3. this.colors = ["#F6511D", "#FFB400", "#00A6ED", "#7FB800", "#0D2C54"];
  4. this.i = 0;
  5. this.map = new Map();
  6. }
  7. getColor(userId) {
  8. let color = this.map.get(userId);
  9. if (color === undefined) {
  10. color = this.colors[this.i++];
  11. this.map.set(userId, color);
  12. }
  13. return color;
  14. }
  15. }
  16. module.exports = { UserColors };