UNPKG

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