Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
The dtype npm package is used to determine the data type of a JavaScript value. It is a simple utility that can be useful in various scenarios where type checking is necessary.
Determine the data type of a value
This feature allows you to determine the data type of various JavaScript values such as numbers, strings, booleans, arrays, and objects.
const dtype = require('dtype');
console.log(dtype(42)); // 'int32'
console.log(dtype(3.14)); // 'float64'
console.log(dtype('hello')); // 'string'
console.log(dtype(true)); // 'bool'
console.log(dtype([1, 2, 3])); // 'array'
console.log(dtype({ key: 'value' })); // 'object'
The typeof package provides a more detailed type checking than the native JavaScript typeof operator. It can distinguish between different types of objects and primitives. Compared to dtype, typeof offers a more comprehensive type checking but may not be as specialized in certain numeric types.
The type-detect package is a robust library for type detection in JavaScript. It can identify a wide range of types including custom types. Compared to dtype, type-detect is more versatile and can handle more complex type detection scenarios.
The is package provides a set of type-checking functions for various JavaScript types. It is more modular and allows for checking specific types with dedicated functions. Compared to dtype, is offers a more granular approach to type checking.
Return a data type from a string representing the data type.
Mostly useful for using with ndarray
where you would like instantiate a typed array of the same array.dtype
.
See ndarray-dtype if you need to support Buffer and other ndarray types.
var dtype = require('dtype')
var ndarray = require('ndarray')
var arr = ndarray(new Int8Array(32))
// some time later
var newarr = ndarray(new (dtype(arr.dtype)))
dtype(string)
will return the following data types based on the strings given:
Data type | String |
---|---|
Int8Array | "int8" |
Int16Array | "int16" |
Int32Array | "int32" |
Uint8Array | "uint8" |
Uint16Array | "uint16" |
Uint32Array | "uint32" |
Float32Array | "float32" |
Float64Array | "float64" |
Array | "array" |
Uint8ClampedArray | "uint8_clamped" |
Returns undefined
if the type isn't recognized.
With npm do:
npm install dtype
Use browserify to require('dtype')
.
Copyright (c) 2015 Kyle Robinson Young
Licensed under the MIT license.
FAQs
Return a data type from a string representing the type
The npm package dtype receives a total of 191,675 weekly downloads. As such, dtype popularity was classified as popular.
We found that dtype demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.