Skip to content

sapphiredev/type

Folders and files

NameName
Last commit message
Last commit date

Latest commit

e9565a5 · Mar 30, 2025
Feb 15, 2025
Aug 17, 2024
Mar 30, 2025
Dec 18, 2022
Jan 19, 2024
Jul 11, 2024
Jan 5, 2025
Oct 27, 2024
Apr 28, 2021
Apr 28, 2021
Apr 28, 2021
Apr 28, 2021
May 7, 2022
Nov 12, 2022
Nov 12, 2022
Jul 23, 2023
Aug 30, 2022
Mar 30, 2025
Dec 14, 2024
Apr 28, 2021
Aug 17, 2024
Nov 12, 2022
Jun 16, 2024
Mar 30, 2025
Aug 17, 2024
Dec 4, 2023
Dec 4, 2023
Dec 5, 2023
Nov 2, 2024
Jul 11, 2024
Mar 30, 2025

Repository files navigation

Sapphire Logo

@sapphire/type

A type detection utility for JavaScript.

GitHub npm bundle size npm


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

  • Written in TypeScript
  • Bundled with Rollup so it can be used in NodeJS and browsers
  • Offers CommonJS, ESM and UMD bundles
  • Fully tested

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 With Address
Open Collective Click Here
Ko-fi Click Here
Patreon Click Here
PayPal Click 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!