2017-06-23 19:08:06 +00:00
|
|
|
import emojiMap from 'emojis/digests.json';
|
|
|
|
import emojiAliases from 'emojis/aliases.json';
|
|
|
|
import getUnicodeSupportMap from './unicode_support_map';
|
|
|
|
import isEmojiUnicodeSupported from './is_emoji_unicode_supported';
|
|
|
|
|
2017-06-24 06:41:49 +00:00
|
|
|
const validEmojiNames = [...Object.keys(emojiMap), ...Object.keys(emojiAliases)];
|
|
|
|
|
|
|
|
function normalizeEmojiName(name) {
|
|
|
|
return Object.prototype.hasOwnProperty.call(emojiAliases, name) ? emojiAliases[name] : name;
|
|
|
|
}
|
|
|
|
|
|
|
|
function isEmojiNameValid(name) {
|
|
|
|
return validEmojiNames.indexOf(name) >= 0;
|
|
|
|
}
|
|
|
|
|
2017-06-24 06:44:57 +00:00
|
|
|
function filterEmojiNames(filter) {
|
|
|
|
const match = filter.toLowerCase();
|
|
|
|
return validEmojiNames.filter(name => name.indexOf(match) >= 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
function filterEmojiNamesByAlias(filter) {
|
|
|
|
return _.uniq(filterEmojiNames(filter).map(name => normalizeEmojiName(name)));
|
|
|
|
}
|
|
|
|
|
2017-06-24 07:25:04 +00:00
|
|
|
let emojiByCategory;
|
|
|
|
function getEmojiByCategory(category = null) {
|
|
|
|
if (!emojiByCategory) {
|
|
|
|
emojiByCategory = {
|
|
|
|
activity: [],
|
|
|
|
people: [],
|
|
|
|
nature: [],
|
|
|
|
food: [],
|
|
|
|
travel: [],
|
|
|
|
objects: [],
|
|
|
|
symbols: [],
|
|
|
|
flags: [],
|
|
|
|
};
|
|
|
|
Object.keys(emojiMap).forEach((name) => {
|
|
|
|
const emoji = emojiMap[name];
|
|
|
|
if (emojiByCategory[emoji.category]) {
|
|
|
|
emojiByCategory[emoji.category].push(name);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return category ? emojiByCategory[category] : emojiByCategory;
|
|
|
|
}
|
|
|
|
|
2017-06-23 19:08:06 +00:00
|
|
|
export {
|
|
|
|
emojiMap,
|
|
|
|
emojiAliases,
|
2017-06-24 06:41:49 +00:00
|
|
|
normalizeEmojiName,
|
2017-06-24 06:44:57 +00:00
|
|
|
filterEmojiNames,
|
|
|
|
filterEmojiNamesByAlias,
|
2017-06-24 07:25:04 +00:00
|
|
|
getEmojiByCategory,
|
2017-06-23 19:08:06 +00:00
|
|
|
getUnicodeSupportMap,
|
|
|
|
isEmojiNameValid,
|
|
|
|
isEmojiUnicodeSupported,
|
|
|
|
};
|