pax_global_header 0000666 0000000 0000000 00000000064 14730376041 0014517 g ustar 00root root 0000000 0000000 52 comment=e8e0b5b1625b45fca47eea2931f8b9185fa19da1
inspect-js-typed-array-byte-length-1ff4b11/ 0000775 0000000 0000000 00000000000 14730376041 0020663 5 ustar 00root root 0000000 0000000 inspect-js-typed-array-byte-length-1ff4b11/.eslintrc 0000664 0000000 0000000 00000000146 14730376041 0022510 0 ustar 00root root 0000000 0000000 {
"root": true,
"extends": "@ljharb",
"globals": {
"Uint8Array": false,
},
"rules": {
},
}
inspect-js-typed-array-byte-length-1ff4b11/.github/ 0000775 0000000 0000000 00000000000 14730376041 0022223 5 ustar 00root root 0000000 0000000 inspect-js-typed-array-byte-length-1ff4b11/.github/FUNDING.yml 0000664 0000000 0000000 00000001115 14730376041 0024036 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-byte-length-1ff4b11/.github/workflows/ 0000775 0000000 0000000 00000000000 14730376041 0024260 5 ustar 00root root 0000000 0000000 inspect-js-typed-array-byte-length-1ff4b11/.github/workflows/node-aught.yml 0000664 0000000 0000000 00000000354 14730376041 0027040 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-byte-length-1ff4b11/.github/workflows/node-pretest.yml 0000664 0000000 0000000 00000000206 14730376041 0027412 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-byte-length-1ff4b11/.github/workflows/node-tens.yml 0000664 0000000 0000000 00000000547 14730376041 0026705 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
node:
name: 'node 10 - 20'
needs: [tests]
runs-on: ubuntu-latest
steps:
- run: true
inspect-js-typed-array-byte-length-1ff4b11/.github/workflows/node-twenties.yml 0000664 0000000 0000000 00000000536 14730376041 0027574 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
node:
name: 'node >= 20'
needs: [tests]
runs-on: ubuntu-latest
steps:
- run: true
inspect-js-typed-array-byte-length-1ff4b11/.github/workflows/rebase.yml 0000664 0000000 0000000 00000000257 14730376041 0026250 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-byte-length-1ff4b11/.github/workflows/require-allow-edits.yml 0000664 0000000 0000000 00000000303 14730376041 0030675 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-byte-length-1ff4b11/.gitignore 0000664 0000000 0000000 00000003404 14730376041 0022654 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
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
# Only apps should have lockfiles
npm-shrinkwrap.json
package-lock.json
yarn.lock
.npmignore
inspect-js-typed-array-byte-length-1ff4b11/.npmrc 0000664 0000000 0000000 00000000067 14730376041 0022006 0 ustar 00root root 0000000 0000000 package-lock=false
allow-same-version=true
message=v%s
inspect-js-typed-array-byte-length-1ff4b11/.nycrc 0000664 0000000 0000000 00000000330 14730376041 0021776 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-byte-length-1ff4b11/CHANGELOG.md 0000664 0000000 0000000 00000007017 14730376041 0022501 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.3](https://github.com/inspect-js/typed-array-byte-length/compare/v1.0.2...v1.0.3) - 2024-12-17
### Commits
- [types] oops, this is a type export, not a value export [`2fcf3e8`](https://github.com/inspect-js/typed-array-byte-length/commit/2fcf3e87f0312bca866dd24e805641f9c2c0798b)
## [v1.0.2](https://github.com/inspect-js/typed-array-byte-length/compare/v1.0.1...v1.0.2) - 2024-12-17
### Commits
- [types] improve types [`fcc9606`](https://github.com/inspect-js/typed-array-byte-length/commit/fcc9606bf4f27d1299aacbfa3011973ecf3f25bc)
- [types] use shared config [`ca29c46`](https://github.com/inspect-js/typed-array-byte-length/commit/ca29c46795620d624bcb6cbdbc32c1b0580ab0f8)
- [actions] split out node 10-20, and 20+ [`9a38c81`](https://github.com/inspect-js/typed-array-byte-length/commit/9a38c81be40d6e34b4a1cbe3d83dde8806a998cc)
- [Dev Deps] update `@arethetypeswrong/cli`, `@ljharb/eslint-config`, `@ljharb/tsconfig`, `@types/object-inspect`, `@types/tape`, `auto-changelog`, `object-inspect`, `tape` [`78cd1f2`](https://github.com/inspect-js/typed-array-byte-length/commit/78cd1f274612d46207951cf16a05615d2d14d13e)
- [Deps] update `call-bind`, `gopd`, `has-proto`, `is-typed-array` [`8c13b84`](https://github.com/inspect-js/typed-array-byte-length/commit/8c13b84060a47865c6f6f5fafdeccfdf8f304258)
- [Tests] replace `aud` with `npm audit` [`0d9aee3`](https://github.com/inspect-js/typed-array-byte-length/commit/0d9aee379568e90c7898163b43163c3287004e71)
- [Tests] use `@arethetypeswrong/cli` [`abf28fa`](https://github.com/inspect-js/typed-array-byte-length/commit/abf28fa1baff255683c3f38fe594271178199743)
- [Dev Deps] add missing peer dep [`dfd248d`](https://github.com/inspect-js/typed-array-byte-length/commit/dfd248d58080f8c74990d76202e72acd4f3e9fa0)
## [v1.0.1](https://github.com/inspect-js/typed-array-byte-length/compare/v1.0.0...v1.0.1) - 2024-02-20
### Commits
- add types [`3144671`](https://github.com/inspect-js/typed-array-byte-length/commit/3144671ca4035136c558a107ce61af255ae3e858)
- [actions] skip ls check on node < 10; remove redundant finisher [`0f83947`](https://github.com/inspect-js/typed-array-byte-length/commit/0f83947bfe641fd87253330a6a83e8b7571e5c6a)
- [Refactor] use `gopd` [`507b948`](https://github.com/inspect-js/typed-array-byte-length/commit/507b948f9e754ad5b0888a15558448ec879c04c4)
- [Dev Deps] update `aud`, `available-typed-arrays`, `npmignore`, `object-inspect`, `tape` [`aba282d`](https://github.com/inspect-js/typed-array-byte-length/commit/aba282da3a3e16f648ceb4bc4f174cf4942a94e9)
- [Deps] update `call-bind`, `has-proto`, `is-typed-array` [`acfe4a9`](https://github.com/inspect-js/typed-array-byte-length/commit/acfe4a9081f35cea3b450b07a4736e1ab037a708)
- [meta] add `sideEffects` flag [`063a8a7`](https://github.com/inspect-js/typed-array-byte-length/commit/063a8a7ec8c134a012903531beccfc4418f701d0)
## v1.0.0 - 2023-07-14
### Commits
- Initial implementation, tests, readme [`b8800c8`](https://github.com/inspect-js/typed-array-byte-length/commit/b8800c8f7f0fddd8744fd13dfa6239a504b4dc8d)
- Initial commit [`72723d8`](https://github.com/inspect-js/typed-array-byte-length/commit/72723d8f8fbff27d74b19f5e096d2eb2087d90dc)
- Only apps should have lockfiles [`a7dfc57`](https://github.com/inspect-js/typed-array-byte-length/commit/a7dfc57098655049b9c43cf1c3a39f24205821be)
inspect-js-typed-array-byte-length-1ff4b11/LICENSE 0000664 0000000 0000000 00000002053 14730376041 0021670 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-byte-length-1ff4b11/README.md 0000664 0000000 0000000 00000007127 14730376041 0022151 0 ustar 00root root 0000000 0000000 # typed-array-byte-offset [![Version Badge][npm-version-svg]][package-url]
[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]
[![npm badge][npm-badge-png]][package-url]
Robustly get the byte offset of a Typed Array, or `false` if it is not a Typed Array. Works cross-realm, in every engine, even if the `byteOffset` property is overridden.
## Example
```js
var typedArrayByteOffset = require('typed-array-byte-offset');
var assert = require('assert');
assert.equal(false, typedArrayByteOffset(undefined));
assert.equal(false, typedArrayByteOffset(null));
assert.equal(false, typedArrayByteOffset(false));
assert.equal(false, typedArrayByteOffset(true));
assert.equal(false, typedArrayByteOffset([]));
assert.equal(false, typedArrayByteOffset({}));
assert.equal(false, typedArrayByteOffset(/a/g));
assert.equal(false, typedArrayByteOffset(new RegExp('a', 'g')));
assert.equal(false, typedArrayByteOffset(new Date()));
assert.equal(false, typedArrayByteOffset(42));
assert.equal(false, typedArrayByteOffset(NaN));
assert.equal(false, typedArrayByteOffset(Infinity));
assert.equal(false, typedArrayByteOffset(new Number(42)));
assert.equal(false, typedArrayByteOffset('foo'));
assert.equal(false, typedArrayByteOffset(Object('foo')));
assert.equal(false, typedArrayByteOffset(function () {}));
assert.equal(false, typedArrayByteOffset(function* () {}));
assert.equal(false, typedArrayByteOffset(x => x * x));
assert.equal(false, typedArrayByteOffset([]));
const buffer = new ArrayBuffer(32);
assert.equal(8, typedArrayByteOffset(new Int8Array(buffer, 8)));
assert.equal(8, typedArrayByteOffset(new Uint8Array(buffer, 8)));
assert.equal(8, typedArrayByteOffset(new Uint8ClampedArray(buffer, 8)));
assert.equal(4, typedArrayByteOffset(new Int16Array(buffer, 4)));
assert.equal(4, typedArrayByteOffset(new Uint16Array(buffer, 4)));
assert.equal(8, typedArrayByteOffset(new Int32Array(buffer, 8)));
assert.equal(8, typedArrayByteOffset(new Uint32Array(buffer, 8)));
assert.equal(16, typedArrayByteOffset(new Float32Array(buffer, 16)));
assert.equal(16, typedArrayByteOffset(new Float64Array(buffer, 16)));
assert.equal(16, typedArrayByteOffset(new BigInt64Array(buffer, 16)));
assert.equal(16, typedArrayByteOffset(new BigUint64Array(buffer, 16)));
```
## Tests
Simply clone the repo, `npm install`, and run `npm test`
[package-url]: https://npmjs.org/package/typed-array-byte-offset
[npm-version-svg]: https://versionbadg.es/inspect-js/typed-array-byte-offset.svg
[deps-svg]: https://david-dm.org/inspect-js/typed-array-byte-offset.svg
[deps-url]: https://david-dm.org/inspect-js/typed-array-byte-offset
[dev-deps-svg]: https://david-dm.org/inspect-js/typed-array-byte-offset/dev-status.svg
[dev-deps-url]: https://david-dm.org/inspect-js/typed-array-byte-offset#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/typed-array-byte-offset.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/typed-array-byte-offset.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/typed-array-byte-offset.svg
[downloads-url]: https://npm-stat.com/charts.html?package=typed-array-byte-offset
[codecov-image]: https://codecov.io/gh/inspect-js/typed-array-byte-offset/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/inspect-js/typed-array-byte-offset/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/typed-array-byte-offset
[actions-url]: https://github.com/inspect-js/typed-array-byte-offset/actions
inspect-js-typed-array-byte-length-1ff4b11/index.d.ts 0000664 0000000 0000000 00000000433 14730376041 0022564 0 ustar 00root root 0000000 0000000 import type { TypedArray } from 'is-typed-array';
declare namespace typedArrayByteLength {
export type { TypedArray };
}
declare function typedArrayByteLength(value: TypedArray): number;
declare function typedArrayByteLength(value: unknown): false;
export = typedArrayByteLength; inspect-js-typed-array-byte-length-1ff4b11/index.js 0000664 0000000 0000000 00000005272 14730376041 0022336 0 ustar 00root root 0000000 0000000 'use strict';
var callBind = require('call-bind');
var forEach = require('for-each');
var gOPD = require('gopd');
var hasProto = require('has-proto')();
var isTypedArray = require('is-typed-array');
var typedArrays = require('available-typed-arrays')();
/** @typedef {import('possible-typed-array-names')[number]} TypedArrayName */
/** @typedef {(value: import('.').TypedArray) => number} Getter */
/** @type {Partial & { __proto__: null }>} */
var getters = {
__proto__: null
};
var oDP = Object.defineProperty;
if (gOPD) {
/** @type {Getter} */
var getByteLength = function (x) {
return x.byteLength;
};
forEach(typedArrays, function (typedArray) {
// In Safari 7, Typed Array constructors are typeof object
if (typeof global[typedArray] === 'function' || typeof global[typedArray] === 'object') {
var TA = global[typedArray];
/** @type {import('.').TypedArray} */
var Proto = TA.prototype;
// @ts-expect-error TS doesn't narrow properly inside callbacks
var descriptor = gOPD(Proto, 'byteLength');
if (!descriptor && hasProto) {
// @ts-expect-error hush, TS, every object has a dunder proto
var superProto = Proto.__proto__; // eslint-disable-line no-proto
// @ts-expect-error TS doesn't narrow properly inside callbacks
descriptor = gOPD(superProto, 'byteLength');
}
// Opera 12.16 has a magic byteLength data property on instances AND on Proto
if (descriptor && descriptor.get) {
getters[typedArray] = callBind(descriptor.get);
} else if (oDP) {
// this is likely an engine where instances have a magic byteLength data property
var arr = new global[typedArray](2);
// @ts-expect-error TS doesn't narrow properly inside callbacks
descriptor = gOPD(arr, 'byteLength');
if (descriptor && descriptor.configurable) {
oDP(arr, 'length', { value: 3 });
}
if (arr.length === 2) {
getters[typedArray] = getByteLength;
}
}
}
});
}
/** @type {Getter} */
var tryTypedArrays = function tryAllTypedArrays(value) {
/** @type {number} */ var foundByteLength;
forEach(
// eslint-disable-next-line no-extra-parens
/** @type {Record} */ (getters),
/** @type {(getter: Getter) => void} */ function (getter) {
if (typeof foundByteLength !== 'number') {
try {
var byteLength = getter(value);
if (typeof byteLength === 'number') {
foundByteLength = byteLength;
}
} catch (e) {}
}
}
);
// @ts-expect-error TS can't guarantee the callback is invoked sync
return foundByteLength;
};
/** @type {import('.')} */
module.exports = function typedArrayByteLength(value) {
if (!isTypedArray(value)) {
return false;
}
return tryTypedArrays(value);
};
inspect-js-typed-array-byte-length-1ff4b11/package.json 0000664 0000000 0000000 00000005602 14730376041 0023154 0 ustar 00root root 0000000 0000000 {
"name": "typed-array-byte-length",
"version": "1.0.3",
"description": "Robustly get the byte 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 --ext=js,mjs .",
"postlint": "tsc -p . && attw -P",
"tests-only": "nyc tape 'test/**/*.js'",
"test": "npm run tests-only",
"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-byte-length.git"
},
"keywords": [
"typed",
"array",
"byteLength",
"byte",
"length",
"robust",
"es",
"Int8Array",
"Uint8Array",
"Uint8ClampedArray",
"Int16Array",
"Uint16Array",
"Int32Array",
"Uint32Array",
"Float32Array",
"Float64Array",
"BigInt64Array",
"BigUint64Array"
],
"author": "Jordan Harband ",
"funding": {
"url": "https://github.com/sponsors/ljharb"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/inspect-js/typed-array-byte-length/issues"
},
"homepage": "https://github.com/inspect-js/typed-array-byte-length#readme",
"dependencies": {
"call-bind": "^1.0.8",
"for-each": "^0.3.3",
"gopd": "^1.2.0",
"has-proto": "^1.2.0",
"is-typed-array": "^1.1.14"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.17.1",
"@ljharb/eslint-config": "^21.1.1",
"@ljharb/tsconfig": "^0.2.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.7.0",
"auto-changelog": "^2.5.0",
"available-typed-arrays": "^1.0.7",
"encoding": "^0.1.13",
"eslint": "=8.8.0",
"evalmd": "^0.0.19",
"in-publish": "^2.0.1",
"is-callable": "^1.2.7",
"make-arrow-function": "^1.2.0",
"make-generator-function": "^2.0.0",
"npmignore": "^0.3.1",
"nyc": "^10.3.2",
"object-inspect": "^1.13.3",
"safe-publish-latest": "^2.0.0",
"tape": "^5.9.0",
"typescript": "next"
},
"engines": {
"node": ">= 0.4"
},
"auto-changelog": {
"output": "CHANGELOG.md",
"template": "keepachangelog",
"unreleased": false,
"commitLimit": false,
"backfillLimit": false,
"hideCredit": true
},
"testling": {
"files": "test/index.js"
},
"publishConfig": {
"ignore": [
".github/workflows"
]
}
}
inspect-js-typed-array-byte-length-1ff4b11/test/ 0000775 0000000 0000000 00000000000 14730376041 0021642 5 ustar 00root root 0000000 0000000 inspect-js-typed-array-byte-length-1ff4b11/test/index.js 0000664 0000000 0000000 00000006044 14730376041 0023313 0 ustar 00root root 0000000 0000000 'use strict';
var test = require('tape');
var typedArrayByteLength = 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 availableTypedArrays = require('available-typed-arrays')();
test('not arrays', function (t) {
t.test('non-number/string primitives', function (st) {
// @ts-expect-error
st.equal(false, typedArrayByteLength(), 'undefined is not typed array');
st.equal(false, typedArrayByteLength(null), 'null is not typed array');
st.equal(false, typedArrayByteLength(false), 'false is not typed array');
st.equal(false, typedArrayByteLength(true), 'true is not typed array');
st.end();
});
t.equal(false, typedArrayByteLength({}), 'object is not typed array');
t.equal(false, typedArrayByteLength(/a/g), 'regex literal is not typed array');
t.equal(false, typedArrayByteLength(new RegExp('a', 'g')), 'regex object is not typed array');
t.equal(false, typedArrayByteLength(new Date()), 'new Date() is not typed array');
t.test('numbers', function (st) {
st.equal(false, typedArrayByteLength(42), 'number is not typed array');
st.equal(false, typedArrayByteLength(Object(42)), 'number object is not typed array');
st.equal(false, typedArrayByteLength(NaN), 'NaN is not typed array');
st.equal(false, typedArrayByteLength(Infinity), 'Infinity is not typed array');
st.end();
});
t.test('strings', function (st) {
st.equal(false, typedArrayByteLength('foo'), 'string primitive is not typed array');
st.equal(false, typedArrayByteLength(Object('foo')), 'string object is not typed array');
st.end();
});
t.end();
});
test('Functions', function (t) {
t.equal(false, typedArrayByteLength(function () {}), 'function is not typed array');
t.end();
});
test('Generators', { skip: generators.length === 0 }, function (t) {
forEach(generators, function (genFn) {
t.equal(false, typedArrayByteLength(genFn), 'generator function ' + inspect(genFn) + ' is not typed array');
});
t.end();
});
test('Arrow functions', { skip: !arrowFn }, function (t) {
t.equal(false, typedArrayByteLength(arrowFn), 'arrow function is not typed array');
t.end();
});
test('Typed Arrays', { skip: availableTypedArrays.length === 0 }, function (t) {
var length = 64;
var byteLength = 32;
forEach(availableTypedArrays, function (typedArray) {
var buffer = new ArrayBuffer(length);
var TypedArray = global[typedArray];
if (isCallable(TypedArray)) {
// @ts-expect-error TS doesn't seem to know about the second TA arg
var arr = new TypedArray(buffer, byteLength);
t.equal(typedArrayByteLength(arr), byteLength, 'new ' + typedArray + '(new ArrayBuffer(' + length + '), ' + byteLength + ') is typed array of byte Length ' + byteLength);
} else {
t.comment('# SKIP ' + typedArray + ' is not supported');
}
});
var buffer = new ArrayBuffer(8);
var uint8 = new Uint8Array(buffer, 2);
t.equal(typedArrayByteLength(uint8), 6, 'byteLength is as expected');
t.end();
});
inspect-js-typed-array-byte-length-1ff4b11/tsconfig.json 0000664 0000000 0000000 00000000164 14730376041 0023373 0 ustar 00root root 0000000 0000000 {
"extends": "@ljharb/tsconfig",
"compilerOptions": {
"target": "ES2021",
},
"exclude": [
"coverage",
],
}