]> git.r.bdr.sh - rbdr/forum/blob - src/utils/glyph_hash.js
120c02ace705490c7ceeea0a723554ae48aa2504
[rbdr/forum] / src / utils / glyph_hash.js
1 const internals = {
2 kSplitterRegex: /.{1,8}/g,
3 kGlyphs: [
4 '☽',
5 '☆',
6 '♢',
7 '♡',
8 '╱',
9 '╲',
10 '╳',
11 '〰',
12 '▷',
13 '⏊',
14 '〒',
15 '▢',
16 '◯',
17 '⏃',
18 '⏀',
19 '⏆'
20 ]
21 };
22
23 // Return a glyph with color based on a 4 byte fragment of a UUIDv4
24 const getGlyphHashFragment = function (uuidFragment) {
25
26 const glyphIndex = parseInt(uuidFragment.substring(0,2), 16) % 16;
27 return {
28 glyph: internals.kGlyphs[glyphIndex],
29 color: `#${uuidFragment.substring(2,8)}`
30 };
31 };
32
33 // Return an array of glyphs based on a UUIDv4
34 export const getGlyphHash = function (uuid) {
35
36 const hashFragments = uuid.match(internals.kSplitterRegex);
37 return hashFragments.map(getGlyphHashFragment);
38 };