Sin descripción

decode_codepoint.js 622B

1234567891011121314151617181920212223242526
  1. var decodeMap = require("../maps/decode.json");
  2. module.exports = decodeCodePoint;
  3. // modified version of https://github.com/mathiasbynens/he/blob/master/src/he.js#L94-L119
  4. function decodeCodePoint(codePoint){
  5. if((codePoint >= 0xD800 && codePoint <= 0xDFFF) || codePoint > 0x10FFFF){
  6. return "\uFFFD";
  7. }
  8. if(codePoint in decodeMap){
  9. codePoint = decodeMap[codePoint];
  10. }
  11. var output = "";
  12. if(codePoint > 0xFFFF){
  13. codePoint -= 0x10000;
  14. output += String.fromCharCode(codePoint >>> 10 & 0x3FF | 0xD800);
  15. codePoint = 0xDC00 | codePoint & 0x3FF;
  16. }
  17. output += String.fromCharCode(codePoint);
  18. return output;
  19. }