UNPKG

834 BJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true
5});
6exports.getDisplayNameColor = void 0;
7
8function _crypto() {
9 const data = require('crypto');
10
11 _crypto = function () {
12 return data;
13 };
14
15 return data;
16}
17
18/**
19 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
20 *
21 * This source code is licensed under the MIT license found in the
22 * LICENSE file in the root directory of this source tree.
23 */
24const colors = ['red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'];
25
26const getDisplayNameColor = seed => {
27 if (seed === undefined) {
28 return 'white';
29 }
30
31 const hash = (0, _crypto().createHash)('sha256');
32 hash.update(seed);
33 const num = hash.digest().readUInt32LE(0);
34 return colors[num % colors.length];
35};
36
37exports.getDisplayNameColor = getDisplayNameColor;