index.js 506 B

12345678910111213141516171819
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var callBound = require('call-bind/callBound');
  4. var $dataViewByteLength = callBound('DataView.prototype.byteLength', true);
  5. var isDataView = require('is-data-view');
  6. // node <= 0.10, < 0.11.4 has a nonconfigurable own property instead of a prototype getter
  7. /** @type {import('.')} */
  8. module.exports = $dataViewByteLength || function byteLength(x) {
  9. if (!isDataView(x)) {
  10. throw new $TypeError('not a DataView');
  11. }
  12. return x.byteLength;
  13. };