(str)
| 169 | * Useful for colorizing strings consistenyl based on their content. |
| 170 | */ |
| 171 | const stringToSafeColor = (str) => { |
| 172 | let hash = 0 |
| 173 | for (let i = 0; i < str.length; i++) { |
| 174 | hash = str.charCodeAt(i) + ((hash << 5) - hash) |
| 175 | } |
| 176 | |
| 177 | const base = 128 |
| 178 | const range = 127 |
| 179 | |
| 180 | const red = base + (hash & range) |
| 181 | const green = base + ((hash >> 8) & range) |
| 182 | const blue = base + ((hash >> 16) & range) |
| 183 | |
| 184 | return chalk.rgb(red, green, blue) |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Colorize a string based on its "safe" color |
no outgoing calls
no test coverage detected
searching dependent graphs…