decode_codepoint.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. 'use strict';
  2. // Adapted from https://github.com/mathiasbynens/he/blob/36afe179392226cf1b6ccdb16ebbb7a5a844d93a/src/he.js#L106-L134
  3. var _a;
  4. Object.defineProperty(exports, '__esModule', {
  5. value: true
  6. });
  7. exports.replaceCodePoint = exports.fromCodePoint = void 0;
  8. var decodeMap = new Map([
  9. [0, 65533],
  10. [128, 8364],
  11. [130, 8218],
  12. [131, 402],
  13. [132, 8222],
  14. [133, 8230],
  15. [134, 8224],
  16. [135, 8225],
  17. [136, 710],
  18. [137, 8240],
  19. [138, 352],
  20. [139, 8249],
  21. [140, 338],
  22. [142, 381],
  23. [145, 8216],
  24. [146, 8217],
  25. [147, 8220],
  26. [148, 8221],
  27. [149, 8226],
  28. [150, 8211],
  29. [151, 8212],
  30. [152, 732],
  31. [153, 8482],
  32. [154, 353],
  33. [155, 8250],
  34. [156, 339],
  35. [158, 382],
  36. [159, 376]
  37. ]);
  38. exports.fromCodePoint =
  39. (_a = String.fromCodePoint) !== null && _a !== void 0
  40. ? _a
  41. : function (codePoint) {
  42. var output = '';
  43. if (codePoint > 65535) {
  44. codePoint -= 65536;
  45. output += String.fromCharCode(((codePoint >>> 10) & 1023) | 55296);
  46. codePoint = 56320 | (codePoint & 1023);
  47. }
  48. output += String.fromCharCode(codePoint);
  49. return output;
  50. };
  51. function replaceCodePoint(codePoint) {
  52. var _a;
  53. if ((codePoint >= 55296 && codePoint <= 57343) || codePoint > 1114111) {
  54. return 65533;
  55. }
  56. return (_a = decodeMap.get(codePoint)) !== null && _a !== void 0 ? _a : codePoint;
  57. }
  58. exports.replaceCodePoint = replaceCodePoint;
  59. function decodeCodePoint(codePoint) {
  60. return (0, exports.fromCodePoint)(replaceCodePoint(codePoint));
  61. }
  62. exports.default = decodeCodePoint;
  63. //# sourceMappingURL=decode_codepoint.js.map