Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typedescriptor

Package Overview
Dependencies
Maintainers
5
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typedescriptor

typedescriptor identifies and describes types.

  • 3.0.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
5
Created
Source

typedescriptor

typedescriptor identifies and describes types.

Status

CategoryStatus
Versionnpm
DependenciesDavid
Dev dependenciesDavid
BuildGitHub Actions
LicenseGitHub

Installation

$ npm install typedescriptor

Quick Start

First you need to add a reference to typedescriptor to your application:

const { Type } = require('typedescriptor');

If you use TypeScript, use the following code instead:

import { Type } from 'typedescriptor';

Then, to identify a value's type, call the static of function and hand over the value:

const type = Type.of('the native web');

console.log(type);
// => 'string'

The types array, boolean, function, null, number, object, string, symbol and undefined are supported.

Getting detailed type descriptions

To get a detailed type descriptor object, call the static from function and hand over the value:

const typeDescriptor = Type.from('the native web');

console.log(typeDescriptor);
// => {
//      name: 'string',
//
//      isValueType: true,
//      isReferenceType: false,
//
//      isArray: false,
//      isBoolean: false,
//      isFunction: false,
//      isNull: false,
//      isNumber: false,
//      isObject: false,
//      isString: true,
//      isSymbol: false,
//      isUndefined: false
//    }

Using TypeScript type guards

Since using the descriptors above doesn't tell TypeScript anything, there are type guards for every type check:

import Type from 'typedescriptor';

const someValue = getSomeValue() as any;

if (Type.isArray(someValue)) {
  // TypeScript now realizes that `someValue` is of type []
}

if (Type.isValueType(someValue)) {
  // TypeScript now realizes that `someValue` is of type string | number | boolean | null | undefined
}

Running quality assurance

To run quality assurance for this module use roboter:

$ npx roboter

Keywords

FAQs

Package last updated on 25 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc