ucs2-length.js 551 B

1234567891011121314151617181920
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.ucs2length = ucs2length;
  4. function ucs2length(s) {
  5. let result = 0;
  6. let length = s.length;
  7. let index = 0;
  8. let charCode;
  9. while (index < length) {
  10. result++;
  11. charCode = s.charCodeAt(index++);
  12. if (charCode >= 0xd800 && charCode <= 0xdbff && index < length) {
  13. charCode = s.charCodeAt(index);
  14. if ((charCode & 0xfc00) == 0xdc00) {
  15. index++;
  16. }
  17. }
  18. }
  19. return result;
  20. }