IonicaBizau/typpy
Deno port oftyppy
A better typeof for JavaScript.
π Example
// Dependencies
import {Typpy} from "../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
β Get Help
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. π
π Documentation
Typpy(input, target)
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
Params
- 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
).
Return
- 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).
Typpy.is(input, target)
Checks if the input value has a specified type.
Params
- 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
).
Return
- Boolean
true
, if the input has the same type with the target orfalse
otherwise.
Typpy.get(input, str)
Gets the type of the input value. This is used internally.
Params
- Anything
input
: The input value. - Boolean
str
: A flag to indicate if the return value should be a string or not.
Return
- Constructor|String The input value constructor (if any) or the stringified type (always lowercase).
π How to contribute
Have an idea? Found a bug? See how to contribute.
π« Where is this library used?
If you are using this library in one of your projects, add it in this list. β¨
π License
MIT Β© IonicΔ BizΔu MIT Β© Hunter Paulson