Skip to content

Type

Is function that help you get better data type information rather than the default typeof, inspired from python type Built-in function

๐ŸŽฌ Usage

<script>
    import {type} from "@sveu/shared"
</script>

<h1>string? {type("svelte") === "string"  ? 'yea' : "nope"}</h1>

๐Ÿ‘ฉโ€๐Ÿ’ปAPI

๐Ÿ‘ป Arguments

Name Description Type Required
value The value to check any Yes

โ†ฉ๏ธ Returns

A string that represent the type of the value.

๐Ÿงช Playground

Source Code ๐Ÿ‘€

Source Code
/**
 * A function that get date type, that inspired from python type function.
 *
 * @remarks This function is used to get the type of the value.
 *
 * @param value - The value to get type.
 *
 * @see https://docs.python.org/3/library/functions.html#type
 *
 * @returns The type of the value.
 */
export function type<T>(value: T): string {
    return Object.prototype.toString.call(value).slice(8, -1).toLowerCase()
}

Last update: 2023-02-09