db0b181a9d4bf2219193677e9719a895909a65f30606389013d0e65e338d6c6d00bbfe83de4877ce93678b728cb60bf706e72ac4e83c85fe3bdde61a15ab9f 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # is-typed-array <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
  2. [![github actions][actions-image]][actions-url]
  3. [![coverage][codecov-image]][codecov-url]
  4. [![dependency status][5]][6]
  5. [![dev dependency status][7]][8]
  6. [![License][license-image]][license-url]
  7. [![Downloads][downloads-image]][downloads-url]
  8. [![npm badge][npm-badge-png]][package-url]
  9. Is this value a JS Typed Array? This module works cross-realm/iframe, does not depend on `instanceof` or mutable properties, and despite ES6 Symbol.toStringTag.
  10. ## Example
  11. ```js
  12. var isTypedArray = require('is-typed-array');
  13. var assert = require('assert');
  14. assert.equal(false, isTypedArray(undefined));
  15. assert.equal(false, isTypedArray(null));
  16. assert.equal(false, isTypedArray(false));
  17. assert.equal(false, isTypedArray(true));
  18. assert.equal(false, isTypedArray([]));
  19. assert.equal(false, isTypedArray({}));
  20. assert.equal(false, isTypedArray(/a/g));
  21. assert.equal(false, isTypedArray(new RegExp('a', 'g')));
  22. assert.equal(false, isTypedArray(new Date()));
  23. assert.equal(false, isTypedArray(42));
  24. assert.equal(false, isTypedArray(NaN));
  25. assert.equal(false, isTypedArray(Infinity));
  26. assert.equal(false, isTypedArray(new Number(42)));
  27. assert.equal(false, isTypedArray('foo'));
  28. assert.equal(false, isTypedArray(Object('foo')));
  29. assert.equal(false, isTypedArray(function () {}));
  30. assert.equal(false, isTypedArray(function* () {}));
  31. assert.equal(false, isTypedArray(x => x * x));
  32. assert.equal(false, isTypedArray([]));
  33. assert.ok(isTypedArray(new Int8Array()));
  34. assert.ok(isTypedArray(new Uint8Array()));
  35. assert.ok(isTypedArray(new Uint8ClampedArray()));
  36. assert.ok(isTypedArray(new Int16Array()));
  37. assert.ok(isTypedArray(new Uint16Array()));
  38. assert.ok(isTypedArray(new Int32Array()));
  39. assert.ok(isTypedArray(new Uint32Array()));
  40. assert.ok(isTypedArray(new Float32Array()));
  41. assert.ok(isTypedArray(new Float64Array()));
  42. assert.ok(isTypedArray(new BigInt64Array()));
  43. assert.ok(isTypedArray(new BigUint64Array()));
  44. ```
  45. ## Tests
  46. Simply clone the repo, `npm install`, and run `npm test`
  47. [package-url]: https://npmjs.org/package/is-typed-array
  48. [npm-version-svg]: https://versionbadg.es/inspect-js/is-typed-array.svg
  49. [deps-svg]: https://david-dm.org/inspect-js/is-typed-array.svg
  50. [deps-url]: https://david-dm.org/inspect-js/is-typed-array
  51. [dev-deps-svg]: https://david-dm.org/inspect-js/is-typed-array/dev-status.svg
  52. [dev-deps-url]: https://david-dm.org/inspect-js/is-typed-array#info=devDependencies
  53. [npm-badge-png]: https://nodei.co/npm/is-typed-array.png?downloads=true&stars=true
  54. [license-image]: https://img.shields.io/npm/l/is-typed-array.svg
  55. [license-url]: LICENSE
  56. [downloads-image]: https://img.shields.io/npm/dm/is-typed-array.svg
  57. [downloads-url]: https://npm-stat.com/charts.html?package=is-typed-array
  58. [codecov-image]: https://codecov.io/gh/inspect-js/is-typed-array/branch/main/graphs/badge.svg
  59. [codecov-url]: https://app.codecov.io/gh/inspect-js/is-typed-array/
  60. [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/is-typed-array
  61. [actions-url]: https://github.com/inspect-js/is-typed-array/actions