1 export type GlyphHash = GlyphHashFragment[];
2 type GlyphHashFragment = {
8 kDehyphenRegex: /[-]/g,
9 kSplitterRegex: /.{1,8}/g,
28 unexpectedUUIDLength: class UnexpectedUUIDLength extends Error {
29 name = 'UnexpectedUUIDLength';
30 message = 'The provided string was not a valid UUIDv4, please provide a 32 character long string'
34 // Return a glyph with color based on a 4 byte fragment of a UUIDv4
35 const getGlyphHashFragment = function (uuidFragment: string): GlyphHashFragment {
37 const glyphIndex = parseInt(uuidFragment.substring(0, 2), 16) % 16;
39 glyph: internals.kGlyphs[glyphIndex],
40 color: `#${uuidFragment.substring(2, 8)}`
44 // Return an array of glyphs based on a UUIDv4
45 export const getGlyphHash = function (uuid: string): GlyphHash {
47 const dehyphenedUuid = uuid.replace(/[-]/g, '');
49 if (dehyphenedUuid.length !== 32) {
50 throw new internals.unexpectedUUIDLength();
53 const hashFragments = dehyphenedUuid.match(internals.kSplitterRegex);
54 return hashFragments.map(getGlyphHashFragment);