v1.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.default = (buf, start, length) => {
  4. let offset = start;
  5. const end = offset + length;
  6. const units = [];
  7. let result = '';
  8. while (offset < end) {
  9. const byte1 = buf[offset++];
  10. if ((byte1 & 0x80) === 0) {
  11. units.push(byte1);
  12. }
  13. else if ((byte1 & 0xe0) === 0xc0) {
  14. const byte2 = buf[offset++] & 0x3f;
  15. units.push(((byte1 & 0x1f) << 6) | byte2);
  16. }
  17. else if ((byte1 & 0xf0) === 0xe0) {
  18. const byte2 = buf[offset++] & 0x3f;
  19. const byte3 = buf[offset++] & 0x3f;
  20. units.push(((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3);
  21. }
  22. else if ((byte1 & 0xf8) === 0xf0) {
  23. const byte2 = buf[offset++] & 0x3f;
  24. const byte3 = buf[offset++] & 0x3f;
  25. const byte4 = buf[offset++] & 0x3f;
  26. let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;
  27. if (unit > 0xffff) {
  28. unit -= 0x10000;
  29. units.push(((unit >>> 10) & 0x3ff) | 0xd800);
  30. unit = 0xdc00 | (unit & 0x3ff);
  31. }
  32. units.push(unit);
  33. }
  34. else {
  35. units.push(byte1);
  36. }
  37. if (units.length >= 1000) {
  38. result += String.fromCharCode(...units);
  39. units.length = 0;
  40. }
  41. }
  42. if (units.length > 0)
  43. result += String.fromCharCode(...units);
  44. return result;
  45. };
  46. //# sourceMappingURL=v1.js.map