Closed iamsaksham closed 5 years ago
Not at the moment
Is there any progress?
This is the temporary solution I added for my application:
import _ from 'lodash';
import { emojiIndex } from 'emoji-mart';
const { emojis } = emojiIndex;
export function getEmojiDataByNativeString (nativeString) {
return _.find(emojis, { 'native': nativeString });
}
Not sure if this works in all cases yet. lodash
isn't essential for this, I just use it elsewhere in my application.
Example without lodash:
import { emojiIndex } from 'emoji-mart';
export function getEmojiDataByNativeString (nativeString) {
return Object.values(emojiIndex.emojis).find(item => item.native === nativeString)
}
Won't work when the unicode has skin tones in it.
This should though:
import { emojiIndex } from 'emoji-mart';
export function getEmojiDataByNativeString(nativeString) {
const skinTones = ['', '๐ป', '๐ผ', '๐ฝ', '๐พ', '๐ฟ'];
let skin;
let baseNativeString = nativeString;
skinTones.forEach(skinTone => {
baseNativeString = baseNativeString.replace(skinTone, '');
if (nativeString.indexOf(skinTone) > 0) {
skin = skinTones.indexOf(skinTone) + 1;
}
});
const emojiData = Object.values(emojiIndex.emojis).find(item => item.native === baseNativeString);
emojiData.skin = skin;
return emojiData;
}
@johnsenpeder Very nice thanks.
However I have found a few instances where this doesn't work. They appear to be gender related:
person_with_ball man-bouncing-ball woman-bouncing-ball
You can have a play here to see the problem: https://codesandbox.io/s/oq8rkky5yq
@jmcrthrs yeah, seems to be gender related... :thinking: interesting..
A quick fix would be to add the following since no other gender dependent emoji which I checked had the same problem. That being said I haven't investigated this fully.
import { emojiIndex } from 'emoji-mart';
import { BaseEmoji, CustomEmoji } from 'emoji-mart/dist-es/utils/emoji-index/nimble-emoji-index';
const isBaseEmoji = (emoji: BaseEmoji | CustomEmoji | undefined): emoji is BaseEmoji => {
return Boolean(emoji && (emoji as BaseEmoji).native);
};
export function getEmojiDataByNativeString(nativeString: string) {
const skinTones = ['', '๐ป', '๐ผ', '๐ฝ', '๐พ', '๐ฟ'];
let skin = null;
let baseNativeString = nativeString;
skinTones.forEach(skinTone => {
baseNativeString = baseNativeString.replace(skinTone, '');
if (nativeString.indexOf(skinTone) > 0) {
skin = skinTones.indexOf(skinTone) + 1;
}
});
// Added to checks - no other gender dependent emoji which I checked had the same problem.
if (baseNativeString === 'โนโโ๏ธ') {
baseNativeString = 'โน๏ธโโ๏ธ';
} else if (baseNativeString === 'โนโ๏ธโ๏ธ') {
baseNativeString = 'โน๏ธโโ๏ธ';
}
const emojiData = Object.values(emojiIndex.emojis)
.filter(isBaseEmoji)
.find(item => item.native === baseNativeString);
if (emojiData) {
emojiData.skin = skin;
}
return emojiData;
}
@ifiokjr sadly it does happen with other ones too, :man-lifting-weights:
is one
For anybody else landing here from a Google search and wondering why this issue is closed, emoji-mart
now has a getEmojiDataFromNative
function ๐
https://github.com/missive/emoji-mart/blob/master/README.md#get-emoji-data-from-native
is there any way by which we can get Emoji from its unicode?