]> git.r.bdr.sh - rbdr/forum/blame_incremental - src/utils/glyph_hash.js
Update the config
[rbdr/forum] / src / utils / glyph_hash.js
... / ...
CommitLineData
1const 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
7const 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
17export const getGlyphHash = function (uuid) {
18
19 const hashFragments = uuid.replace(/[-]/g, '').match(internals.kSplitterRegex);
20 return hashFragments.map(getGlyphHashFragment);
21};