Socket
Socket
Sign inDemoInstall

which-typed-array

Package Overview
Dependencies
64
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.1 - 2020-01-24

Commits

  • [Tests] use shared travis-ci configs 0a627d9
  • [meta] add auto-changelog 2a14c58
  • [meta] remove unused Makefile and associated utilities 75f7f22
  • [Tests] up to node v12.10, v11.15, v10.16, v8.16, v6.17 4162327
  • [Refactor] use es-abstract’s callBound, available-typed-arrays, has-symbols 9b04a2a
  • [readme] fix repo URLs, remove testling 03ed52f
  • [Dev Deps] update eslint, @ljharb/eslint-config, replace, semver, tape bfbcf3e
  • [actions] add automatic rebasing / merge commit blocking cc88ac5
  • [meta] create FUNDING.yml acbc723
  • [Dev Deps] update eslint, @ljharb/eslint-config, is-callable, tape f1ab63e
  • [Dev Deps] update eslint, @ljharb/eslint-config; add safe-publish-latest ac9f50b
  • [Tests] use npx aud instead of nsp or npm audit with hoops aaaa15d
  • [Dev Deps] update eslint, @ljharb/eslint-config, tape 602fc9a
  • [Deps] update available-typed-arrays, is-typed-array b2d69b6
  • [meta] add funding field 156f613

Readme

Source

which-typed-array Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

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()));
assert.equal('BigInt64Array', whichTypedArray(new BigInt64Array()));
assert.equal('BigUint64Array', whichTypedArray(new BigUint64Array()));

Tests

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

Keywords

FAQs

Last updated on 24 Jan 2020

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