-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement emoji generation #4
Changes from 12 commits
7f4278a
4d9672f
c0717dd
ed009eb
eea2c37
7eb8130
b8dadc5
071afb2
c49edcf
b314647
aa607a1
b25d8e7
4c21308
49bf2cf
3ce15b5
fdf063f
5e9706e
7c5b445
cae0e52
d6453b5
8730e21
9fcf29e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import type { EmojiSequence, EmojiVariation } from "../types"; | ||
import type { Emoji, EmojiData, EmojiSequence, EmojiShortcode, EmojiVariation, Property, ShortcodeProvider } from "../types"; | ||
Check failure on line 1 in src/adapter/v16.ts
|
||
import { defineMojiAdapter } from "../adapter"; | ||
import { FEMALE_SIGN, MALE_SIGN } from "../constants"; | ||
import { extractEmojiVersion, extractUnicodeVersion } from "../utils"; | ||
import { fetchCache } from "../utils/cache"; | ||
import { expandHexRange } from "../utils/hexcode"; | ||
|
||
|
@@ -12,12 +13,12 @@ | |
sequences: async (ctx) => { | ||
const [sequences, zwj] = await Promise.all([ | ||
{ | ||
cacheKey: `v${ctx.version}/sequences.json`, | ||
url: `https://unicode.org/Public/emoji/${ctx.version}/emoji-sequences.txt`, | ||
cacheKey: `v${ctx.emojiVersion}/sequences.json`, | ||
url: `https://unicode.org/Public/emoji/${ctx.emojiVersion}/emoji-sequences.txt`, | ||
}, | ||
{ | ||
cacheKey: `v${ctx.version}/zwj-sequences.json`, | ||
url: `https://unicode.org/Public/emoji/${ctx.version}/emoji-zwj-sequences.txt`, | ||
cacheKey: `v${ctx.emojiVersion}/zwj-sequences.json`, | ||
url: `https://unicode.org/Public/emoji/${ctx.emojiVersion}/emoji-zwj-sequences.txt`, | ||
}, | ||
].map(async ({ cacheKey, url }) => { | ||
return await fetchCache(url, { | ||
|
@@ -28,7 +29,7 @@ | |
const sequences: EmojiSequence[] = []; | ||
|
||
for (let line of lines) { | ||
// skip empty line & comments | ||
// skip empty line & comments | ||
if (line.trim() === "" || line.startsWith("#")) { | ||
continue; | ||
} | ||
|
@@ -68,11 +69,87 @@ | |
zwj: zwj || [], | ||
}; | ||
}, | ||
async emojis({ version, force }) { | ||
async emojis(ctx) { | ||
const unicodeNames = await this.unicodeNames!(ctx); | ||
const { sequences, zwj } = await this.sequences!(ctx); | ||
Check failure on line 74 in src/adapter/v16.ts
|
||
const metadata = await this.metadata!(ctx); | ||
const variations = await this.variations!(ctx); | ||
|
||
const emojis: Record<string, Emoji> = {}; | ||
|
||
const emojiData = await fetchCache(`https://unicode.org/Public/${ctx.emojiVersion}.0/ucd/emoji/emoji-data.txt`, { | ||
cacheKey: `v${ctx.emojiVersion}/emoji-data.json`, | ||
parser(data) { | ||
const lines = data.split("\n"); | ||
|
||
const emojiData: Record<string, EmojiData> = {}; | ||
|
||
for (const line of lines) { | ||
// skip empty line & comments | ||
if (line.trim() === "" || line.startsWith("#")) { | ||
continue; | ||
} | ||
|
||
const lineCommentIndex = line.indexOf("#"); | ||
const lineComment = lineCommentIndex !== -1 ? line.slice(lineCommentIndex + 1).trim() : ""; | ||
|
||
let [hex, property] = line.split(";").map((col) => col.trim()).slice(0, 4); | ||
|
||
if (hex == null || property == null) { | ||
throw new Error(`invalid line: ${line}`); | ||
} | ||
|
||
// remove line comment from property | ||
const propertyCommentIndex = property.indexOf("#"); | ||
if (propertyCommentIndex !== -1) { | ||
property = property.slice(0, propertyCommentIndex).trim(); | ||
} | ||
|
||
if (property === "Extended_Pictographic") { | ||
continue; | ||
} | ||
|
||
const expandedHex = expandHexRange(hex); | ||
const emojiVersion = extractEmojiVersion(lineComment); | ||
|
||
const emoji: EmojiData = { | ||
description: lineComment, | ||
hexcode: "", | ||
gender: null, | ||
properties: [(property as Property) || "Emoji"], | ||
unicodeVersion: extractUnicodeVersion(emojiVersion, ctx.unicodeVersion), | ||
emojiVersion, | ||
name: unicodeNames[hex] || "", | ||
}; | ||
|
||
for (const hex of expandedHex) { | ||
if (emojiData[hex] != null) { | ||
emojiData[hex].properties = [...new Set([...emojiData[hex].properties, ...emoji.properties])]; | ||
} else { | ||
emojiData[hex] = { | ||
...emoji, | ||
hexcode: hex.replace(/\s+/g, "-"), | ||
}; | ||
} | ||
} | ||
} | ||
|
||
return emojiData; | ||
}, | ||
bypassCache: ctx.force, | ||
}); | ||
|
||
// join names, metadata, variations, sequences, zwj | ||
|
||
for (const [hex, data] of Object.entries(emojiData)) { | ||
Check failure on line 144 in src/adapter/v16.ts
|
||
|
||
} | ||
|
||
return {}; | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Complete the implementation of the The function has several issues:
Please complete the implementation by using the fetched data to construct and return the emoji objects. 🧰 Tools🪛 GitHub Check: build[failure] 74-74: [failure] 74-74: [failure] 75-75: [failure] 76-76: [failure] 78-78: [failure] 144-144: [failure] 144-144: 🪛 ESLint[error] 74-74: 'sequences' is assigned a value but never used. Allowed unused vars must match /^_/u. (unused-imports/no-unused-vars) [error] 74-74: 'zwj' is assigned a value but never used. Allowed unused vars must match /^_/u. (unused-imports/no-unused-vars) [error] 75-75: 'metadata' is assigned a value but never used. Allowed unused vars must match /^_/u. (unused-imports/no-unused-vars) [error] 76-76: 'variations' is assigned a value but never used. Allowed unused vars must match /^_/u. (unused-imports/no-unused-vars) [error] 78-78: 'emojis' is assigned a value but never used. Allowed unused vars must match /^_/u. (unused-imports/no-unused-vars) [error] 144-144: 'hex' is assigned a value but never used. Allowed unused vars must match /^_/u. (unused-imports/no-unused-vars) [error] 144-144: 'data' is assigned a value but never used. Allowed unused vars must match /^_/u. (unused-imports/no-unused-vars) [error] 144-146: Empty block statement. (no-empty) |
||
variations: async (ctx) => { | ||
return fetchCache(`https://unicode.org/Public/${ctx.version}.0/ucd/emoji/emoji-variation-sequences.txt`, { | ||
cacheKey: `v${ctx.version}/variations.json`, | ||
return fetchCache(`https://unicode.org/Public/${ctx.emojiVersion}.0/ucd/emoji/emoji-variation-sequences.txt`, { | ||
cacheKey: `v${ctx.emojiVersion}/variations.json`, | ||
parser(data) { | ||
const lines = data.split("\n"); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unused import.
The
EmojiData
type is imported but never used, as flagged by static analysis.📝 Committable suggestion
🧰 Tools
🪛 GitHub Check: build
[failure] 1-1:
'EmojiData' is defined but never used
🪛 ESLint
[error] 1-1: 'EmojiData' is defined but never used.
(unused-imports/no-unused-imports)
🪛 GitHub Actions: CI
[error] 1-1: 'EmojiData' is defined but never used