MCPcopy Create free account
hub / github.com/ampproject/amphtml / byteLength

Function byteLength

validator/js/engine/htmlparser.js:135–144  ·  view source on GitHub ↗
(utf8Str)

Source from the content-addressed store, hash-verified

133 * @return {number}
134 */
135const 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};
145exports.byteLength = byteLength;
146
147/**

Callers 1

constructorMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected