711634a6acf614d9522f301b87304a53b0d339c3abfba50f7c2de299b70fba1b0ba4cd4f3c535651429be8225b71a8a429b67b64270623941c8d1633d9c812 3.4 KB

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