Socket
Socket
Sign inDemoInstall

which-typed-array

Package Overview
Dependencies
2
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    which-typed-array

Which kind of Typed Array is this JavaScript value? Works cross-realm, without `instanceof`, and despite Symbol.toStringTag.


Version published
Weekly downloads
36M
increased by1.89%
Maintainers
1
Created
Weekly downloads
 

Package description

What is which-typed-array?

The `which-typed-array` npm package is designed to identify the type of a given typed array instance. It supports all built-in JavaScript typed array types, including `Int8Array`, `Uint8Array`, `Uint8ClampedArray`, `Int16Array`, `Uint16Array`, `Int32Array`, `Uint32Array`, `Float32Array`, `Float64Array`, and `BigInt64Array`, `BigUint64Array`. This package is useful for applications that need to process or manipulate typed arrays and must determine their specific types to apply the correct operations.

What are which-typed-array's main functionalities?

Identifying Typed Array Type

This feature allows the identification of the type of a typed array. The function `whichTypedArray` is called with a typed array as its argument, and it returns a string representing the type of the typed array.

"use strict";\nconst whichTypedArray = require('which-typed-array');\nconsole.log(whichTypedArray(new Uint8Array())); // 'Uint8Array'\nconsole.log(whichTypedArray(new Float32Array())); // 'Float32Array'"

Other packages similar to which-typed-array

Changelog

Source

v1.1.0 - 2019-02-16

Commits

  • [Tests] remove jscs 381c9b4
  • [Tests] up to node v8.2, v7.10, v6.11, v5.8; improve matrix; newer npm breaks on older node 7015c19
  • [Tests] up to node v10.0, v9.11, v8.11, v6.14, v4.9; use nvm install-latest-npm ad67885
  • [Tests] up to node v11.6, v10.15, v8.15, v6.16 dd94bfb
  • [Refactor] use an array instead of an object for storing Typed Array names de98bc1
  • [meta] ignore test.html 06cfb1b
  • [Tests] up to node v7.0, v6.9, v4.6; improve test matrix df76eaa
  • [New] add BigInt64Array and BigUint64Array d6bca3a
  • [Dev Deps] update jscs, nsp, eslint f23b45b
  • [Dev Deps] update @ljharb/eslint-config, eslint, semver, tape ddb4484
  • [Dev Deps] update eslint, @ljharb/eslint-config, covert, is-callable, replace, semver, tape 4524e59
  • [Dev Deps] update tape, jscs, nsp, eslint, @ljharb/eslint-config, semver 1ec7056
  • [Dev Deps] update jscs, nsp, eslint, @ljharb/eslint-config 799487d
  • [Dev Deps] update tape, jscs, nsp, eslint, @ljharb/eslint-config, semver 8092598
  • [Tests] up to node v11.10 a5aabb1
  • [Dev Deps] update @ljharb/eslint-config, eslint, nsp, semver, tape 277be33
  • [Tests] use npm audit instead of nsp ee97dc7
  • [Dev Deps] update tape, eslint, @ljharb/eslint-config 262ffb0
  • [Dev Deps] update jscs, eslint, @ljharb/eslint-config d6bbcfc
  • [Tests] up to node v6.2 2ff89eb
  • Only apps should have lockfiles e2bc271
  • [Dev Deps] update nsp, eslint, @ljharb/eslint-config b79e93b
  • [Dev Deps] update nsp, eslint, @ljharb/eslint-config 016dbff
  • [Dev Deps] update eslint, tape 6ce4bbc
  • [Tests] on node v10.1 f0683a0
  • [Tests] up to node v7.2 2f29cef
  • [Dev Deps] update replace 73b5ba6
  • [Deps] update function-bind c8a18c2
  • [Tests] on node v5.12 812102b
  • [Tests] on node v5.10 271584f

Readme

Source

which-typed-array Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

browser support

Which kind of Typed Array is this JavaScript value? Works cross-realm, without instanceof, and despite Symbol.toStringTag.

Example

var whichTypedArray = require('which-typed-array');
var assert = require('assert');

assert.equal(false, whichTypedArray(undefined));
assert.equal(false, whichTypedArray(null));
assert.equal(false, whichTypedArray(false));
assert.equal(false, whichTypedArray(true));
assert.equal(false, whichTypedArray([]));
assert.equal(false, whichTypedArray({}));
assert.equal(false, whichTypedArray(/a/g));
assert.equal(false, whichTypedArray(new RegExp('a', 'g')));
assert.equal(false, whichTypedArray(new Date()));
assert.equal(false, whichTypedArray(42));
assert.equal(false, whichTypedArray(NaN));
assert.equal(false, whichTypedArray(Infinity));
assert.equal(false, whichTypedArray(new Number(42)));
assert.equal(false, whichTypedArray('foo'));
assert.equal(false, whichTypedArray(Object('foo')));
assert.equal(false, whichTypedArray(function () {}));
assert.equal(false, whichTypedArray(function* () {}));
assert.equal(false, whichTypedArray(x => x * x));
assert.equal(false, whichTypedArray([]));

assert.equal('Int8Array', whichTypedArray(new Int8Array()));
assert.equal('Uint8Array', whichTypedArray(new Uint8Array()));
assert.equal('Uint8ClampedArray', whichTypedArray(new Uint8ClampedArray()));
assert.equal('Int16Array', whichTypedArray(new Int16Array()));
assert.equal('Uint16Array', whichTypedArray(new Uint16Array()));
assert.equal('Int32Array', whichTypedArray(new Int32Array()));
assert.equal('Uint32Array', whichTypedArray(new Uint32Array()));
assert.equal('Float32Array', whichTypedArray(new Float32Array()));
assert.equal('Float64Array', whichTypedArray(new Float64Array()));

Tests

Simply clone the repo, npm install, and run npm test

Keywords

FAQs

Last updated on 16 Feb 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc