Socket
Socket
Sign inDemoInstall

typedescriptor

Package Overview
Dependencies
Maintainers
6
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.


Version published
Weekly downloads
59K
increased by93.79%
Maintainers
6
Weekly downloads
 
Created
Source

typedescriptor

typedescriptor identifies and describes types.

Status

CategoryStatus
Versionnpm
DependenciesDavid
Dev dependenciesDavid
BuildCircleCI
LicenseGitHub

Installation

$ npm install typedescriptor

Quick Start

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

const Type = require('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
//    }

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 the build

To build this module use roboter.

$ npx roboter

Keywords

FAQs

Package last updated on 22 Aug 2019

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