logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

unicode_to_filename.js (660B)


  1. // taken from:
  2. // https://github.com/twitter/twemoji/blob/47732c7/twemoji-generator.js#L848-L866
  3. exports.unicodeToFilename = (str) => {
  4. let result = '';
  5. let charCode = 0;
  6. let p = 0;
  7. let i = 0;
  8. while (i < str.length) {
  9. charCode = str.charCodeAt(i++);
  10. if (p) {
  11. if (result.length > 0) {
  12. result += '-';
  13. }
  14. result += (0x10000 + ((p - 0xD800) << 10) + (charCode - 0xDC00)).toString(16);
  15. p = 0;
  16. } else if (0xD800 <= charCode && charCode <= 0xDBFF) {
  17. p = charCode;
  18. } else {
  19. if (result.length > 0) {
  20. result += '-';
  21. }
  22. result += charCode.toString(16);
  23. }
  24. }
  25. return result;
  26. };