/* * The colors we support generating an Avatar background color from a "seed" for. * Changing this array will change the assignment between seeds. * Do not change this array. */ const avatarColors = [ 'var(--color-bright-blue)', 'var(--color-bright-yellow)', 'var(--color-bright-pink)', 'var(--color-bright-orange)', ] as const; /* * Takes in a "seed" string and spits out an index for the color we should use. * This implementation has been synced across all three clients so that we consistently * generate branded avatar colors when rendering a list of Avatars. * Do not change this implementation. */ const hashSeed = (seed: string): number => { const base = 31; const modulo = avatarColors.length; let hashValue = 0; let basePow = 1; for (let i = 0; i < seed.length; i += 1) { hashValue = (hashValue + seed.charCodeAt(i) * basePow) % modulo; basePow = (basePow * base) % modulo; } return hashValue; }; export const getBrandColorFromSeed = (seed: string): (typeof avatarColors)[number] => { return avatarColors[hashSeed(seed)]; };