-
Notifications
You must be signed in to change notification settings - Fork 0
/
openmoji-convert.ts
83 lines (76 loc) · 1.91 KB
/
openmoji-convert.ts
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Compile the openmoji data into a more slimline format
import openmojiData from './node_modules/openmoji/data/openmoji.json'
import { readFile, writeFile, mkdir } from 'node:fs/promises'
import path from 'node:path'
const openMojiIcons = (
openmojiData as {
emoji: string // e.g. "😀",
hexcode: string // e.g. "1F600",
group: string // e.g. "smileys-emotion",
subgroups: string // e.g. "face-smiling",
annotation: string // e.g. "grinning face",
tags: string // e.g. "face, grin",
openmoji_tags: string // e.g. "smile, happy",
openmoji_author: string // e.g. "Emily Jäger",
openmoji_date: string // e.g. "2018-04-18",
skintone: string // e.g. "",
skintone_combination: string // e.g. "",
skintone_base_emoji: string // e.g. "",
skintone_base_hexcode: string // e.g. "",
unicode: number // e.g. 1,
order: number // e.g. 1
}[]
)
.sort(({ order: o1 }, { order: o2 }) => o2 - o1)
.map(
({
emoji, // '😀',
hexcode, // '1F600',
annotation, // 'grinning face',
tags, // 'face, grin',
}) => ({
emoji,
search: `${annotation}${tags.length > 0 ? ` (${tags})` : ''}`,
hexcode,
}),
)
try {
await mkdir(path.join(process.cwd(), 'static', 'openmoji'))
} catch {
// pass
}
try {
await mkdir(path.join(process.cwd(), 'src', 'openmoji'))
} catch {
// pass
}
for (const { hexcode } of openMojiIcons) {
const svgColor = (
await readFile(
path.join(
process.cwd(),
'node_modules',
'openmoji',
'color',
'svg',
`${hexcode}.svg`,
),
'utf-8',
)
)
.replace('id="emoji"', 'class="openmoji"')
.replace(/id="[^"]+"/g, '')
.replace(/[a-z]+:[a-z]+="[^"]+"/gi, '')
await writeFile(
path.join('static', 'openmoji', `${hexcode}.svg`),
svgColor,
'utf-8',
)
}
await writeFile(
path.join(process.cwd(), 'static', 'openmoji', 'list.json'),
JSON.stringify(
openMojiIcons.map(({ hexcode, search, emoji }) => [hexcode, search, emoji]),
),
'utf-8',
)