aboutsummaryrefslogtreecommitdiff
path: root/app/utils/glyph_hash.js
blob: 120c02ace705490c7ceeea0a723554ae48aa2504 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const internals = {
  kSplitterRegex: /.{1,8}/g,
  kGlyphs: [
    '☽',
    '☆',
    '♢',
    '♡',
    '╱',
    '╲',
    '╳',
    '〰',
    '▷',
    '⏊',
    '〒',
    '▢',
    '◯',
    '⏃',
    '⏀',
    '⏆'
  ]
};

// Return a glyph with color based on a 4 byte fragment of a UUIDv4
const getGlyphHashFragment = function (uuidFragment) {

  const glyphIndex = parseInt(uuidFragment.substring(0,2), 16) % 16;
  return {
    glyph: internals.kGlyphs[glyphIndex],
    color: `#${uuidFragment.substring(2,8)}`
  };
};

// Return an array of glyphs based on a UUIDv4
export const getGlyphHash = function (uuid) {

  const hashFragments = uuid.match(internals.kSplitterRegex);
  return hashFragments.map(getGlyphHashFragment);
};