Socket
Socket
Sign inDemoInstall

js-type-descriptor

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    js-type-descriptor

Allows types to be described with JavaScript, and computes TypeScript types from those descriptions.


Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Install size
6.99 kB
Created
Weekly downloads
 

Readme

Source

Type Descriptor

Allows types to be described with JavaScript, and computes TypeScript types from those descriptions. Can be used to validate the structure of an object, or anything else where type information is required in the runtime.

Usage

npm i js-type-descriptor
const {isType} = require('js-type-descriptor');

if (isType(value, {kind: 'string'} as const)) {
  // value is a string
}

Types

  • "string"
  • "number"
  • "boolean"
  • "null"
  • "undefined"
  • "symbol"
  • "bigint"
  • "any"
  • "enum"
    • values Array of allowed values
  • "array"
    • subtype Type of the items in the array
  • "literal"
    • value The value of the literal
  • "intersection"
    • type1 Type
    • type2 Type
  • "union"
    • type1 Type
    • type2 Type
  • "instanceof"
    • value constructor to use in the instanceof comparison
  • "object"
    • properties A plain object with string keys and Type values

FAQs

Last updated on 07 Sep 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc