What is dtype?
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.
What are dtype's main functionalities?
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'
Other packages similar to dtype
typeof
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.
type-detect
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.
is
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.
dtype
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
.
example
var dtype = require('dtype')
var ndarray = require('ndarray')
var arr = ndarray(new Int8Array(32))
var newarr = ndarray(new (dtype(arr.dtype)))
API
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" |
ArrayBuffer | "generic" |
ArrayBuffer | "data" |
ArrayBuffer | "dataview" |
Buffer | "buffer" |
If Buffer
is not present then "buffer"
will return ArrayBuffer
.
install
With npm do:
npm install dtype
Use browserify to require('dtype')
.
release history
license
Copyright (c) 2013 Kyle Robinson Young
Licensed under the MIT license.