pax_global_header 0000666 0000000 0000000 00000000064 15206064206 0014513 g ustar 00root root 0000000 0000000 52 comment=a010b13975273ff20a96947fe51ebf59d4c48cc7
inspect-js-typed-array-length-0c44364/ 0000775 0000000 0000000 00000000000 15206064206 0017561 5 ustar 00root root 0000000 0000000 inspect-js-typed-array-length-0c44364/.github/ 0000775 0000000 0000000 00000000000 15206064206 0021121 5 ustar 00root root 0000000 0000000 inspect-js-typed-array-length-0c44364/.github/FUNDING.yml 0000664 0000000 0000000 00000001115 15206064206 0022734 0 ustar 00root root 0000000 0000000 # These are supported funding model platforms
github: [ljharb]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: npm/typed-array-length
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
inspect-js-typed-array-length-0c44364/.github/workflows/ 0000775 0000000 0000000 00000000000 15206064206 0023156 5 ustar 00root root 0000000 0000000 inspect-js-typed-array-length-0c44364/.github/workflows/node-aught.yml 0000664 0000000 0000000 00000000354 15206064206 0025736 0 ustar 00root root 0000000 0000000 name: 'Tests: node.js < 10'
on: [pull_request, push]
jobs:
tests:
uses: ljharb/actions/.github/workflows/node.yml@main
with:
range: '< 10'
type: minors
command: npm run tests-only
skip-ls-check: true
inspect-js-typed-array-length-0c44364/.github/workflows/node-harmony.yml 0000664 0000000 0000000 00000000372 15206064206 0026303 0 ustar 00root root 0000000 0000000 name: 'Tests: node.js (harmony)'
on: [pull_request, push]
jobs:
tests:
uses: ljharb/actions/.github/workflows/node.yml@main
with:
range: '>= 0.8 < 16'
type: minors
command: npm run test:harmony
skip-ls-check: true
inspect-js-typed-array-length-0c44364/.github/workflows/node-pretest.yml 0000664 0000000 0000000 00000000206 15206064206 0026310 0 ustar 00root root 0000000 0000000 name: 'Tests: pretest/posttest'
on: [pull_request, push]
jobs:
tests:
uses: ljharb/actions/.github/workflows/pretest.yml@main
inspect-js-typed-array-length-0c44364/.github/workflows/node-tens.yml 0000664 0000000 0000000 00000000372 15206064206 0025577 0 ustar 00root root 0000000 0000000 name: 'Tests: node.js 10 - 20'
on: [pull_request, push]
permissions:
contents: read
jobs:
tests:
uses: ljharb/actions/.github/workflows/node.yml@main
with:
range: '>= 10 < 20'
type: minors
command: npm run tests-only
inspect-js-typed-array-length-0c44364/.github/workflows/node-twenties.yml 0000664 0000000 0000000 00000002107 15206064206 0026466 0 ustar 00root root 0000000 0000000 name: 'Tests: node.js >= 20'
on: [pull_request, push]
permissions:
contents: read
jobs:
tests:
uses: ljharb/actions/.github/workflows/node.yml@main
with:
range: '>= 20'
type: minors
command: npm run tests-only
no-proto:
name: 'node, --disable-proto=delete'
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
disable-sudo: true
egress-policy: audit
allowed-endpoints: >
github.com:443
raw.githubusercontent.com:443
nodejs.org:443
iojs.org:443
registry.npmjs.org:443
actions-results-receiver-production.githubapp.com:443
- uses: actions/checkout@v4
with:
show-progress: false
- uses: ljharb/actions/node/install@main
- run: NODE_OPTIONS=--disable-proto=delete npm run tests-only
- uses: codecov/codecov-action@v3.1.5
finisher:
needs: [tests, no-proto]
name: 'node >= 20'
runs-on: ubuntu-latest
steps:
- run: true
inspect-js-typed-array-length-0c44364/.github/workflows/rebase.yml 0000664 0000000 0000000 00000000257 15206064206 0025146 0 ustar 00root root 0000000 0000000 name: Automatic Rebase
on: [pull_request_target]
jobs:
_:
uses: ljharb/actions/.github/workflows/rebase.yml@main
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
inspect-js-typed-array-length-0c44364/.github/workflows/require-allow-edits.yml 0000664 0000000 0000000 00000000303 15206064206 0027573 0 ustar 00root root 0000000 0000000 name: Require “Allow Edits”
on: [pull_request_target]
jobs:
_:
name: "Require “Allow Edits”"
runs-on: ubuntu-latest
steps:
- uses: ljharb/require-allow-edits@main
inspect-js-typed-array-length-0c44364/.gitignore 0000664 0000000 0000000 00000003251 15206064206 0021552 0 ustar 00root root 0000000 0000000 # Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# Next.js build output
.next
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Only apps should have lockfiles
npm-shrinkwrap.json
package-lock.json
yarn.lock
.npmignore
inspect-js-typed-array-length-0c44364/.npmrc 0000664 0000000 0000000 00000000067 15206064206 0020704 0 ustar 00root root 0000000 0000000 package-lock=false
allow-same-version=true
message=v%s
inspect-js-typed-array-length-0c44364/.nycrc 0000664 0000000 0000000 00000000330 15206064206 0020674 0 ustar 00root root 0000000 0000000 {
"all": true,
"check-coverage": false,
"reporter": ["text-summary", "text", "html", "json"],
"lines": 86,
"statements": 85.93,
"functions": 82.43,
"branches": 76.06,
"exclude": [
"coverage",
"test"
]
}
inspect-js-typed-array-length-0c44364/CHANGELOG.md 0000664 0000000 0000000 00000026462 15206064206 0021404 0 ustar 00root root 0000000 0000000 # Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1.0.8](https://github.com/inspect-js/typed-array-length/compare/v1.0.7...v1.0.8) - 2026-05-28
### Commits
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`; migrate to flat config [`24ae7de`](https://github.com/inspect-js/typed-array-length/commit/24ae7de57fa5e3f3da07b80a3cf78c73f0af4327)
- [Dev Deps] update `@arethetypeswrong/cli`, `@ljharb/eslint-config`, `@ljharb/tsconfig`, `@types/tape`, `eslint`, `make-generator-function`, `npmignore`, `object-inspect` [`157fbce`](https://github.com/inspect-js/typed-array-length/commit/157fbce5cfaa4ab63492014fc13a2a70efd1f9fe)
- [types] improve types [`9580efa`](https://github.com/inspect-js/typed-array-length/commit/9580efac65f3728f65f679e3380e29522428de39)
- [Deps] update `call-bind`, `for-each`, `is-typed-array`, `possible-typed-array-names`, `reflect.getprototypeof` [`0b6c478`](https://github.com/inspect-js/typed-array-length/commit/0b6c478a07e57d883b7ea7c379f81c863aebc442)
- [Deps] update `call-bind`, `gopd`, `is-typed-array`, `reflect.getprototypeof` [`25825a3`](https://github.com/inspect-js/typed-array-length/commit/25825a3b562f42c93e2ab93bfedf8329ab4c76e1)
- [Dev Deps] update `@ljharb/eslint-config`, `auto-changelog`, `eslint` [`ee0f33d`](https://github.com/inspect-js/typed-array-length/commit/ee0f33d09047d1b9680b18849bc51c20d96761e3)
- [Dev Deps] update `@arethetypeswrong/cli`, `@ljharb/tsconfig`, `@types/tape` [`075f435`](https://github.com/inspect-js/typed-array-length/commit/075f435ba8aa79679a063c37681a6173a1cbd1b7)
- [Dev Deps] update `eslint` [`a16cdcc`](https://github.com/inspect-js/typed-array-length/commit/a16cdcc8dfcf3612cf64238a0e2685dfc1cbb6c1)
## [v1.0.7](https://github.com/inspect-js/typed-array-length/compare/v1.0.6...v1.0.7) - 2024-11-22
### Fixed
- [Fix] avoid relying on `__proto__` accessor [`#9`](https://github.com/inspect-js/typed-array-length/issues/9)
### Commits
- [Tests] fix TS issues [`f36b6bd`](https://github.com/inspect-js/typed-array-length/commit/f36b6bdbe472923cdd24158705a19b91ae5f512c)
- [actions] split out node 10-20, and 20+ [`d81efa0`](https://github.com/inspect-js/typed-array-length/commit/d81efa0b275161e82f78ceddb3ccf0bd63c2b834)
- [Dev Deps] update `@arethetypeswrong/cli`, `@ljharb/eslint-config`, `@types/object-inspect`, `auto-changelog`, `object-inspect`, `tape` [`a61b15b`](https://github.com/inspect-js/typed-array-length/commit/a61b15baa1dbc40d0fdd0e23779bfa32acab6f5e)
- [Tests] replace `aud` with `npm audit` [`b0b4e8f`](https://github.com/inspect-js/typed-array-length/commit/b0b4e8fa9a3050edcddead80e86765d8fd78298c)
## [v1.0.6](https://github.com/inspect-js/typed-array-length/compare/v1.0.5...v1.0.6) - 2024-03-21
### Commits
- [types] vastly improve types [`9f68d36`](https://github.com/inspect-js/typed-array-length/commit/9f68d36cdc1abeb412f47e91de289b5fb903a696)
- [types] use shared config [`b6b3cbc`](https://github.com/inspect-js/typed-array-length/commit/b6b3cbcaf8f4a46f5bcb77226d4cea2b3f62ffe2)
- [actions] remove redundant finisher [`c69896e`](https://github.com/inspect-js/typed-array-length/commit/c69896e0d71e9f6da562b9ae0eaba415e4cbff26)
- [Tests] actually check types in tests, and add attw [`e2c3f94`](https://github.com/inspect-js/typed-array-length/commit/e2c3f948bd0b898c38e1d9f63cd9702e728a7109)
## [v1.0.5](https://github.com/inspect-js/typed-array-length/compare/v1.0.4...v1.0.5) - 2024-02-20
### Commits
- add types [`df51e65`](https://github.com/inspect-js/typed-array-length/commit/df51e65a85fa6d1a98571ab30398b36ac2c981bb)
- [Refactor] use `possible-typed-array-names` for a single source of truth [`84503a3`](https://github.com/inspect-js/typed-array-length/commit/84503a3d406e8ae1cc84cf6e893cacc556be664a)
- [actions] update rebase action to use reusable workflow [`f163023`](https://github.com/inspect-js/typed-array-length/commit/f16302365bbb353b0504a41d997fa18196757c80)
- [Dev Deps] update `@ljharb/eslint-config`, `aud`, `npmignore`, `object-inspect`, `tape` [`57ca930`](https://github.com/inspect-js/typed-array-length/commit/57ca93013d607c0ac46b749d8258bb341b903567)
- [Dev Deps] update `aud`, `is-callable`, `object-inspect`, `tape` [`99343f4`](https://github.com/inspect-js/typed-array-length/commit/99343f477d68f2d53597bc0cadf93e532a498138)
- [Refactor] use `gopd` and `has-proto` [`b134a5c`](https://github.com/inspect-js/typed-array-length/commit/b134a5cc4bea1666f4195d6b6c6e97617305420f)
- [Deps] update `call-bind`, `is-typed-array` [`3b62f55`](https://github.com/inspect-js/typed-array-length/commit/3b62f55cc52da8b4c9548fb8839f0e4db222ac1b)
- [meta] add missing `engines.node` [`ff3e9f7`](https://github.com/inspect-js/typed-array-length/commit/ff3e9f7b8d72c0c2d1e9c2122a701ac454e6552c)
- [Deps] update `is-typed-array` [`877f507`](https://github.com/inspect-js/typed-array-length/commit/877f507048ece8b1db6402b56d512c7eb3337ce9)
- [meta] add `sideEffects` flag [`6e91309`](https://github.com/inspect-js/typed-array-length/commit/6e913098eaca5132a3595b0653d211ffec93f2c6)
## [v1.0.4](https://github.com/inspect-js/typed-array-length/compare/v1.0.3...v1.0.4) - 2022-05-23
### Commits
- [actions] reuse common workflows [`dfd4a37`](https://github.com/inspect-js/typed-array-length/commit/dfd4a37d851a28e3d74d892a69874e02f2e58c37)
- [meta] use `npmignore` to autogenerate an npmignore file [`a837e80`](https://github.com/inspect-js/typed-array-length/commit/a837e80d4029f26785ab9f3aa571ca782ac8e851)
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `auto-changelog`, `is-callable`, `object-inspect`, `tape` [`7b05a87`](https://github.com/inspect-js/typed-array-length/commit/7b05a8772af399e52bb448618a246cd34d3e3273)
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `auto-changelog`, `object-inspect`, `tape` [`c495f6e`](https://github.com/inspect-js/typed-array-length/commit/c495f6e050a4a7463a82c9195f31f44cf2760945)
- [meta] simplify "exports" [`e42a6b6`](https://github.com/inspect-js/typed-array-length/commit/e42a6b6b0dc243fce32df20a75a7962782ef2a83)
- [Fix] ensure `for-each` dependency is properly listed [`8ec761c`](https://github.com/inspect-js/typed-array-length/commit/8ec761ca56c13927281d626958a2f55211e14f45)
- [Deps] update `call-bind`, `is-typed-array` [`2cc173a`](https://github.com/inspect-js/typed-array-length/commit/2cc173a4216e167db896bea7b8e03edf8b2d3833)
- [meta] add `safe-publish-latest` [`e8e3afa`](https://github.com/inspect-js/typed-array-length/commit/e8e3afa431ce98bbdbb68c9f8e3c029cc5128c6c)
- [Deps] update `is-typed-array` [`cd8084d`](https://github.com/inspect-js/typed-array-length/commit/cd8084db59b734ac4519b6d47f96233b6f73b1a6)
## [v1.0.3](https://github.com/inspect-js/typed-array-length/compare/v1.0.2...v1.0.3) - 2020-12-05
### Commits
- [Tests] migrate tests to Github Actions [`a578b83`](https://github.com/inspect-js/typed-array-length/commit/a578b83e68055c1e7c7120bc4583e1d6926fc268)
- [meta] avoid publishing github workflows [`f064a4b`](https://github.com/inspect-js/typed-array-length/commit/f064a4bf9090202154249d969be0799c34804ad4)
- [Tests] run `nyc` on all tests [`69b841e`](https://github.com/inspect-js/typed-array-length/commit/69b841e43042358c71c3290342514b6d107f08d1)
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `auto-changelog`, `object-inspect`, `tape` [`4594e83`](https://github.com/inspect-js/typed-array-length/commit/4594e83250579cdbff870aa951e7af56ca169489)
- [actions] add "Allow Edits" workflow [`81e953b`](https://github.com/inspect-js/typed-array-length/commit/81e953ba6b3f59c5657e0d17fa1e7619b94891f5)
- [Deps] update `is-typed-array`; use `call-bind` instead of `es-abstract` [`e7da56b`](https://github.com/inspect-js/typed-array-length/commit/e7da56b3c03b7f0db9bb110444ec1ccf19d7e9f9)
- [readme] remove travis badge [`6d610d8`](https://github.com/inspect-js/typed-array-length/commit/6d610d83cb78ac5286c5ca273f4b3c7289f7686e)
- [actions] switch Automatic Rebase workflow to `pull_request_target` event [`2d0ad64`](https://github.com/inspect-js/typed-array-length/commit/2d0ad644a11f754e61b49d327fdf891605abbe58)
## [v1.0.2](https://github.com/inspect-js/typed-array-length/compare/v1.0.1...v1.0.2) - 2020-04-22
### Commits
- [Dev Deps] update `make-arrow-function`, `make-generator-function` [`4facf69`](https://github.com/inspect-js/typed-array-length/commit/4facf697cafb36b9c1057dc4ca1a21d8550c564e)
- [Deps] update `is-typed-array`, `es-abstract` [`aaf3585`](https://github.com/inspect-js/typed-array-length/commit/aaf3585429896b9520dedd886c07aa4a96b50615)
- [Dev Deps] update `aud`, `auto-changelog` [`f10e298`](https://github.com/inspect-js/typed-array-length/commit/f10e298c7733b8de59231c1581c9b000c205edbd)
- [meta] allow `package.json` to be required/imported [`104f4c6`](https://github.com/inspect-js/typed-array-length/commit/104f4c6a6363e600d54aeb7abd90e37d99693aaf)
- [Tests] only audit prod deps [`c748ab5`](https://github.com/inspect-js/typed-array-length/commit/c748ab596de505483df14ca7eeda7f27aeb20383)
- [Deps] update `es-abstract` [`6cd213e`](https://github.com/inspect-js/typed-array-length/commit/6cd213ec654da3325abc8190f8c07c860474d944)
- [Dev Deps] update `tape` [`2b0b2ea`](https://github.com/inspect-js/typed-array-length/commit/2b0b2ea9be106e8a068597c3f499ef703cce1edb)
- [Dev Deps] update `@ljharb/eslint-config` [`cf462f3`](https://github.com/inspect-js/typed-array-length/commit/cf462f3352cf2fd592e624746371e3de800a265d)
- [Deps] update `is-typed-array` [`ff46995`](https://github.com/inspect-js/typed-array-length/commit/ff469955b5d92942ba066c77eac7467e0c4de1ec)
## [v1.0.1](https://github.com/inspect-js/typed-array-length/compare/v1.0.0...v1.0.1) - 2020-01-19
### Commits
- readme [`d3643fd`](https://github.com/inspect-js/typed-array-length/commit/d3643fd11919844b1f42041ef980a1f33215b515)
- [meta] fix "exports" field [`006e28b`](https://github.com/inspect-js/typed-array-length/commit/006e28b30b11f8948e607d13ef0e96c3d7d7f61f)
## v1.0.0 - 2020-01-18
### Commits
- Initial commit [`5f9e2ec`](https://github.com/inspect-js/typed-array-length/commit/5f9e2ec6650f80dc894e354e9e98181b09006346)
- Tests [`6b9cadb`](https://github.com/inspect-js/typed-array-length/commit/6b9cadb0c274933bc7ee5e3fc6a5a380163cbe76)
- Implementation [`6a3cb50`](https://github.com/inspect-js/typed-array-length/commit/6a3cb50429f40fc4ac9020bbf9539560c1b70213)
- npm init [`41d42cd`](https://github.com/inspect-js/typed-array-length/commit/41d42cddfd3d47df6c9d480cf77787eae1109432)
- [meta] add `auto-changelog` [`4fd159b`](https://github.com/inspect-js/typed-array-length/commit/4fd159bc6535e86c370a2186d60a68656f0d8917)
- [meta] add `funding` field; create FUNDING.yml [`6a9fca7`](https://github.com/inspect-js/typed-array-length/commit/6a9fca7e0fdf3ff3fd4b0f18596471ca3d050a39)
- [actions] add automatic rebasing / merge commit blocking [`8303296`](https://github.com/inspect-js/typed-array-length/commit/83032967b14afd37c382d4bf2c1fc5c95e3764bd)
- [Tests] add `npm run lint` [`47a9c21`](https://github.com/inspect-js/typed-array-length/commit/47a9c211f474dbe8528f6b28f50080eacd5bf7eb)
- [Tests] use shared travis-ci configs [`d0c8915`](https://github.com/inspect-js/typed-array-length/commit/d0c89153e1c50f1eadd0b42521bcdcf3366b8af5)
- Only apps should have lockfiles [`3eaef9c`](https://github.com/inspect-js/typed-array-length/commit/3eaef9cd192b1a25d1930739e7c0044e39ad3c0d)
inspect-js-typed-array-length-0c44364/LICENSE 0000664 0000000 0000000 00000002053 15206064206 0020566 0 ustar 00root root 0000000 0000000 MIT License
Copyright (c) 2020 Inspect JS
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
inspect-js-typed-array-length-0c44364/README.md 0000664 0000000 0000000 00000005365 15206064206 0021051 0 ustar 00root root 0000000 0000000 # typed-array-length [![Version Badge][2]][1]
[![dependency status][5]][6]
[![dev dependency status][7]][8]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]
[![npm badge][11]][1]
Robustly get the length of a Typed Array, or `false` if it is not a Typed Array. Works cross-realm, in every engine, even if the `length` property is overridden.
## Example
```js
var typedArrayLength = require('typed-array-length');
var assert = require('assert');
assert.equal(false, typedArrayLength(undefined));
assert.equal(false, typedArrayLength(null));
assert.equal(false, typedArrayLength(false));
assert.equal(false, typedArrayLength(true));
assert.equal(false, typedArrayLength([]));
assert.equal(false, typedArrayLength({}));
assert.equal(false, typedArrayLength(/a/g));
assert.equal(false, typedArrayLength(new RegExp('a', 'g')));
assert.equal(false, typedArrayLength(new Date()));
assert.equal(false, typedArrayLength(42));
assert.equal(false, typedArrayLength(NaN));
assert.equal(false, typedArrayLength(Infinity));
assert.equal(false, typedArrayLength(new Number(42)));
assert.equal(false, typedArrayLength('foo'));
assert.equal(false, typedArrayLength(Object('foo')));
assert.equal(false, typedArrayLength(function () {}));
assert.equal(false, typedArrayLength(function* () {}));
assert.equal(false, typedArrayLength(x => x * x));
assert.equal(false, typedArrayLength([]));
assert.equal(1, typedArrayLength(new Int8Array(1)));
assert.equal(2, typedArrayLength(new Uint8Array(2)));
assert.equal(3, typedArrayLength(new Uint8ClampedArray(3)));
assert.equal(4, typedArrayLength(new Int16Array(4)));
assert.equal(5, typedArrayLength(new Uint16Array(5)));
assert.equal(6, typedArrayLength(new Int32Array(6)));
assert.equal(7, typedArrayLength(new Uint32Array(7)));
assert.equal(8, typedArrayLength(new Float32Array(8)));
assert.equal(9, typedArrayLength(new Float64Array(9)));
assert.equal(10, typedArrayLength(new BigInt64Array(10)));
assert.equal(11, typedArrayLength(new BigUint64Array(11)));
```
## Tests
Simply clone the repo, `npm install`, and run `npm test`
[1]: https://npmjs.org/package/typed-array-length
[2]: https://versionbadg.es/inspect-js/typed-array-length.svg
[5]: https://david-dm.org/inspect-js/typed-array-length.svg
[6]: https://david-dm.org/inspect-js/typed-array-length
[7]: https://david-dm.org/inspect-js/typed-array-length/dev-status.svg
[8]: https://david-dm.org/inspect-js/typed-array-length#info=devDependencies
[11]: https://nodei.co/npm/typed-array-length.png?downloads=true&stars=true
[license-image]: http://img.shields.io/npm/l/typed-array-length.svg
[license-url]: LICENSE
[downloads-image]: http://img.shields.io/npm/dm/typed-array-length.svg
[downloads-url]: http://npm-stat.com/charts.html?package=typed-array-length
inspect-js-typed-array-length-0c44364/eslint.config.mjs 0000664 0000000 0000000 00000000370 15206064206 0023036 0 ustar 00root root 0000000 0000000 import ljharbConfig from '@ljharb/eslint-config/flat';
export default [
...ljharbConfig,
{
rules: {
complexity: ['error', 11],
'max-statements': ['error', 15],
'new-cap': ['error', { capIsNewExceptions: ['IsCallable'] }],
},
},
];
inspect-js-typed-array-length-0c44364/index.d.ts 0000664 0000000 0000000 00000000607 15206064206 0021465 0 ustar 00root root 0000000 0000000 import type names from 'possible-typed-array-names';
import type { TypedArray } from 'is-typed-array';
declare function typedArrayLength(value: typedArrayLength.TypedArray): number;
declare function typedArrayLength(value: unknown): false;
declare namespace typedArrayLength {
export type { TypedArray };
export type TypedArrayName = typeof names[number];
}
export = typedArrayLength;
inspect-js-typed-array-length-0c44364/index.js 0000664 0000000 0000000 00000005552 15206064206 0021235 0 ustar 00root root 0000000 0000000 'use strict';
// /
var callBind = require('call-bind');
var forEach = require('for-each');
var gOPD = require('gopd');
var isTypedArray = require('is-typed-array');
var typedArrays = require('possible-typed-array-names');
var gPO = require('reflect.getprototypeof/polyfill')();
/** @typedef {(value: import('.').TypedArray) => number} TypedArrayLengthGetter */
/** @typedef {{ [k in `$${import('.').TypedArrayName}` | '__proto__']: k extends '__proto__' ? null : TypedArrayLengthGetter }} Cache */
/** @type {Cache} */
// @ts-expect-error TS `satisfies` doesn't work in jsdoc
var getters = { __proto__: null };
var oDP = Object.defineProperty;
if (gOPD) {
var getLength = /** @type {TypedArrayLengthGetter} */ function (x) {
return x.length;
};
forEach(typedArrays, /** @type {(typedArray: import('.').TypedArrayName) => void} */ function (typedArray) {
var TA = global[typedArray];
// In Safari 7, Typed Array constructors are typeof object
if (typeof TA === 'function' || typeof TA === 'object') {
var Proto = TA.prototype;
// @ts-expect-error TS doesn't narrow types inside callbacks, which is weird
var descriptor = gOPD(Proto, 'length');
if (!descriptor) {
var superProto = gPO(Proto);
// @ts-expect-error TS doesn't narrow types inside callbacks, which is weird
descriptor = gOPD(superProto, 'length');
}
// Opera 12.16 has a magic length data property on instances AND on Proto
if (descriptor && descriptor.get) {
// eslint-disable-next-line no-extra-parens
getters[/** @type {`$${import('.').TypedArrayName}`} */ ('$' + typedArray)] = callBind(descriptor.get);
} else if (oDP) {
// this is likely an engine where instances have a magic length data property
var arr = new global[typedArray](2);
// @ts-expect-error TS doesn't narrow types inside callbacks, which is weird
descriptor = gOPD(arr, 'length');
if (descriptor && descriptor.configurable) {
oDP(arr, 'length', { value: 3 });
}
if (arr.length === 2) {
// eslint-disable-next-line no-extra-parens
getters[/** @type {`$${import('.').TypedArrayName}`} */ ('$' + typedArray)] = getLength;
}
}
}
});
}
/** @type {TypedArrayLengthGetter} */
var tryTypedArrays = function tryAllTypedArrays(value) {
/** @type {number} */ var foundLength;
// @ts-expect-error not sure why this won't work
forEach(getters, /** @type {(getter: TypedArrayLengthGetter) => void} */ function (getter) {
if (typeof foundLength !== 'number') {
try {
var length = getter(value);
if (typeof length === 'number') {
foundLength = length;
}
} catch (e) {}
}
});
// @ts-expect-error TS can't guarantee the above callback is invoked sync
return foundLength;
};
/** @type {import('.')} */
module.exports = function typedArrayLength(value) {
if (!isTypedArray(value)) {
return false;
}
return tryTypedArrays(value);
};
inspect-js-typed-array-length-0c44364/package.json 0000664 0000000 0000000 00000005606 15206064206 0022056 0 ustar 00root root 0000000 0000000 {
"name": "typed-array-length",
"version": "1.0.8",
"description": "Robustly get the length of a Typed Array",
"main": "index.js",
"exports": {
".": "./index.js",
"./package.json": "./package.json"
},
"types": "./index.d.ts",
"sideEffects": false,
"scripts": {
"prepack": "npmignore --auto --commentLines=autogenerated",
"prepublishOnly": "safe-publish-latest",
"prepublish": "not-in-publish || npm run prepublishOnly",
"pretest": "npm run lint",
"prelint": "evalmd README.md",
"lint": "eslint .",
"postlint": "tsc -p . && attw -P",
"tests-only": "nyc tape 'test/**/*.js'",
"test:harmony": "nyc node --harmony --es-staging test",
"test": "npm run tests-only && npm run test:harmony",
"posttest": "npx npm@'>=10.2' audit --production",
"version": "auto-changelog && git add CHANGELOG.md",
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
},
"repository": {
"type": "git",
"url": "git+https://github.com/inspect-js/typed-array-length.git"
},
"keywords": [
"typed",
"array",
"length",
"robust",
"es",
"Int8Array",
"Uint8Array",
"Uint8ClampedArray",
"Int16Array",
"Uint16Array",
"Int32Array",
"Uint32Array",
"Float32Array",
"Float64Array"
],
"author": "Jordan Harband ",
"funding": {
"url": "https://github.com/sponsors/ljharb"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/inspect-js/typed-array-length/issues"
},
"homepage": "https://github.com/inspect-js/typed-array-length#readme",
"devDependencies": {
"@arethetypeswrong/cli": "^0.18.2",
"@ljharb/eslint-config": "^22.2.3",
"@ljharb/tsconfig": "^0.3.2",
"@types/call-bind": "^1.0.5",
"@types/for-each": "^0.3.3",
"@types/gopd": "^1.0.3",
"@types/is-callable": "^1.1.2",
"@types/make-arrow-function": "^1.2.2",
"@types/make-generator-function": "^2.0.3",
"@types/object-inspect": "^1.13.0",
"@types/tape": "^5.8.1",
"auto-changelog": "^2.5.1",
"eslint": "^10.4.0",
"evalmd": "^0.0.19",
"in-publish": "^2.0.1",
"is-callable": "^1.2.7",
"jiti": "^0.0.0",
"make-arrow-function": "^1.2.0",
"make-generator-function": "^2.1.0",
"npmignore": "^0.3.5",
"nyc": "^10.3.2",
"object-inspect": "^1.13.4",
"safe-publish-latest": "^2.0.0",
"tape": "^5.9.0",
"typescript": "next"
},
"auto-changelog": {
"output": "CHANGELOG.md",
"template": "keepachangelog",
"unreleased": false,
"commitLimit": false,
"backfillLimit": false,
"hideCredit": true
},
"dependencies": {
"call-bind": "^1.0.9",
"for-each": "^0.3.5",
"gopd": "^1.2.0",
"is-typed-array": "^1.1.15",
"possible-typed-array-names": "^1.1.0",
"reflect.getprototypeof": "^1.0.10"
},
"testling": {
"files": "test/index.js"
},
"publishConfig": {
"ignore": [
".github/workflows",
"types"
]
},
"engines": {
"node": ">= 0.4"
}
}
inspect-js-typed-array-length-0c44364/test/ 0000775 0000000 0000000 00000000000 15206064206 0020540 5 ustar 00root root 0000000 0000000 inspect-js-typed-array-length-0c44364/test/index.js 0000664 0000000 0000000 00000005605 15206064206 0022213 0 ustar 00root root 0000000 0000000 'use strict';
var test = require('tape');
var typedArrayLength = require('../');
var isCallable = require('is-callable');
var generators = require('make-generator-function')();
var arrowFn = require('make-arrow-function')();
var forEach = require('for-each');
var inspect = require('object-inspect');
var typedArrayNames = require('possible-typed-array-names');
test('not arrays', function (t) {
t.test('non-number/string primitives', function (st) {
// @ts-expect-error
st.equal(false, typedArrayLength(), 'undefined is not typed array');
st.equal(false, typedArrayLength(null), 'null is not typed array');
st.equal(false, typedArrayLength(false), 'false is not typed array');
st.equal(false, typedArrayLength(true), 'true is not typed array');
st.end();
});
t.equal(false, typedArrayLength({}), 'object is not typed array');
t.equal(false, typedArrayLength(/a/g), 'regex literal is not typed array');
t.equal(false, typedArrayLength(new RegExp('a', 'g')), 'regex object is not typed array');
t.equal(false, typedArrayLength(new Date()), 'new Date() is not typed array');
t.test('numbers', function (st) {
st.equal(false, typedArrayLength(42), 'number is not typed array');
st.equal(false, typedArrayLength(Object(42)), 'number object is not typed array');
st.equal(false, typedArrayLength(NaN), 'NaN is not typed array');
st.equal(false, typedArrayLength(Infinity), 'Infinity is not typed array');
st.end();
});
t.test('strings', function (st) {
st.equal(false, typedArrayLength('foo'), 'string primitive is not typed array');
st.equal(false, typedArrayLength(Object('foo')), 'string object is not typed array');
st.end();
});
t.end();
});
test('Functions', function (t) {
t.equal(false, typedArrayLength(function () {}), 'function is not typed array');
t.end();
});
test('Generators', { skip: generators.length === 0 }, function (t) {
forEach(generators, function (genFn) {
t.equal(false, typedArrayLength(genFn), 'generator function ' + inspect(genFn) + ' is not typed array');
});
t.end();
});
test('Arrow functions', { skip: !arrowFn }, function (t) {
t.equal(false, typedArrayLength(arrowFn), 'arrow function is not typed array');
t.end();
});
test('Typed Arrays', function (t) {
forEach(typedArrayNames, function (typedArray) {
/** @type {Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float16ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor | BigInt64ArrayConstructor | BigUint64ArrayConstructor} */
var TypedArray = global[typedArray];
if (isCallable(TypedArray)) {
var length = 10;
var arr = new TypedArray(length);
t.equal(typedArrayLength(arr), length, 'new ' + typedArray + '(10) is typed array of length ' + length);
} else {
t.comment('# SKIP ' + typedArray + ' is not supported');
}
});
t.end();
});
inspect-js-typed-array-length-0c44364/tsconfig.json 0000664 0000000 0000000 00000000221 15206064206 0022263 0 ustar 00root root 0000000 0000000 {
"extends": "@ljharb/tsconfig",
"compilerOptions": {
"target": "ES2021",
"maxNodeModuleJsDepth": 0,
},
"exclude": [
"coverage",
],
}
inspect-js-typed-array-length-0c44364/types/ 0000775 0000000 0000000 00000000000 15206064206 0020725 5 ustar 00root root 0000000 0000000 inspect-js-typed-array-length-0c44364/types/reflect.getprototypeof/ 0000775 0000000 0000000 00000000000 15206064206 0025442 5 ustar 00root root 0000000 0000000 inspect-js-typed-array-length-0c44364/types/reflect.getprototypeof/polyfill.d.ts 0000664 0000000 0000000 00000000213 15206064206 0030062 0 ustar 00root root 0000000 0000000 declare module 'reflect.getprototypeof/polyfill' {
function getPolyfill(): typeof Reflect.getPrototypeOf;
export = getPolyfill;
}