]> git.r.bdr.sh - rbdr/forum/blame - app/utils/glyph_hash.js
Remove server
[rbdr/forum] / app / utils / glyph_hash.js
CommitLineData
66dc4cae
BB
1const internals = {
2 kSplitterRegex: /.{1,8}/g,
3 kGlyphs: [
41247723
BB
4 '☽',
5 '☆',
6 '♢',
7 '♡',
8 '╱',
9 '╲',
10 '╳',
11 '〰',
12 '▷',
13 '⏊',
14 '〒',
15 '▢',
16 '◯',
17 '⏃',
18 '⏀',
19 '⏆'
66dc4cae
BB
20 ]
21};
22
23// Return a glyph with color based on a 4 byte fragment of a UUIDv4
24const 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)}`
00a6e8aa 30 };
66dc4cae
BB
31};
32
33// Return an array of glyphs based on a UUIDv4
34export const getGlyphHash = function (uuid) {
35
36 const hashFragments = uuid.match(internals.kSplitterRegex);
37 return hashFragments.map(getGlyphHashFragment);
38};