Long Phan
Long Phan

Reputation: 338

node.js convert emojis into unicode or something else?

I am trying to mess around with the facebook-chat-api NPM package. I am trying to check whenever the message.body contains a fire emoji (🔥) it will execute some logic. But how would I go about getting the unicode (? Not sure what I actually need) of this emoji in Node.js. I've tried utf8 NPM package but it does not seem like it is working

This is the response I see in the terminal:

{     
      type: 'message',
      senderID: 'senderID',
      body: '🔥',
      threadID: 'threadID',
      messageID: 'messageID',
      attachments: [],
      timestamp: '1518288429669',
      isGroup: false 
}

Upvotes: 1

Views: 3743

Answers (1)

kgangadhar
kgangadhar

Reputation: 5088

For emoji to unicode convertion u can use emoji-unicode package:

const emojiUnicode = require("emoji-unicode");

console.log(emojiUnicode("🔥"));
// => 1f525

And for emoji name to unicode, You can use emoji-name-map package:

const toEmoji = require("emoji-name-map");

console.log(emojiUnicode(toEmoji.get("fire")));
// => 1f525

Upvotes: 4

Related Questions