index.js 510 B

123456789101112131415161718
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var callBound = require('call-bind/callBound');
  4. var $typedArrayBuffer = callBound('TypedArray.prototype.buffer', true);
  5. var isTypedArray = require('is-typed-array');
  6. /** @type {import('.')} */
  7. // node <= 0.10, < 0.11.4 has a nonconfigurable own property instead of a prototype getter
  8. module.exports = $typedArrayBuffer || function typedArrayBuffer(x) {
  9. if (!isTypedArray(x)) {
  10. throw new $TypeError('Not a Typed Array');
  11. }
  12. return x.buffer;
  13. };