JavaScript Cross platform emojis in iOS and android -


what best way obtain normal emoji (the yellow one, first in image) in android. if emojis come different colors (ios emojis). reason android doesn't have colored emojis.

enter image description here

all emojis in android less first 1 shows '?' symbol.

i need parse emojis in javascript didn't find library. maybe there replace function solves this.

emojis

first let's understand emoji is. emoji combination of many characters implemented in unicode. example, "light skin tone male shrug emoji" following 5 characters combined:

0x1f937 0x1f3fb 0x200d 0x2642 0xfe0f  - 0x1f937: person shrugging - 0x1f3fb: light skin tone   - 0x200d: 0 width joiner     (used combine 2 characters, in case                                  light skin tone person shrugging ,                                  male sign.) - 0x2642: male sign - 0xfe0f: variation selector-16 (used indicate emoji) 

unicode in javascript

good news is, can remove 0x1f3fb version without skin tone. bad news however, javascript not support utf-16, shows

0xd83e 0xdd37 0xd83c 0xdffb 0x200d 0x2642 0xfe0f └───────── uh oh ─────────┘ 

instead incorrect because doesn't know surrogate pair is. calculate correct code point, have reference utf-16 standard , make necessary corrections. fortunately, someone else did hard work , here i'm converting string proper utf-16 , removing part don't want:

// defines range of skin tone modifiers var modifiersmin = 0x1f3fb, modifiersmax = 0x1f3ff;  // emoji u+1f3fb "light skin tone" modifier combined "male sign" var string = new unicodestring("🤷🏻‍♂️");  // removes modifier string = new unicodestring(string.codepoints.filter(c => {     return c < modifiersmin || c > modifiersmax; });  alert(string.tostring()); 

you can see in action here: https://jsfiddle.net/derekl/b5848tor/

now understand how emojis work, can this:

// replace function var skintonemodifiers = new regexp("\ud83c[\udffb-\udfff]", "g"); var string = "🤷🏻‍♂️"; // remove skin tone modifier string = string.replace(skintonemodifiers, ""); 

which works faster not clear why works without understanding concepts behind it.

see in action: https://jsfiddle.net/derekl/sn4n689r/


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -