@wessberg/typedetector
v1.0.6
Published
A class that holds a set of predicate methods that detects the native type of the input.
Downloads
44
Maintainers
Readme
TypeDetector
A class that holds a few simple predicate functions for detecting the native type of input.
Installation
Simply do: npm install @wessberg/typedetector
.
Usage
const typeDetector = new TypeDetector();
if (typeDetector.isFunction(something)) {
// something is typed as a function in here.
something(arg);
}
const set1 = new Set([1, 2, 3]);
const set2 = new Set([3, 2, 1]);
const set3 = set1;
typeDetector.isEqual(set1, set2); // returns true, their contents are the same.
typeDetector.isEqual(set1, set3); // returns true, by referential equality.
The library only covers a few of the built-in types since instanceof
checks covers the rest.
But, for things such as strings
, numbers
and booleans
, the predicates will be truthy if
their object wrapper types is also used, e.g.:
typeDetector.isNumber(new Number(2)) // returns true
Changelog:
v1.0.6:
- Made type updates to make TypeDetector compatible with Typescript ^2.4.1.
v1.0.5:
- Added typedetection for class instances and class constructors. Added new 'getTypeOf' values. Classes no longer has the types 'function' for constructors and 'object' for instances, but rather 'constructor' for constructors and 'class' for class instances.
v1.0.4:
- Fixed a bug where
getTypeOf
would not catchnull
orundefined
values.
v1.0.3:
- Added a
getTypeOf
method that returns a more appropriate stringified name of the type of the given data.
v1.0.1:
- A few updates in the README.
v1.0.0:
- First release. Contains a few methods for things that traditional
instanceof
checks doesn't cover.