how to convert this π
into this 1f600
in javascript
'π'.charCodeAt(0);
this will return unicode 55357 but how to get 1f600 from π
how to convert this π
into this 1f600
in javascript
'π'.charCodeAt(0);
this will return unicode 55357 but how to get 1f600 from π
Added script to convert this on browser side
function emojiUnicode (emoji) {
var comp;
if (emoji.length === 1) {
comp = emoji.charCodeAt(0);
}
comp = (
(emoji.charCodeAt(0) - 0xD800) * 0x400
+ (emoji.charCodeAt(1) - 0xDC00) + 0x10000
);
if (comp < 0) {
comp = emoji.charCodeAt(0);
}
return comp.toString("16");
};
emojiUnicode("π"); # result "1f600"
returns
from the original function and didn't add the proper ifs
and elses
you altered the function. Correct would be how it is here: raw.githubusercontent.com/IonicaBizau/emoji-unicode/… β
Gloriane Two way
let hex = "π".codePointAt(0).toString(16)
let emo = String.fromCodePoint("0x"+hex);
console.log(hex, emo);
console.log( String.fromCodePoint("0xD83D","0xDE0A") )
(I get this: π - but if I change sequence of this 2 strings I get οΏ½οΏ½ , if I join strings to "0xD83DDE0A" I get exception β
Grimbly Added script to convert this on browser side
function emojiUnicode (emoji) {
var comp;
if (emoji.length === 1) {
comp = emoji.charCodeAt(0);
}
comp = (
(emoji.charCodeAt(0) - 0xD800) * 0x400
+ (emoji.charCodeAt(1) - 0xDC00) + 0x10000
);
if (comp < 0) {
comp = emoji.charCodeAt(0);
}
return comp.toString("16");
};
emojiUnicode("π"); # result "1f600"
returns
from the original function and didn't add the proper ifs
and elses
you altered the function. Correct would be how it is here: raw.githubusercontent.com/IonicaBizau/emoji-unicode/… β
Gloriane This is what I use:
const toUni = function (str) {
if (str.length < 4)
return str.codePointAt(0).toString(16);
return str.codePointAt(0).toString(16) + '-' + str.codePointAt(2).toString(16);
};
Please Read This Link.
Here is the function :
function toUTF16(codePoint) {
var TEN_BITS = parseInt('1111111111', 2);
function u(codeUnit) {
return '\\u'+codeUnit.toString(16).toUpperCase();
}
if (codePoint <= 0xFFFF) {
return u(codePoint);
}
codePoint -= 0x10000;
// Shift right to get to most significant 10 bits
var leadSurrogate = 0xD800 + (codePoint >> 10);
// Mask to get least significant 10 bits
var tailSurrogate = 0xDC00 + (codePoint & TEN_BITS);
return u(leadSurrogate) + u(tailSurrogate);
}
Emojis like π©ββοΈ have two parts: π© +βοΈ.
Here is how to get their code:
emoji = "π©ββοΈ" // corresponds to 1f469-200d-2695-fe0f
code1 = emoji.codePointAt(0).toString(16) // gives only 1f469
code2 = [...emoji].map(e => e.codePointAt(0).toString(16)).join(`-`) // gives correctly 1f469-200d-2695-fe0f
console.log(code1)
console.log(code2)
emoji_code = "-".join(f"{ord(c):x}" for c in "π©ββοΈ")
would be the corresponding implementation in python. β
Kirghiz Here is another way. Source
"π".codePointAt(0).toString(16)
Best answer in my view is to use node-emoji package.
https://www.npmjs.com/package/node-emoji
Here are steps.
do npm i node-emoji
var emoji = require('node-emoji');
var convertEmoji = function(data){
if(emoji.hasEmoji(data)){
return emoji.unemojify(data);
}
else{
return data;
}
}
const
getUnicodeHex = char => char.codePointAt(0).toString(16),
getEmoji = unicodeHex => String.fromCodePoint(unicodeHex)
console.log(
getUnicodeHex('π'), // 1f600
getEmoji(0x1f600) // π
)
© 2022 - 2024 β McMap. All rights reserved.