Advertisement
smhdale

ColourGenerator class

Jun 2nd, 2019
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ColourGenerator {
  2.   constructor () {
  3.     this.map = new Map()
  4.   }
  5.  
  6.   newColour (name) {
  7.     const colour = '#'+((1<<24)*Math.random()|0).toString(16).padStart(6,'0')
  8.     this.map.set(name, colour)
  9.   }
  10.  
  11.   getColour (name) {
  12.     if (!this.map.has(name)) this.newColour(name)
  13.     return this.map.get(name)
  14.   }
  15. }
  16.  
  17. module.exports = new ColourGenerator()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement