MCPcopy Index your code
hub / github.com/plotly/plotly.js / byteLength

Function byteLength

stackgl_modules/index.js:386–428  ·  view source on GitHub ↗
(string, encoding)

Source from the content-addressed store, hash-verified

384 return buffer;
385};
386function byteLength(string, encoding) {
387 if (Buffer.isBuffer(string)) {
388 return string.length;
389 }
390 if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
391 return string.byteLength;
392 }
393 if (typeof string !== 'string') {
394 throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' + 'Received type ' + _typeof(string));
395 }
396 var len = string.length;
397 var mustMatch = arguments.length > 2 && arguments[2] === true;
398 if (!mustMatch && len === 0) return 0;
399
400 // Use a for loop to avoid recursion
401 var loweredCase = false;
402 for (;;) {
403 switch (encoding) {
404 case 'ascii':
405 case 'latin1':
406 case 'binary':
407 return len;
408 case 'utf8':
409 case 'utf-8':
410 return utf8ToBytes(string).length;
411 case 'ucs2':
412 case 'ucs-2':
413 case 'utf16le':
414 case 'utf-16le':
415 return len * 2;
416 case 'hex':
417 return len >>> 1;
418 case 'base64':
419 return base64ToBytes(string).length;
420 default:
421 if (loweredCase) {
422 return mustMatch ? -1 : utf8ToBytes(string).length; // assume utf8
423 }
424 encoding = ('' + encoding).toLowerCase();
425 loweredCase = true;
426 }
427 }
428}
429Buffer.byteLength = byteLength;
430function slowToString(encoding, start, end) {
431 var loweredCase = false;

Callers 1

fromStringFunction · 0.85

Calls 5

isInstanceFunction · 0.85
_typeofFunction · 0.85
utf8ToBytesFunction · 0.85
base64ToBytesFunction · 0.85
getLensFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…