(namespace: string)
| 90 | * distribute Hardhat's namespaces more evenly across the palette. |
| 91 | */ |
| 92 | export function selectColor(namespace: string): number { |
| 93 | let hash = 0x811c9dc5; |
| 94 | |
| 95 | for (let i = 0; i < namespace.length; i++) { |
| 96 | // eslint-disable-next-line no-bitwise -- FNV-1a hash |
| 97 | hash ^= namespace.charCodeAt(i); |
| 98 | hash = Math.imul(hash, 0x01000193); |
| 99 | } |
| 100 | |
| 101 | // xorshift finalizer for better avalanche on the low bits |
| 102 | /* eslint-disable no-bitwise -- xorshift finalizer */ |
| 103 | hash ^= hash >>> 16; |
| 104 | hash = Math.imul(hash, 0x85ebca6b); |
| 105 | hash ^= hash >>> 13; |
| 106 | /* eslint-enable no-bitwise */ |
| 107 | |
| 108 | return COLORS[Math.abs(hash) % COLORS.length]; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Reports whether ANSI colours should be used, honouring `DEBUG_COLORS` and TTY. |
no outgoing calls
no test coverage detected