index.js 421 B

1234567891011121314
  1. 'use strict';
  2. var callBound = require('call-bind/callBound');
  3. var $byteLength = callBound('ArrayBuffer.prototype.byteLength', true);
  4. var isArrayBuffer = require('is-array-buffer');
  5. /** @type {import('.')} */
  6. module.exports = function byteLength(ab) {
  7. if (!isArrayBuffer(ab)) {
  8. return NaN;
  9. }
  10. return $byteLength ? $byteLength(ab) : ab.byteLength;
  11. }; // in node < 0.11, byteLength is an own nonconfigurable property