0

How can I convert html entity 😍 to \uD83D\uDE0D in JavaScript? (react native) (emoji )

Codler
  • 10,951
  • 6
  • 52
  • 65

2 Answers2

0

This he library can decode

import { decode } from 'he';

decode('😍') // outputs 
Codler
  • 10,951
  • 6
  • 52
  • 65
-1

Try String.fromCodePoint(...)

String.fromCodePoint(42);       // "*"
String.fromCodePoint(65, 90);   // "AZ"
String.fromCodePoint(0x404);    // "\u0404"
String.fromCodePoint(0x2F804);  // "\uD87E\uDC04"
String.fromCodePoint(194564);   // "\uD87E\uDC04"
String.fromCodePoint(0x1D306, 0x61, 0x1D307) // "\uD834\uDF06a\uD834\uDF07"

String.fromCodePoint('_');      // RangeError
String.fromCodePoint(Infinity); // RangeError
String.fromCodePoint(-1);       // RangeError
String.fromCodePoint(3.14);     // RangeError
String.fromCodePoint(3e-2);     // RangeError
String.fromCodePoint(NaN);      // RangeError

String.fromCodePoint() MDN Doc