(utf8Str)
| 133 | * @return {number} |
| 134 | */ |
| 135 | const byteLength = function byteLength(utf8Str) { |
| 136 | // To figure out which characters are multi-byte we can abuse |
| 137 | // encodeURIComponent which will escape those specific characters. |
| 138 | const multiByteEscapedChars = encodeURIComponent(utf8Str).match(/%[89ABab]/g); |
| 139 | if (multiByteEscapedChars === null) { |
| 140 | return utf8Str.length; |
| 141 | } else { |
| 142 | return utf8Str.length + multiByteEscapedChars.length; |
| 143 | } |
| 144 | }; |
| 145 | exports.byteLength = byteLength; |
| 146 | |
| 147 | /** |