JavaScript Ninja – Easy Unicode Emoji Generator 😁🌠🐬

  • Without calculating offsets and doing the regular-stuff people are doing to generate surrogate-pairs (1) (2),
    this little trick make use of the decimal HTML-Entity of each unicode character :)

  • start up with browsing the about:blank page, with minimal browser windows opened, the following steps will take a lot of processing power…
  • open up the console and run:
    //this is a good example: 🔌
    (function(){
      var a = [], i;
      
      for(i=120000; i<130000; i+=1){ a.push(i); }
    
      a = "&#" + a.join("; &#") + ";";
      
      document.body.style.display="none";
      document.body.innerHTML = a;
      setTimeout(function(){
        document.body.style.display="block";
      },10);
    }());
    

    find a good range by looking at fileformat.info first.
    if you want to copy stuff around, make sure that your editor is pre-defined to Unicode (UTF-16 LE/Little Endian BOM)

  • well that IS embarrassing — apparently webkit has a bug/feature,
    where- while the Unicode-characters still are perfectly representative on the web-page,
    the content is completely un-copy&&paste-able to a notepad, in fact if you’ll try- you’ll just get the spaces (‘ ‘) between characters (funny isn’t?)

    –this is due to the representation of the string on using HTML Entities,
    the reason is probably that,

    for example (decimal) & # 128268; or (hex) & # x1f50c; are not really the surrogate-pair “\uD83D\uDD0C” it is just a placeholder… (or something)…

  • fear NOT, here is a little longer but still quite nice solution…
    this time we are still looping on range, but we’ll going to render REAL surrogate-pair and use some pinning-together we will use String’s from-char-code (which supports surrogate-pairs!)

    basically it is as easy as:

    var a = [], i;
    
    for(i=128000; i<129000; i+=1) a.push(String.fromCharCode(
      ((i - 0x10000) >> 10) | 0xD800
    , ((i - 0x10000) % 0x400) | 0xDC00
    ));
    

    and taking the code far above with the (near) above modification…

    (function(){
    //browse about:blank first, then open up the console and paste the code :)
    var a = [], i;

    for(i=128000; i<129000; i+=1)
    a.push(String.fromCharCode(
    ((i – 0x10000)>> 10) | 0xD800
    , ((i – 0x10000) % 0x400) | 0xDC00
    ));

    a = a.join(” “);

    document.body.style.display=”none”;
    document.body.innerHTML = a;
    setTimeout(function(){
    document.body.style.display=”block”;
    },10);
    }());

  • and…
    result: totally copy&&paste-able

    result:
    totally
    copy&&paste-able

last thing- bidi chars, can mess with your cursor direction when you are copy&&paste’ing around,
the following will delete (no regex!!) each of the “OFFICIAL” Unicode-bidi chars, if any.

(function(){
  //browse about:blank first, then open up the console and paste the code :)
  var a = [], i;
  
  for(i=0; i<30000; i+=1) 
    a.push(String.fromCharCode(i));

  a = a.join(" ").replace("\u2066","").replace("\u2067","").replace("\u2068","").replace("\u2069","").replace("\u200E","").replace("\u200F","").replace("\u061C","").replace("\u202A","").replace("\u202B","").replace("\u202C","").replace("\u202D","").replace("\u202E","");
  
  document.body.style.display="none";
  document.body.innerHTML = a;
  setTimeout(function(){
    document.body.style.display="block";
  },10);
}());

until 65533 (0XFFFD) you can use single value in .fromCharCode(...),
afterwards it is the world of surrogate-pairs :)
icompile.eladkarako.com_unicode_javascript_5