2020-10-13 05:08:27 -04:00
|
|
|
|
import { initEmojiMap, EMOJI_VERSION } from '~/emoji';
|
2021-12-15 19:15:50 -05:00
|
|
|
|
import { CACHE_VERSION_KEY, CACHE_KEY } from '~/emoji/constants';
|
2020-10-13 05:08:27 -04:00
|
|
|
|
|
2021-12-15 19:15:50 -05:00
|
|
|
|
export const validEmoji = {
|
2020-10-13 05:08:27 -04:00
|
|
|
|
atom: {
|
|
|
|
|
moji: '⚛',
|
|
|
|
|
description: 'atom symbol',
|
|
|
|
|
unicodeVersion: '4.1',
|
|
|
|
|
aliases: ['atom_symbol'],
|
|
|
|
|
},
|
|
|
|
|
bomb: {
|
|
|
|
|
moji: '💣',
|
|
|
|
|
unicodeVersion: '6.0',
|
|
|
|
|
description: 'bomb',
|
|
|
|
|
},
|
|
|
|
|
construction_worker_tone5: {
|
|
|
|
|
moji: '👷🏿',
|
|
|
|
|
unicodeVersion: '8.0',
|
|
|
|
|
description: 'construction worker tone 5',
|
|
|
|
|
},
|
|
|
|
|
five: {
|
|
|
|
|
moji: '5️⃣',
|
|
|
|
|
unicodeVersion: '3.0',
|
|
|
|
|
description: 'keycap digit five',
|
|
|
|
|
},
|
|
|
|
|
grey_question: {
|
|
|
|
|
moji: '❔',
|
|
|
|
|
unicodeVersion: '6.0',
|
|
|
|
|
description: 'white question mark ornament',
|
2020-10-14 11:08:42 -04:00
|
|
|
|
},
|
|
|
|
|
black_heart: {
|
|
|
|
|
moji: '🖤',
|
|
|
|
|
unicodeVersion: '1.1',
|
|
|
|
|
description: 'black heart',
|
|
|
|
|
},
|
|
|
|
|
heart: {
|
|
|
|
|
moji: '❤',
|
|
|
|
|
unicodeVersion: '1.1',
|
|
|
|
|
description: 'heavy black heart',
|
|
|
|
|
},
|
|
|
|
|
custard: {
|
|
|
|
|
moji: '🍮',
|
|
|
|
|
unicodeVersion: '6.0',
|
|
|
|
|
description: 'custard',
|
|
|
|
|
},
|
|
|
|
|
star: {
|
|
|
|
|
moji: '⭐',
|
|
|
|
|
unicodeVersion: '5.1',
|
|
|
|
|
description: 'white medium star',
|
2020-10-13 05:08:27 -04:00
|
|
|
|
},
|
2021-12-15 19:15:50 -05:00
|
|
|
|
gay_pride_flag: {
|
|
|
|
|
moji: '🏳️🌈',
|
|
|
|
|
unicodeVersion: '7.0',
|
|
|
|
|
description: 'because it contains a zero width joiner',
|
|
|
|
|
},
|
|
|
|
|
family_mmb: {
|
|
|
|
|
moji: '👨👨👦',
|
|
|
|
|
unicodeVersion: '6.0',
|
|
|
|
|
description: 'because it contains multiple zero width joiners',
|
|
|
|
|
},
|
2022-06-10 11:09:22 -04:00
|
|
|
|
thumbsup: {
|
|
|
|
|
moji: '👍',
|
|
|
|
|
unicodeVersion: '6.0',
|
|
|
|
|
description: 'thumbs up sign',
|
|
|
|
|
},
|
|
|
|
|
thumbsdown: {
|
|
|
|
|
moji: '👎',
|
|
|
|
|
description: 'thumbs down sign',
|
|
|
|
|
unicodeVersion: '6.0',
|
|
|
|
|
},
|
2021-12-15 19:15:50 -05:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const invalidEmoji = {
|
2021-09-01 05:10:58 -04:00
|
|
|
|
xss: {
|
|
|
|
|
moji: '<img src=x onerror=prompt(1)>',
|
|
|
|
|
unicodeVersion: '5.1',
|
|
|
|
|
description: 'xss',
|
|
|
|
|
},
|
2021-12-15 19:15:50 -05:00
|
|
|
|
non_moji: {
|
|
|
|
|
moji: 'I am not an emoji...',
|
|
|
|
|
unicodeVersion: '9.0',
|
|
|
|
|
description: '...and should be filtered out',
|
|
|
|
|
},
|
|
|
|
|
multiple_moji: {
|
|
|
|
|
moji: '🍂🏭',
|
|
|
|
|
unicodeVersion: '9.0',
|
|
|
|
|
description: 'Multiple separate emoji that are not joined by a zero width joiner',
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const emojiFixtureMap = {
|
|
|
|
|
...validEmoji,
|
|
|
|
|
...invalidEmoji,
|
2020-10-13 05:08:27 -04:00
|
|
|
|
};
|
|
|
|
|
|
2021-02-06 04:09:11 -05:00
|
|
|
|
export const mockEmojiData = Object.keys(emojiFixtureMap).reduce((acc, k) => {
|
|
|
|
|
const { moji: e, unicodeVersion: u, category: c, description: d } = emojiFixtureMap[k];
|
|
|
|
|
acc[k] = { name: k, e, u, c, d };
|
2020-10-14 11:08:42 -04:00
|
|
|
|
|
2021-02-06 04:09:11 -05:00
|
|
|
|
return acc;
|
|
|
|
|
}, {});
|
2020-10-13 05:08:27 -04:00
|
|
|
|
|
2021-12-15 19:15:50 -05:00
|
|
|
|
export function clearEmojiMock() {
|
|
|
|
|
localStorage.clear();
|
|
|
|
|
initEmojiMap.promise = null;
|
|
|
|
|
}
|
2020-10-13 05:08:27 -04:00
|
|
|
|
|
2021-12-15 19:15:50 -05:00
|
|
|
|
export async function initEmojiMock(mockData = mockEmojiData) {
|
|
|
|
|
clearEmojiMock();
|
|
|
|
|
localStorage.setItem(CACHE_VERSION_KEY, EMOJI_VERSION);
|
|
|
|
|
localStorage.setItem(CACHE_KEY, JSON.stringify(mockData));
|
2020-10-13 05:08:27 -04:00
|
|
|
|
await initEmojiMap();
|
|
|
|
|
}
|