MCPcopy Create free account
hub / github.com/Useful-Scripts-Extension/useful-script / byteLength

Function byteLength

scripts/test.js:265–275  ·  view source on GitHub ↗
(str)

Source from the content-addressed store, hash-verified

263
264 // https://stackoverflow.com/a/23329386
265 function byteLength(str) {
266 // returns the byte length of an utf8 string
267 var s = str.length;
268 for (var i = str.length - 1; i >= 0; i--) {
269 var code = str.charCodeAt(i);
270 if (code > 0x7f && code <= 0x7ff) s++;
271 else if (code > 0x7ff && code <= 0xffff) s += 2;
272 if (code >= 0xdc00 && code <= 0xdfff) i--; //trail surrogate
273 }
274 return s;
275 }
276
277 try {
278 let text = document.body.innerText;

Callers 1

test.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected