Deno port of IonicaBizau/typpy
A better typeof for JavaScript.
// Dependencies
import {Typpy} from "https://deno.land/x/typpy/lib/typpy.ts"
console.log(Typpy(0));
// => "number"
console.log(Typpy("", String));
// => true
console.log(Typpy.is(null, "null"));
// => true
console.log(Typpy.get([]));
// => Array
console.log(Typpy({}, true));
// => false
console.log(Typpy({}, Object));
// => true
There are few ways to get help:
- Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
- For bug reports and feature requests, open issues. 🐛
Gets the type of the input value or compares it with a provided type.
Usage:
Typpy({}) // => "object"
Typpy(42, Number); // => true
Typpy.get([], "array"); // => true
- Anything
input
: The input value. - Constructor|String
target
: The target type. It could be a string (e.g."array"
) or a constructor (e.g.Array
).
- String|Boolean It returns
true
if the input has the provided typetarget
(if was provided),false
if the input type does not have the provided typetarget
or the stringified type of the input (always lowercase).
Checks if the input value has a specified type.
- Anything
input
: The input value. - Constructor|String
target
: The target type. It could be a string (e.g."array"
) or a constructor (e.g.Array
).
- Boolean
true
, if the input has the same type with the target orfalse
otherwise.
Gets the type of the input value. This is used internally.
- Anything
input
: The input value. - Boolean
str
: A flag to indicate if the return value should be a string or not.
- Constructor|String The input value constructor (if any) or the stringified type (always lowercase).
Have an idea? Found a bug? See how to contribute.
If you are using this library in one of your projects, add it in this list. ✨