Home

Awesome

<div align="center">

Sapphire Logo

@sapphire/type

A type detection utility for JavaScript.

GitHub npm bundle size npm

</div>

Table of Contents

Description

Sometimes there is a need to know what a value's type of something is, this package exists to satisfy those needs by implementing a parser that can retrieve the type of the value recursively and process a string similar to TypeScript's types.

Features

Installation

yarn add @sapphire/type
# npm install @sapphire/type

Usage

Note: While this section uses require, the imports match 1:1 with ESM imports. For example const { Type } = require('@sapphire/type') equals import { Type } from '@sapphire/type'.

Note: When using ESM syntax you can also default-import Type class: import Type from '@sapphire/type'.

Note: The internal functions of getPromiseDetails and getProxyDetails are also exported. If you don't know what these are, then you need not be concerned about this.

Basic Usage

// Import the Type class
const { Type } = require('@sapphire/type');

// Define a Type with an array of two numbers
const type = new Type([1, 2]);

console.log(type.toString());
// Logs: Array<number>

Buy us some doughnuts

Sapphire Community is and always will be open source, even if we don't get donations. That being said, we know there are amazing people who may still want to donate just to show their appreciation. Thank you very much in advance!

We accept donations through Open Collective, Ko-fi, PayPal, Patreon and GitHub Sponsorships. You can use the buttons below to donate through your method of choice.

Donate WithAddress
Open CollectiveClick Here
Ko-fiClick Here
PatreonClick Here
PayPalClick Here

Contributors

Please make sure to read the Contributing Guide before making a pull request.

Thank you to all the people who already contributed to Sapphire!

<a href="https://github.com/sapphiredev/type/graphs/contributors"> <img src="https://contrib.rocks/image?repo=sapphiredev/type" /> </a>