Usage

import {githubEmojiUrl} from "https://esm.town/v/karfau/githubEmoji";
console.log(githubEmojiUrl('+1'))
//"https://github.githubassets.com/images/icons/emoji/unicode/1f44d.png?v8" 

or in a browser

<img src="https://karfau-githubEmoji.web.val.run/+1"></img>

Looks like in the preview.

curl https://karfau-githubEmoji.web.val.run/+1

(prints "https://github.githubassets.com/images/icons/emoji/unicode/1f44d.png?v8")


If the name you pass (as argument or in the request path) is not in the list, it returns octocat

The list of names can be accessed using githubEmojiNames or by calling https://karfau-githubemoji.web.val.run/names

Readme
Fork
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { GITHUB_EMOJIS } from "https://esm.town/v/karfau/GITHUB_EMOJIS";
import { fetch } from "https://esm.town/v/std/fetch?v=4";
export const isEmoji = (key: string) => Object.hasOwn(GITHUB_EMOJIS, key);
export const githubEmojiUrl = (name: string, fallback = "octocat"): string =>
GITHUB_EMOJIS[isEmoji(name) ? name : fallback];
export const githubEmojiNames = (): string[] => Object.keys(GITHUB_EMOJIS);
export default async function githubEmoji(req: Request): Promise<Response> {
const contentType = req.headers.get("Content-Type");
const nameFromURL = new URL(req.url).pathname.split("/").filter(Boolean)[0];
if (nameFromURL === "names") {
return Response.json(githubEmojiNames());
}
const url = githubEmojiUrl(nameFromURL);
if (contentType || contentType === "application/json") {
return Response.json(url);
}
try {
return fetch(url);
} catch (error) {
console.error(req.url, nameFromURL, error);
return new Response(
"<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"64\" height=\"64\" viewBox=\"218.329 117.251 67.385 67.385\" xml:space=\"preserve\"><path style=\"stroke:#e9d535;stroke-width:0;stroke-dasharray:none;stroke-linecap:butt;stroke-dashoffset:0;stroke-li
{ headers: { "Content-Type": "image/svg" }, status: 307, statusText: "Currently not available" },
);
}
}
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.
Comments
stevekrouse avatar

Awesome! I reformatted your REAMDE: https://www.val.town/v/stevekrouse/githubEmoji

Feel free to ignore or take from that whatever is useful.

To get the raw text of it, fork it to a new val, then edit it, and then copy and paste it where you want. We'll make this flow easier with pull requests soon!