]> git.r.bdr.sh - rbdr/forum/blame_incremental - app/utils/glyph_hash.js
Fix linter and linteer warnings
[rbdr/forum] / app / utils / glyph_hash.js
... / ...
CommitLineData
1const 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
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)}`
30 }
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};