]>
Commit | Line | Data |
---|---|---|
66dc4cae BB |
1 | const internals = { |
2 | kSplitterRegex: /.{1,8}/g, | |
58f7d521 | 3 | kGlyphs: ['☽', '☆', '♢', '♡', '╱', '╲', '╳', '〰', '▷', '⏊', '〒', '▢', '◯', '⏃', '⏀', '⏆'] |
66dc4cae BB |
4 | }; |
5 | ||
6 | // Return a glyph with color based on a 4 byte fragment of a UUIDv4 | |
7 | const getGlyphHashFragment = function (uuidFragment) { | |
8 | ||
58f7d521 | 9 | const glyphIndex = parseInt(uuidFragment.substring(0, 2), 16) % 16; |
66dc4cae BB |
10 | return { |
11 | glyph: internals.kGlyphs[glyphIndex], | |
58f7d521 | 12 | color: `#${uuidFragment.substring(2, 8)}` |
00a6e8aa | 13 | }; |
66dc4cae BB |
14 | }; |
15 | ||
16 | // Return an array of glyphs based on a UUIDv4 | |
17 | export const getGlyphHash = function (uuid) { | |
18 | ||
58f7d521 | 19 | const hashFragments = uuid.replace(/[-]/g, '').match(internals.kSplitterRegex); |
66dc4cae BB |
20 | return hashFragments.map(getGlyphHashFragment); |
21 | }; |