]>
git.r.bdr.sh - rbdr/forum/blob - src/utils/glyph_hash.js
2 kDehyphenRegex: /[-]/g,
3 kSplitterRegex: /.{1,8}/g,
22 unexpectedUUIDLength: class UnexpectedUUIDLength
extends Error
{
23 name
= 'UnexpectedUUIDLength';
24 message
= 'The provided string was not a valid UUIDv4, please provide a 32 character long string'
28 // Return a glyph with color based on a 4 byte fragment of a UUIDv4
29 const getGlyphHashFragment = function (uuidFragment
) {
31 const glyphIndex
= parseInt(uuidFragment
.substring(0, 2), 16) % 16;
33 glyph: internals
.kGlyphs
[glyphIndex
],
34 color: `#${uuidFragment.substring(2, 8)}`
38 // Return an array of glyphs based on a UUIDv4
39 export const getGlyphHash = function (uuid
) {
41 const dehyphenedUuid
= uuid
.replace(/[-]/g, '');
43 if (dehyphenedUuid
.length
!== 32) {
44 throw new internals
.unexpectedUUIDLength();
47 const hashFragments
= dehyphenedUuid
.match(internals
.kSplitterRegex
);
48 return hashFragments
.map(getGlyphHashFragment
);