/typpy-deno

✌️A better typeof for JavaScript.

Primary LanguageTypeScriptMIT LicenseMIT

Deno port of IonicaBizau/typpy

typpy

typpy

A better typeof for JavaScript.

📋 Example

// 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

❓ Get Help

There are few ways to get help:

  1. Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
  2. 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 type target (if was provided), false if the input type does not have the provided type target 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 or false 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