Skip to content
This repository was archived by the owner on Mar 1, 2025. It is now read-only.

Commit 3ce15b5

Browse files
committed
feat: update emoji version handling to correctly map unicode versions and simplify sorting logic
1 parent 49bf2cf commit 3ce15b5

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/utils.ts

+24-7
Original file line numberDiff line numberDiff line change
@@ -118,23 +118,40 @@ export async function getAllEmojiVersions(): Promise<EmojiVersion[]> {
118118
// if it does, we will update the emoji version.
119119
const existing = versions.find((v) => v.unicode_version === version);
120120

121+
let unicode_version = null;
122+
123+
// the emoji version 13.1 is using the unicode
124+
// 13.0, since it was never released.
125+
if (match[1] === "13.1") {
126+
unicode_version = "13.0.0";
127+
}
128+
129+
if (match[1] === "5.0") {
130+
unicode_version = "10.0.0";
131+
}
132+
133+
if (match[1] === "4.0" || match[1] === "3.0") {
134+
unicode_version = "9.0.0";
135+
}
136+
137+
if (match[1] === "2.0" || match[1] === "1.0") {
138+
unicode_version = "8.0.0";
139+
}
140+
121141
if (existing) {
142+
existing.unicode_version = unicode_version || existing.unicode_version;
122143
existing.emoji_version = match[1];
123144
continue;
124145
}
125146

126147
versions.push({
127148
emoji_version: match[1],
128-
unicode_version: null,
149+
unicode_version,
129150
draft: version === draft,
130151
});
131152
}
132153

133-
return versions.sort((a, b) => {
134-
const versionA = a.unicode_version ?? `${a.emoji_version}.0`;
135-
const versionB = b.unicode_version ?? `${b.emoji_version}.0`;
136-
return semver.compare(versionB, versionA);
137-
});
154+
return versions.sort((a, b) => semver.compare(`${b.emoji_version}.0`, `${a.emoji_version}.0`));
138155
}
139156

140157
/**
@@ -166,7 +183,7 @@ export async function isEmojiVersionValid(version: string): Promise<boolean> {
166183
// from v1 to v5, there was only major releases. So no v1.1, v1.2, etc.
167184
// only, v1.0, v2.0, v3.0, v4.0, v5.0.
168185
// if version has any minor or patch, it is invalid.
169-
if (semver.minor(version) !== 0 || semver.patch(version) !== 0) {
186+
if (semver.major(version) <= 5 && (semver.minor(version) !== 0 || semver.patch(version) !== 0)) {
170187
return false;
171188
}
172189

0 commit comments

Comments
 (0)