decode_codepoint.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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", { value: true });
  5. exports.replaceCodePoint = exports.fromCodePoint = void 0;
  6. var decodeMap = new Map([
  7. [0, 65533],
  8. [128, 8364],
  9. [130, 8218],
  10. [131, 402],
  11. [132, 8222],
  12. [133, 8230],
  13. [134, 8224],
  14. [135, 8225],
  15. [136, 710],
  16. [137, 8240],
  17. [138, 352],
  18. [139, 8249],
  19. [140, 338],
  20. [142, 381],
  21. [145, 8216],
  22. [146, 8217],
  23. [147, 8220],
  24. [148, 8221],
  25. [149, 8226],
  26. [150, 8211],
  27. [151, 8212],
  28. [152, 732],
  29. [153, 8482],
  30. [154, 353],
  31. [155, 8250],
  32. [156, 339],
  33. [158, 382],
  34. [159, 376],
  35. ]);
  36. exports.fromCodePoint =
  37. // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, node/no-unsupported-features/es-builtins
  38. (_a = String.fromCodePoint) !== null && _a !== void 0 ? _a : function (codePoint) {
  39. var output = "";
  40. if (codePoint > 0xffff) {
  41. codePoint -= 0x10000;
  42. output += String.fromCharCode(((codePoint >>> 10) & 0x3ff) | 0xd800);
  43. codePoint = 0xdc00 | (codePoint & 0x3ff);
  44. }
  45. output += String.fromCharCode(codePoint);
  46. return output;
  47. };
  48. function replaceCodePoint(codePoint) {
  49. var _a;
  50. if ((codePoint >= 0xd800 && codePoint <= 0xdfff) || codePoint > 0x10ffff) {
  51. return 0xfffd;
  52. }
  53. return (_a = decodeMap.get(codePoint)) !== null && _a !== void 0 ? _a : codePoint;
  54. }
  55. exports.replaceCodePoint = replaceCodePoint;
  56. function decodeCodePoint(codePoint) {
  57. return (0, exports.fromCodePoint)(replaceCodePoint(codePoint));
  58. }
  59. exports.default = decodeCodePoint;
  60. //# sourceMappingURL=decode_codepoint.js.map