Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
benborgers committed Mar 26, 2024
1 parent f56e7d7 commit 5d5f102
Show file tree
Hide file tree
Showing 5 changed files with 1,343 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.wrangler
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# emojicdn
52 changes: 52 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
export default {
async fetch(request) {
const url = new URL(request.url);
const path = url.pathname.replace(/^\/+|\/+$/g, "");

if (path === "") {
return Response.redirect("https://github.com/benborgers/emojicdn");
}

if (path === "favicon.ico") {
return new Response("");
}

function emojiToUnicodeCodePoints(emoji) {
// Get the code point for the emoji itself, in hexadecimal
let baseCodePoint = emoji.codePointAt(0).toString(16).toUpperCase();

// Initialize the result with the base emoji code point
let result = baseCodePoint;

// Check if there's a variation selector or another part (e.g., skin tone modifiers)
// Since an emoji can be composed of multiple code points, we use `Array.from` to split it properly
if (Array.from(emoji).length > 1) {
// Iterate through each character (considering surrogate pairs) in the emoji string after the first character
for (let i = 1; i < Array.from(emoji).length; i++) {
// Get the code point of the current part of the emoji, in hexadecimal
let additionalCodePoint = emoji
.codePointAt(i)
.toString(16)
.toUpperCase();

// Append the additional code point to the result string, with a dash
result += "-" + additionalCodePoint;

// Consider emojis that might be represented by more than one code point
// Adjust the loop counter by the number of code units the current code point takes up
// This is a precaution if emojis in future Unicode versions take up more than 2 code units
if (emoji.codePointAt(i) > 0xffff) {
i++; // Skip the next because we already handled a surrogate pair
}
}
}

return result;
}

console.log(decodeURIComponent(path));
console.log("HERE: " + emojiToUnicodeCodePoints(decodeURIComponent(path)));

return Response.json({});
},
};
Loading

0 comments on commit 5d5f102

Please sign in to comment.