ucs2length.js 808 B

123456789101112131415161718192021222324
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. // https://mathiasbynens.be/notes/javascript-encoding
  4. // https://github.com/bestiejs/punycode.js - punycode.ucs2.decode
  5. function ucs2length(str) {
  6. const len = str.length;
  7. let length = 0;
  8. let pos = 0;
  9. let value;
  10. while (pos < len) {
  11. length++;
  12. value = str.charCodeAt(pos++);
  13. if (value >= 0xd800 && value <= 0xdbff && pos < len) {
  14. // high surrogate, and there is a next character
  15. value = str.charCodeAt(pos);
  16. if ((value & 0xfc00) === 0xdc00)
  17. pos++; // low surrogate
  18. }
  19. }
  20. return length;
  21. }
  22. exports.default = ucs2length;
  23. ucs2length.code = 'require("ajv/dist/runtime/ucs2length").default';
  24. //# sourceMappingURL=ucs2length.js.map