From bd8e98d7e24c4dbaee7db6ec7955f7c2f6d396a6 Mon Sep 17 00:00:00 2001 From: Ruben Beltran del Rio Date: Tue, 9 Mar 2021 22:43:12 +0100 Subject: Update to SvelteKit --- src/utils/glyph_hash.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/utils/glyph_hash.js (limited to 'src/utils') diff --git a/src/utils/glyph_hash.js b/src/utils/glyph_hash.js new file mode 100644 index 0000000..120c02a --- /dev/null +++ b/src/utils/glyph_hash.js @@ -0,0 +1,38 @@ +const internals = { + kSplitterRegex: /.{1,8}/g, + kGlyphs: [ + '☽', + '☆', + '♢', + '♡', + '╱', + '╲', + '╳', + '〰', + '▷', + '⏊', + '〒', + '▢', + '◯', + '⏃', + '⏀', + '⏆' + ] +}; + +// Return a glyph with color based on a 4 byte fragment of a UUIDv4 +const getGlyphHashFragment = function (uuidFragment) { + + const glyphIndex = parseInt(uuidFragment.substring(0,2), 16) % 16; + return { + glyph: internals.kGlyphs[glyphIndex], + color: `#${uuidFragment.substring(2,8)}` + }; +}; + +// Return an array of glyphs based on a UUIDv4 +export const getGlyphHash = function (uuid) { + + const hashFragments = uuid.match(internals.kSplitterRegex); + return hashFragments.map(getGlyphHashFragment); +}; -- cgit