color.js 834 B

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