decode_codepoint.js 1.5 KB

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