├── .editorconfig ├── .eslintrc ├── .github ├── FUNDING.yml └── workflows │ ├── node-aught.yml │ ├── node-harmony.yml │ ├── node-pretest.yml │ ├── node-tens.yml │ ├── node-twenties.yml │ ├── rebase.yml │ └── require-allow-edits.yml ├── .gitignore ├── .npmrc ├── .nycrc ├── CHANGELOG.md ├── LICENSE ├── README.md ├── index.d.ts ├── index.js ├── package.json ├── test └── index.js └── tsconfig.json /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | max_line_length = 150 11 | 12 | [CHANGELOG.md] 13 | indent_style = space 14 | indent_size = 2 15 | 16 | [*.json] 17 | max_line_length = off 18 | 19 | [Makefile] 20 | max_line_length = off 21 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | 4 | "extends": "@ljharb", 5 | 6 | "globals": { 7 | "globalThis": false 8 | }, 9 | 10 | "rules": { 11 | "max-statements-per-line": [2, { "max": 2 }] 12 | }, 13 | } 14 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [ljharb] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: npm/is-typed-array 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.github/workflows/node-aught.yml: -------------------------------------------------------------------------------- 1 | name: 'Tests: node.js < 10' 2 | 3 | on: [pull_request, push] 4 | 5 | jobs: 6 | tests: 7 | uses: ljharb/actions/.github/workflows/node.yml@main 8 | with: 9 | range: '< 10' 10 | type: minors 11 | command: npm run tests-only 12 | skip-ls-check: true 13 | 14 | node: 15 | name: 'node < 10' 16 | needs: [tests] 17 | runs-on: ubuntu-latest 18 | steps: 19 | - run: true 20 | -------------------------------------------------------------------------------- /.github/workflows/node-harmony.yml: -------------------------------------------------------------------------------- 1 | name: 'Tests: node.js (harmony)' 2 | 3 | on: [pull_request, push] 4 | 5 | jobs: 6 | tests: 7 | uses: ljharb/actions/.github/workflows/node.yml@main 8 | with: 9 | range: '>=0.4 <16' 10 | type: minors 11 | command: npm run test:harmony 12 | skip-ls-check: true 13 | 14 | node: 15 | name: 'node: harmony' 16 | needs: [tests] 17 | runs-on: ubuntu-latest 18 | steps: 19 | - run: true 20 | -------------------------------------------------------------------------------- /.github/workflows/node-pretest.yml: -------------------------------------------------------------------------------- 1 | name: 'Tests: pretest/posttest' 2 | 3 | on: [pull_request, push] 4 | 5 | jobs: 6 | tests: 7 | uses: ljharb/actions/.github/workflows/pretest.yml@main 8 | -------------------------------------------------------------------------------- /.github/workflows/node-tens.yml: -------------------------------------------------------------------------------- 1 | name: 'Tests: node.js 10 - 20' 2 | 3 | on: [pull_request, push] 4 | 5 | permissions: 6 | contents: read 7 | 8 | jobs: 9 | tests: 10 | uses: ljharb/actions/.github/workflows/node.yml@main 11 | with: 12 | range: '>= 10 < 20' 13 | type: minors 14 | command: npm run tests-only 15 | 16 | node: 17 | name: 'node 10 - 20' 18 | needs: [tests] 19 | runs-on: ubuntu-latest 20 | steps: 21 | - run: true 22 | -------------------------------------------------------------------------------- /.github/workflows/node-twenties.yml: -------------------------------------------------------------------------------- 1 | name: 'Tests: node.js >= 20' 2 | 3 | on: [pull_request, push] 4 | 5 | permissions: 6 | contents: read 7 | 8 | jobs: 9 | tests: 10 | uses: ljharb/actions/.github/workflows/node.yml@main 11 | with: 12 | range: '>= 20' 13 | type: minors 14 | command: npm run tests-only 15 | 16 | node: 17 | name: 'node >= 20' 18 | needs: [tests] 19 | runs-on: ubuntu-latest 20 | steps: 21 | - run: true 22 | -------------------------------------------------------------------------------- /.github/workflows/rebase.yml: -------------------------------------------------------------------------------- 1 | name: Automatic Rebase 2 | 3 | on: [pull_request_target] 4 | 5 | jobs: 6 | _: 7 | uses: ljharb/actions/.github/workflows/rebase.yml@main 8 | secrets: 9 | token: ${{ secrets.GITHUB_TOKEN }} 10 | -------------------------------------------------------------------------------- /.github/workflows/require-allow-edits.yml: -------------------------------------------------------------------------------- 1 | name: Require “Allow Edits” 2 | 3 | on: [pull_request_target] 4 | 5 | jobs: 6 | _: 7 | name: "Require “Allow Edits”" 8 | 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: ljharb/require-allow-edits@main 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | .nyc_output/ 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 28 | node_modules 29 | 30 | # Only apps should have lockfiles 31 | npm-shrinkwrap.json 32 | package-lock.json 33 | yarn.lock 34 | 35 | .npmignore 36 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | allow-same-version=true 3 | message=v%s 4 | -------------------------------------------------------------------------------- /.nycrc: -------------------------------------------------------------------------------- 1 | { 2 | "all": true, 3 | "check-coverage": false, 4 | "reporter": ["text-summary", "text", "html", "json"], 5 | "exclude": [ 6 | "coverage", 7 | "test" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## [v1.1.15](https://github.com/inspect-js/is-typed-array/compare/v1.1.14...v1.1.15) - 2024-12-18 9 | 10 | ### Commits 11 | 12 | - [types] improve types [`d934b49`](https://github.com/inspect-js/is-typed-array/commit/d934b49f7a16d5e20ba437a795b887f1f71ef240) 13 | - [Dev Deps] update `@types/tape` [`da26511`](https://github.com/inspect-js/is-typed-array/commit/da26511ad7515c50fdc720701d5735b0d8a40800) 14 | 15 | ## [v1.1.14](https://github.com/inspect-js/is-typed-array/compare/v1.1.13...v1.1.14) - 2024-12-17 16 | 17 | ### Commits 18 | 19 | - [types] use shared config [`eafa7fa`](https://github.com/inspect-js/is-typed-array/commit/eafa7fad2fc8d464a68e218d39a7eab782d9ce76) 20 | - [actions] split out node 10-20, and 20+ [`cd6d5a3`](https://github.com/inspect-js/is-typed-array/commit/cd6d5a3283a1e65cf5885e57daede65a5176fd91) 21 | - [types] use `which-typed-array`’s `TypedArray` type; re-export it [`d7d9fcd`](https://github.com/inspect-js/is-typed-array/commit/d7d9fcd75d538b7f8146dcd9faca5142534a3d45) 22 | - [Dev Deps] update `@arethetypeswrong/cli`, `@ljharb/eslint-config`, `@ljharb/tsconfig`, `@types/node`, `@types/object-inspect`, `@types/tape`, `auto-changelog`, `object-inspect`, `tape` [`65afb42`](https://github.com/inspect-js/is-typed-array/commit/65afb4263ff4f4ee4ee51b284dc7519ce969a666) 23 | - [Dev Deps] update `@types/node`, `has-tostringtag`, `tape` [`9e27ddd`](https://github.com/inspect-js/is-typed-array/commit/9e27ddd62a51ebae46781de0adbd8871341c633c) 24 | - [Tests] replace `aud` with `npm audit` [`ad4defe`](https://github.com/inspect-js/is-typed-array/commit/ad4defe211c77d42b880d13faf7737b8f1adaf13) 25 | - [Tests] use `@arethetypeswrong/cli` [`ac4bcca`](https://github.com/inspect-js/is-typed-array/commit/ac4bcca4ee2215662e79aa21681756984bb0b6d1) 26 | - [Deps] update `which-typed-array` [`c298129`](https://github.com/inspect-js/is-typed-array/commit/c2981299c09cd64d89bf1e496447c0379b45d03a) 27 | - [Deps] update `which-typed-array` [`744c29a`](https://github.com/inspect-js/is-typed-array/commit/744c29aa8d4f9df360082074f7b4f2f0d42d76e5) 28 | - [Dev Deps] add missing peer dep [`94d2f5a`](https://github.com/inspect-js/is-typed-array/commit/94d2f5a11016516823e8d943e0bfc7b29dcb146d) 29 | 30 | ## [v1.1.13](https://github.com/inspect-js/is-typed-array/compare/v1.1.12...v1.1.13) - 2024-02-01 31 | 32 | ### Commits 33 | 34 | - [patch] add types [`8a8a679`](https://github.com/inspect-js/is-typed-array/commit/8a8a679937d1c4b970c98556460cef2b7fa0bffb) 35 | - [Dev Deps] update `aud`, `has-tostringtag`, `npmignore`, `object-inspect`, `tape` [`8146b60`](https://github.com/inspect-js/is-typed-array/commit/8146b6019a24f502e66e2c224ce5bea8df9f39bc) 36 | - [actions] optimize finishers [`34f875a`](https://github.com/inspect-js/is-typed-array/commit/34f875ace16c4900d6b0ef4688e9e3eb7d502715) 37 | - [Deps] update `which-typed-array` [`19c974f`](https://github.com/inspect-js/is-typed-array/commit/19c974f4bbd93ffc45cb8638b86688bc00f1420b) 38 | - [meta] add `sideEffects` flag [`0b68e5e`](https://github.com/inspect-js/is-typed-array/commit/0b68e5e58684b79110a82a0a51df8beb7574d6a2) 39 | 40 | ## [v1.1.12](https://github.com/inspect-js/is-typed-array/compare/v1.1.11...v1.1.12) - 2023-07-17 41 | 42 | ### Commits 43 | 44 | - [Refactor] use `which-typed-array` for all internals [`7619405`](https://github.com/inspect-js/is-typed-array/commit/761940532de595f6721fed101b02814dcfa7fe4e) 45 | 46 | ## [v1.1.11](https://github.com/inspect-js/is-typed-array/compare/v1.1.10...v1.1.11) - 2023-07-17 47 | 48 | ### Commits 49 | 50 | - [Fix] `node < v0.6` lacks proper Object toString behavior [`c94b90d`](https://github.com/inspect-js/is-typed-array/commit/c94b90dc6bc457783d6f8cc208415a49da0933b7) 51 | - [Robustness] use `call-bind` [`573b00b`](https://github.com/inspect-js/is-typed-array/commit/573b00b8deec42ac1ac262415e442ea0b7e1c96b) 52 | - [Dev Deps] update `@ljharb/eslint-config`, `aud`, `object-inspect`, `tape` [`c88c2d4`](https://github.com/inspect-js/is-typed-array/commit/c88c2d479976110478fa4038fe8921251c06a163) 53 | 54 | ## [v1.1.10](https://github.com/inspect-js/is-typed-array/compare/v1.1.9...v1.1.10) - 2022-11-02 55 | 56 | ### Commits 57 | 58 | - [meta] add `auto-changelog` [`cf6d86b`](https://github.com/inspect-js/is-typed-array/commit/cf6d86bf2f693eca357439d4d12e76d641f91f92) 59 | - [actions] update rebase action to use reusable workflow [`8da51a5`](https://github.com/inspect-js/is-typed-array/commit/8da51a5dce6d2442ae31ccbc2be136f2e04d6bef) 60 | - [Dev Deps] update `aud`, `is-callable`, `object-inspect`, `tape` [`554e3de`](https://github.com/inspect-js/is-typed-array/commit/554e3deec59dec926d0badc628e589ab363e465b) 61 | - [Refactor] use `gopd` instead of an `es-abstract` helper` [`cdaa465`](https://github.com/inspect-js/is-typed-array/commit/cdaa465d5f94bfc9e32475e31209e1c2458a9603) 62 | - [Deps] update `es-abstract` [`677ae4b`](https://github.com/inspect-js/is-typed-array/commit/677ae4b3c8323b59d6650a9254ab945045c33f79) 63 | 64 | 65 | 66 | 1.1.9 / 2022-05-13 67 | ================= 68 | * [Refactor] use `foreach` instead of `for-each` 69 | * [readme] markdown URL cleanup 70 | * [Deps] update `es-abstract` 71 | * [meta] use `npmignore` to autogenerate an npmignore file 72 | * [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `object-inspect`, `safe-publish-latest`, `tape` 73 | * [actions] reuse common workflows 74 | * [actions] update codecov uploader 75 | 76 | 1.1.8 / 2021-08-30 77 | ================= 78 | * [Refactor] use `globalThis` if available (#53) 79 | * [Deps] update `available-typed-arrays` 80 | * [Dev Deps] update `@ljharb/eslint-config` 81 | 82 | 1.1.7 / 2021-08-07 83 | ================= 84 | * [Fix] if Symbol.toStringTag exists but is not present, use Object.prototype.toString 85 | * [Dev Deps] update `is-callable`, `tape` 86 | 87 | 1.1.6 / 2021-08-05 88 | ================= 89 | * [Fix] use `has-tostringtag` to behave correctly in the presence of symbol shams 90 | * [readme] add actions and codecov badges 91 | * [meta] use `prepublishOnly` script for npm 7+ 92 | * [Deps] update `available-typed-arrays`, `es-abstract` 93 | * [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `object-inspect`, `tape` 94 | * [actions] use `node/install` instead of `node/run`; use `codecov` action 95 | 96 | 1.1.5 / 2021-02-14 97 | ================= 98 | * [meta] do not publish github action workflow files or nyc output 99 | * [Deps] update `call-bind`, `es-abstract` 100 | * [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `is-callable`, `tape` 101 | 102 | 1.1.4 / 2020-12-05 103 | ================= 104 | * [readme] fix repo URLs, remove defunct badges 105 | * [Deps] update `available-typed-arrays`, `es-abstract`; use `call-bind` where applicable 106 | * [meta] gitignore nyc output 107 | * [meta] only audit prod deps 108 | * [actions] add "Allow Edits" workflow 109 | * [actions] switch Automatic Rebase workflow to `pull_request_target` event 110 | * [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `is-callable`, `make-arrow-function`, `make-generator-function`, `object-inspect`, `tape`; add `aud` 111 | * [Tests] migrate tests to Github Actions 112 | * [Tests] run `nyc` on all tests 113 | 114 | 1.1.3 / 2020-01-24 115 | ================= 116 | * [Refactor] use `es-abstract`’s `callBound`, `available-typed-arrays`, `has-symbols` 117 | 118 | 1.1.2 / 2020-01-20 119 | ================= 120 | * [Fix] in envs without Symbol.toStringTag, dc8a8cc made arrays return `true` 121 | * [Tests] add `evalmd` to `prelint` 122 | 123 | 1.1.1 / 2020-01-18 124 | ================= 125 | * [Robustness] don’t rely on Array.prototype.indexOf existing 126 | * [meta] remove unused Makefile and associated utilities 127 | * [meta] add `funding` field; create FUNDING.yml 128 | * [actions] add automatic rebasing / merge commit blocking 129 | * [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `is-callable`, `replace`, `semver`, `tape`; add `safe-publish-latest` 130 | * [Tests] use shared travis-ci configs 131 | * [Tests] use `npx aud` instead of `nsp` or `npm audit` with hoops 132 | 133 | 1.1.0 / 2019-02-16 134 | ================= 135 | * [New] add `BigInt64Array` and `BigUint64Array` 136 | * [Refactor] use an array instead of an object for storing Typed Array names 137 | * [meta] ignore `test.html` 138 | * [Tests] up to `node` `v11.10`, `v10.15`, `v8.15`, `v7.10`, `v6.16`, `v5.10`, `v4.9` 139 | * [Tests] remove `jscs` 140 | * [Tests] use `npm audit` instead of `nsp` 141 | * [Dev Deps] update `eslint`,` @ljharb/eslint-config`, `is-callable`, `tape`, `replace`, `semver` 142 | * [Dev Deps] remove unused eccheck script + dep 143 | 144 | 1.0.4 / 2016-03-19 145 | ================= 146 | * [Fix] `Symbol.toStringTag` is on the super-`[[Prototype]]` of Float32Array, not the `[[Prototype]]` (#3) 147 | * [Tests] up to `node` `v5.9`, `v4.4` 148 | * [Tests] use pretest/posttest for linting/security 149 | * [Dev Deps] update `tape`, `jscs`, `nsp`, `eslint`, `@ljharb/eslint-config`, `semver`, `is-callable` 150 | 151 | 1.0.3 / 2015-10-13 152 | ================= 153 | * [Deps] Add missing `foreach` dependency (#1) 154 | 155 | 1.0.2 / 2015-10-05 156 | ================= 157 | * [Deps] Remove unneeded "isarray" dependency 158 | * [Dev Deps] update `eslint`, `@ljharb/eslint-config` 159 | 160 | 1.0.1 / 2015-10-02 161 | ================= 162 | * Rerelease: avoid instanceof and the constructor property; work cross-realm; work with Symbol.toStringTag. 163 | 164 | 1.0.0 / 2015-05-06 165 | ================= 166 | * Initial release. 167 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Jordan Harband 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # is-typed-array [![Version Badge][npm-version-svg]][package-url] 2 | 3 | [![github actions][actions-image]][actions-url] 4 | [![coverage][codecov-image]][codecov-url] 5 | [![dependency status][5]][6] 6 | [![dev dependency status][7]][8] 7 | [![License][license-image]][license-url] 8 | [![Downloads][downloads-image]][downloads-url] 9 | 10 | [![npm badge][npm-badge-png]][package-url] 11 | 12 | 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. 13 | 14 | ## Example 15 | 16 | ```js 17 | var isTypedArray = require('is-typed-array'); 18 | var assert = require('assert'); 19 | 20 | assert.equal(false, isTypedArray(undefined)); 21 | assert.equal(false, isTypedArray(null)); 22 | assert.equal(false, isTypedArray(false)); 23 | assert.equal(false, isTypedArray(true)); 24 | assert.equal(false, isTypedArray([])); 25 | assert.equal(false, isTypedArray({})); 26 | assert.equal(false, isTypedArray(/a/g)); 27 | assert.equal(false, isTypedArray(new RegExp('a', 'g'))); 28 | assert.equal(false, isTypedArray(new Date())); 29 | assert.equal(false, isTypedArray(42)); 30 | assert.equal(false, isTypedArray(NaN)); 31 | assert.equal(false, isTypedArray(Infinity)); 32 | assert.equal(false, isTypedArray(new Number(42))); 33 | assert.equal(false, isTypedArray('foo')); 34 | assert.equal(false, isTypedArray(Object('foo'))); 35 | assert.equal(false, isTypedArray(function () {})); 36 | assert.equal(false, isTypedArray(function* () {})); 37 | assert.equal(false, isTypedArray(x => x * x)); 38 | assert.equal(false, isTypedArray([])); 39 | 40 | assert.ok(isTypedArray(new Int8Array())); 41 | assert.ok(isTypedArray(new Uint8Array())); 42 | assert.ok(isTypedArray(new Uint8ClampedArray())); 43 | assert.ok(isTypedArray(new Int16Array())); 44 | assert.ok(isTypedArray(new Uint16Array())); 45 | assert.ok(isTypedArray(new Int32Array())); 46 | assert.ok(isTypedArray(new Uint32Array())); 47 | assert.ok(isTypedArray(new Float32Array())); 48 | assert.ok(isTypedArray(new Float64Array())); 49 | assert.ok(isTypedArray(new BigInt64Array())); 50 | assert.ok(isTypedArray(new BigUint64Array())); 51 | ``` 52 | 53 | ## Tests 54 | Simply clone the repo, `npm install`, and run `npm test` 55 | 56 | [package-url]: https://npmjs.org/package/is-typed-array 57 | [npm-version-svg]: https://versionbadg.es/inspect-js/is-typed-array.svg 58 | [deps-svg]: https://david-dm.org/inspect-js/is-typed-array.svg 59 | [deps-url]: https://david-dm.org/inspect-js/is-typed-array 60 | [dev-deps-svg]: https://david-dm.org/inspect-js/is-typed-array/dev-status.svg 61 | [dev-deps-url]: https://david-dm.org/inspect-js/is-typed-array#info=devDependencies 62 | [npm-badge-png]: https://nodei.co/npm/is-typed-array.png?downloads=true&stars=true 63 | [license-image]: https://img.shields.io/npm/l/is-typed-array.svg 64 | [license-url]: LICENSE 65 | [downloads-image]: https://img.shields.io/npm/dm/is-typed-array.svg 66 | [downloads-url]: https://npm-stat.com/charts.html?package=is-typed-array 67 | [codecov-image]: https://codecov.io/gh/inspect-js/is-typed-array/branch/main/graphs/badge.svg 68 | [codecov-url]: https://app.codecov.io/gh/inspect-js/is-typed-array/ 69 | [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/is-typed-array 70 | [actions-url]: https://github.com/inspect-js/is-typed-array/actions 71 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | import type { TypedArray } from 'which-typed-array'; 2 | 3 | declare namespace isTypedArray { 4 | export { TypedArray }; 5 | } 6 | 7 | declare function isTypedArray(value: unknown): value is isTypedArray.TypedArray; 8 | 9 | export = isTypedArray; 10 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var whichTypedArray = require('which-typed-array'); 4 | 5 | /** @type {import('.')} */ 6 | module.exports = function isTypedArray(value) { 7 | return !!whichTypedArray(value); 8 | }; 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "is-typed-array", 3 | "version": "1.1.15", 4 | "author": { 5 | "name": "Jordan Harband", 6 | "email": "ljharb@gmail.com", 7 | "url": "http://ljharb.codes" 8 | }, 9 | "funding": { 10 | "url": "https://github.com/sponsors/ljharb" 11 | }, 12 | "contributors": [ 13 | { 14 | "name": "Jordan Harband", 15 | "email": "ljharb@gmail.com", 16 | "url": "http://ljharb.codes" 17 | } 18 | ], 19 | "description": "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.", 20 | "license": "MIT", 21 | "main": "index.js", 22 | "types": "./index.d.ts", 23 | "sideEffects": false, 24 | "scripts": { 25 | "prepack": "npmignore --auto --commentLines=autogenerated", 26 | "prepublishOnly": "safe-publish-latest", 27 | "prepublish": "not-in-publish || npm run prepublishOnly", 28 | "prelint": "evalmd README.md", 29 | "lint": "eslint --ext=js,mjs .", 30 | "postlint": "tsc -p . && attw -P", 31 | "pretest": "npm run --silent lint", 32 | "test": "npm run tests-only && npm run test:harmony", 33 | "tests-only": "nyc tape test", 34 | "test:harmony": "nyc node --harmony --es-staging test", 35 | "posttest": "npx npm@'>= 10.2' audit --production", 36 | "version": "auto-changelog && git add CHANGELOG.md", 37 | "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" 38 | }, 39 | "repository": { 40 | "type": "git", 41 | "url": "git://github.com/inspect-js/is-typed-array.git" 42 | }, 43 | "keywords": [ 44 | "array", 45 | "TypedArray", 46 | "typed array", 47 | "is", 48 | "typed", 49 | "Int8Array", 50 | "Uint8Array", 51 | "Uint8ClampedArray", 52 | "Int16Array", 53 | "Uint16Array", 54 | "Int32Array", 55 | "Uint32Array", 56 | "Float32Array", 57 | "Float64Array", 58 | "ES6", 59 | "toStringTag", 60 | "Symbol.toStringTag", 61 | "@@toStringTag" 62 | ], 63 | "dependencies": { 64 | "which-typed-array": "^1.1.16" 65 | }, 66 | "devDependencies": { 67 | "@arethetypeswrong/cli": "^0.17.1", 68 | "@ljharb/eslint-config": "^21.1.1", 69 | "@ljharb/tsconfig": "^0.2.2", 70 | "@types/for-each": "^0.3.3", 71 | "@types/is-callable": "^1.1.2", 72 | "@types/make-arrow-function": "^1.2.2", 73 | "@types/make-generator-function": "^2.0.3", 74 | "@types/node": "^20.17.10", 75 | "@types/object-inspect": "^1.13.0", 76 | "@types/tape": "^5.8.0", 77 | "auto-changelog": "^2.5.0", 78 | "encoding": "^0.1.13", 79 | "eslint": "=8.8.0", 80 | "evalmd": "^0.0.19", 81 | "for-each": "^0.3.3", 82 | "has-tostringtag": "^1.0.2", 83 | "in-publish": "^2.0.1", 84 | "is-callable": "^1.2.7", 85 | "make-arrow-function": "^1.2.0", 86 | "make-generator-function": "^2.0.0", 87 | "npmignore": "^0.3.1", 88 | "nyc": "^10.3.2", 89 | "object-inspect": "^1.13.3", 90 | "safe-publish-latest": "^2.0.0", 91 | "tape": "^5.9.0", 92 | "typescript": "next" 93 | }, 94 | "testling": { 95 | "files": "test/index.js", 96 | "browsers": [ 97 | "iexplore/6.0..latest", 98 | "firefox/3.0..6.0", 99 | "firefox/15.0..latest", 100 | "firefox/nightly", 101 | "chrome/4.0..10.0", 102 | "chrome/20.0..latest", 103 | "chrome/canary", 104 | "opera/10.0..latest", 105 | "opera/next", 106 | "safari/4.0..latest", 107 | "ipad/6.0..latest", 108 | "iphone/6.0..latest", 109 | "android-browser/4.2" 110 | ] 111 | }, 112 | "engines": { 113 | "node": ">= 0.4" 114 | }, 115 | "auto-changelog": { 116 | "output": "CHANGELOG.md", 117 | "template": "keepachangelog", 118 | "unreleased": false, 119 | "commitLimit": false, 120 | "backfillLimit": false, 121 | "hideCredit": true, 122 | "startingVersion": "1.1.10" 123 | }, 124 | "publishConfig": { 125 | "ignore": [ 126 | ".github/workflows" 127 | ] 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var test = require('tape'); 4 | var isTypedArray = require('../'); 5 | var isCallable = require('is-callable'); 6 | var hasToStringTag = require('has-tostringtag/shams')(); 7 | var generators = require('make-generator-function')(); 8 | var arrowFn = require('make-arrow-function')(); 9 | var forEach = require('for-each'); 10 | var inspect = require('object-inspect'); 11 | 12 | var typedArrayNames = [ 13 | 'Int8Array', 14 | 'Uint8Array', 15 | 'Uint8ClampedArray', 16 | 'Int16Array', 17 | 'Uint16Array', 18 | 'Int32Array', 19 | 'Uint32Array', 20 | 'Float32Array', 21 | 'Float64Array', 22 | 'BigInt64Array', 23 | 'BigUint64Array' 24 | ]; 25 | 26 | test('not arrays', function (t) { 27 | t.test('non-number/string primitives', function (st) { 28 | // @ts-expect-error Expected 1 arguments, but got 0.ts(2554) 29 | st.notOk(isTypedArray(), 'undefined is not typed array'); 30 | st.notOk(isTypedArray(null), 'null is not typed array'); 31 | st.notOk(isTypedArray(false), 'false is not typed array'); 32 | st.notOk(isTypedArray(true), 'true is not typed array'); 33 | st.end(); 34 | }); 35 | 36 | t.notOk(isTypedArray({}), 'object is not typed array'); 37 | t.notOk(isTypedArray(/a/g), 'regex literal is not typed array'); 38 | t.notOk(isTypedArray(new RegExp('a', 'g')), 'regex object is not typed array'); 39 | t.notOk(isTypedArray(new Date()), 'new Date() is not typed array'); 40 | 41 | t.test('numbers', function (st) { 42 | st.notOk(isTypedArray(42), 'number is not typed array'); 43 | st.notOk(isTypedArray(Object(42)), 'number object is not typed array'); 44 | st.notOk(isTypedArray(NaN), 'NaN is not typed array'); 45 | st.notOk(isTypedArray(Infinity), 'Infinity is not typed array'); 46 | st.end(); 47 | }); 48 | 49 | t.test('strings', function (st) { 50 | st.notOk(isTypedArray('foo'), 'string primitive is not typed array'); 51 | st.notOk(isTypedArray(Object('foo')), 'string object is not typed array'); 52 | st.end(); 53 | }); 54 | 55 | t.end(); 56 | }); 57 | 58 | test('Functions', function (t) { 59 | t.notOk(isTypedArray(function () {}), 'function is not typed array'); 60 | t.end(); 61 | }); 62 | 63 | test('Generators', { skip: generators.length === 0 }, function (t) { 64 | forEach(generators, function (genFn) { 65 | t.notOk(isTypedArray(genFn), 'generator function ' + inspect(genFn) + ' is not typed array'); 66 | }); 67 | t.end(); 68 | }); 69 | 70 | test('Arrow functions', { skip: !arrowFn }, function (t) { 71 | t.notOk(isTypedArray(arrowFn), 'arrow function is not typed array'); 72 | t.end(); 73 | }); 74 | 75 | test('@@toStringTag', { skip: !hasToStringTag }, function (t) { 76 | forEach(typedArrayNames, function (typedArray) { 77 | // @ts-expect-error 78 | if (typeof global[typedArray] === 'function') { 79 | // @ts-expect-error 80 | var fakeTypedArray = []; 81 | // @ts-expect-error 82 | fakeTypedArray[Symbol.toStringTag] = typedArray; 83 | // @ts-expect-error 84 | t.notOk(isTypedArray(fakeTypedArray), 'faked ' + typedArray + ' is not typed array'); 85 | } else { 86 | t.comment('# SKIP ' + typedArray + ' is not supported'); 87 | } 88 | }); 89 | t.end(); 90 | }); 91 | 92 | test('non-Typed Arrays', function (t) { 93 | t.notOk(isTypedArray([]), '[] is not typed array'); 94 | t.end(); 95 | }); 96 | 97 | /** @typedef {Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor | BigInt64ArrayConstructor | BigUint64ArrayConstructor} TypedArrayConstructor */ 98 | 99 | test('Typed Arrays', function (t) { 100 | forEach(typedArrayNames, function (typedArray) { 101 | // @ts-expect-error 102 | /** @type {TypedArrayConstructor} */ var TypedArray = global[typedArray]; 103 | if (isCallable(TypedArray)) { 104 | var arr = new TypedArray(10); 105 | t.ok(isTypedArray(arr), 'new ' + typedArray + '(10) is typed array'); 106 | } else { 107 | t.comment('# SKIP ' + typedArray + ' is not supported'); 108 | } 109 | }); 110 | t.end(); 111 | }); 112 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@ljharb/tsconfig", 3 | "exclude": [ 4 | "coverage", 5 | ], 6 | } 7 | --------------------------------------------------------------------------------