MCPcopy Create free account
hub / github.com/NomicFoundation/hardhat / selectColor

Function selectColor

packages/hardhat-utils/src/internal/debug.ts:92–109  ·  view source on GitHub ↗
(namespace: string)

Source from the content-addressed store, hash-verified

90 * distribute Hardhat's namespaces more evenly across the palette.
91 */
92export 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.

Callers 2

debug.tsFile · 0.85
createDebugFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected