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