type-detect
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Type-detect is a highly useful npm package that provides improved type detection features for both Node.js and browsers. It returns a string representation of an object's type, delivering better specificity than native 'typeof' statements. Not only does it overcome the common problem of 'typeof' only specifying primitive values, with all other types falling under the vague "object" category, but it also addresses the speed and consistency issues associated with using Object.prototype.toString()
. Through a custom code, type-detect improves speed checks upto 20-30x for some values and ensures consistency across JS and DOM objects.
Incorporating type-detect into your project is simple and convenient whether you are working in Node.js or within a browser. If you are operating on Node.js, type-detect can be downloaded from npm. Simply type $ npm install type-detect
in your command prompt. For browser usage, the process is just as straightforward. Install via npm and utilize the type-detect.js
file found within the download. An example usage:
<script src="./node_modules/type-detect/type-detect.js"></script>
After installation, type-detect can be incorporated into the code. Here are a few usage examples:
var type = require('type-detect');
assert(type([]) === 'Array');
assert(type(/a-z/gi) === 'RegExp');
assert(type(function () {}) === 'function');
assert(type(undefined) === 'undefined');
assert(type(null) === 'null');
assert(type({}) === 'Object');
assert(type(new Map()) === 'Map');
assert(type(new WeakMap()) === 'WeakMap');
assert(type(Symbol()) === 'symbol');
The documentation of type-detect is accessible on the official Github page of the package: chaijs/type-detect. The documentation includes all the necessary information about the usage and features of the package, to ensure smooth integration into projects.