Giter Site home page Giter Site logo

Get Emoji from its unicode about emoji-mart HOT 10 CLOSED

missive avatar missive commented on August 22, 2024 3
Get Emoji from its unicode

from emoji-mart.

Comments (10)

Fauntleroy avatar Fauntleroy commented on August 22, 2024 2

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.

from emoji-mart.

stnwk avatar stnwk commented on August 22, 2024 2

Example without lodash:

import { emojiIndex } from 'emoji-mart';

export function getEmojiDataByNativeString (nativeString) {
  return Object.values(emojiIndex.emojis).find(item => item.native === nativeString)
}

from emoji-mart.

johnsenpeder avatar johnsenpeder commented on August 22, 2024 2

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;
}

from emoji-mart.

jmcrthrs avatar jmcrthrs commented on August 22, 2024 1

@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

from emoji-mart.

TranquilMarmot avatar TranquilMarmot commented on August 22, 2024 1

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

from emoji-mart.

EtienneLem avatar EtienneLem commented on August 22, 2024

Not at the moment

from emoji-mart.

goodmind avatar goodmind commented on August 22, 2024

Is there any progress?

from emoji-mart.

johnsenpeder avatar johnsenpeder commented on August 22, 2024

@jmcrthrs yeah, seems to be gender related... ๐Ÿค” interesting..

from emoji-mart.

ifiokjr avatar ifiokjr commented on August 22, 2024

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;
}

from emoji-mart.

johnsenpeder avatar johnsenpeder commented on August 22, 2024

@ifiokjr sadly it does happen with other ones too, :man-lifting-weights: is one

from emoji-mart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.