Skip to content

Instantly share code, notes, and snippets.

@matjaz
Created December 31, 2022 00:29
Show Gist options
  • Save matjaz/d7a5cb57e7ca5c0cd1c34d35319c6c69 to your computer and use it in GitHub Desktop.
Save matjaz/d7a5cb57e7ca5c0cd1c34d35319c6c69 to your computer and use it in GitHub Desktop.
// Menu: Emoji
// Shortcut:
// Twitter: @vjthlk
// Author: Vojta Holik
/** @type {import("@johnlindquist/kit")} */
import "@johnlindquist/kit";
const { emojis, write } = await db("emojis-db", {
emojis: [],
});
let emojiPath = tmpPath(`emoji.json`);
if (!(await isFile(emojiPath))) {
await download(
`https://raw.githubusercontent.com/github/gemoji/master/db/emoji.json`,
tmpPath()
);
}
let emojiJson = await readJson(emojiPath);
debugger
let emojiJsonHistory = emojis.map((e) => {
return _.find(emojiJson, { emoji: e });
});
const mode = (arr) =>
arr.reduce(
(a, b, i, arr) =>
arr.filter((v) => v === a).length >= arr.filter((v) => v === b).length
? a
: b,
null
);
let mostUsed = mode(emojiJsonHistory);
let history = _.uniq(
[...emojiJsonHistory]
.filter((e) => e.description !== mostUsed.description)
.reverse()
);
let emojiList = [
...history.slice(0, 1),
mostUsed,
...history.slice(1, 5),
...emojiJson.filter((e) => {
return !history.includes(e);
}),
];
debugger
console.log(emojiList)
let selectedEmoji = await arg(
"Search",
emojiList.map((e) => {
return {
name: `${e.emoji} ${e.description}`,
description: `${e.category} ${!_.isEmpty(e.tags) ? "-" : ""} ${e.tags.map(
(tag) => ` ${tag}`
)}`,
value: e.emoji,
shortcode: e.tags.map((tag) => ` ${tag}`),
};
})
);
emojis.push(!selectedEmoji.name && selectedEmoji);
await write();
await setSelectedText(selectedEmoji);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment