Procházet zdrojové kódy

Add flag emoji lookup logic

Kirk Trombley před 4 roky
rodič
revize
fa84862f4e
1 změnil soubory, kde provedl 14 přidání a 0 odebrání
  1. 14 0
      client/src/domain/flagLookup.js

+ 14 - 0
client/src/domain/flagLookup.js

@@ -0,0 +1,14 @@
+// Based on https://stackoverflow.com/questions/42234666/
+
+const flagOffset = 0x1F1E6;
+const asciiOffset = 0x41;
+const flagShift = flagOffset - asciiOffset;
+
+const flagLookup = country => {
+  const upper = country.toUpperCase();
+  const firstChar = upper.charCodeAt(0) + flagShift;
+  const secondChar = upper.charCodeAt(1) + flagShift;
+  return String.fromCodePoint(firstChar, secondChar);
+};
+
+export default flagLookup;