thoov/mock-socket

View on GitHub
src/helpers/byte-length.js

Summary

Maintainability
A
0 mins
Test Coverage
export default function lengthInUtf8Bytes(str) {
  // Matches only the 10.. bytes that are non-initial characters in a multi-byte sequence.
  const m = encodeURIComponent(str).match(/%[89ABab]/g);
  return str.length + (m ? m.length : 0);
}