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
Authors: Mohamed-Kaizen