added tests

This commit is contained in:
ewwwwwwww 2022-07-07 15:33:55 -07:00
parent a6e56b131c
commit b1f5902397
4 changed files with 1874 additions and 26 deletions

File diff suppressed because it is too large Load diff

View file

@ -68,23 +68,10 @@ const convertCustom = (shortname: string, filename: string) => {
return `<img draggable="false" class="emojione" alt="${shortname}" title="${shortname}" src="${filename}" />`;
};
function replaceAll(str: string, find: string, replace: string) {
return str.replace(new RegExp(find, 'g'), replace);
}
const convertUnicode = (c: string) => {
const { unified, shortcode } = unicodeMapping[c];
let hex;
// TODO: move to mapping.ts
if (unified.includes('200d') && unified !== '1f441-fe0f-200d-1f5e8-fe0f') {
hex = unified;
} else {
hex = replaceAll(unified, '-fe0f', '');
}
return `<img draggable="false" class="emojione" alt="${c}" title=":${shortcode}:" src="/packs/emoji/${hex}.svg" />`;
return `<img draggable="false" class="emojione" alt="${c}" title=":${shortcode}:" src="/packs/emoji/${unified}.svg" />`;
};
const convertEmoji = (str: string, customEmojis: any) => {

View file

@ -1,5 +1,11 @@
import data, { EmojiData } from './data';
const stripLeadingZeros = /^0+/;
function replaceAll(str: string, find: string, replace: string) {
return str.replace(new RegExp(find, 'g'), replace);
}
interface UnicodeMap {
[s: string]: {
unified: string,
@ -15,9 +21,17 @@ export const generateMappings = (data: EmojiData): UnicodeMap => {
// @ts-ignore
for (const item of value.skins) {
const { unified, native } = item;
const stripped = unified.replace(stripLeadingZeros, '');
// @ts-ignore
result[native] = { unified, shortcode: value.id };
if (unified.includes('200d') && unified !== '1f441-fe0f-200d-1f5e8-fe0f') {
// @ts-ignore
result[native] = { unified: stripped, shortcode: value.id };
} else {
const twemojiCode = replaceAll(stripped, '-fe0f', '');
// @ts-ignore
result[native] = { unified: twemojiCode, shortcode: value.id };
}
}
}

View file

@ -5039,11 +5039,6 @@ emoji-regex@^9.0.0:
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-9.2.2.tgz#840c8803b0d8047f4ff0cf963176b32d4ef3ed72"
integrity sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==
emoji-unicode@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/emoji-unicode/-/emoji-unicode-2.0.1.tgz#37b05f0cd20254fd366d1df4442b5c613a3a021a"
integrity sha512-jjswgV5nR3KDqtC9ugzEOYQaBLLQP5hqaH2tiTBaq9maYpMnmvl9T+ogY3u2bN6O5NAP0Ddh9D+Meo7sfW/1uw==
emojis-list@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-2.1.0.tgz#4daa4d9db00f9819880c79fa457ae5b09a1fd389"