]> git.r.bdr.sh - rbdr/forum/blobdiff - app/utils/glyph_hash.js
Add skeleton for topic
[rbdr/forum] / app / utils / glyph_hash.js
diff --git a/app/utils/glyph_hash.js b/app/utils/glyph_hash.js
new file mode 100644 (file)
index 0000000..c074376
--- /dev/null
@@ -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);
+};