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

@typedefs/parser

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@typedefs/parser

The Parser For JSDoc Types.

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
44
decreased by-27.87%
Maintainers
1
Weekly downloads
 
Created
Source

@typedefs/parser

npm version

@typedefs/parser is The Parser For JSDoc Types.

yarn add @typedefs/parser

Table Of Contents

API

The package is available by importing its default function:

import parse from '@typedefs/parser'

parse(
  type: string,
): Type

Parses the type recursively. Obeys the JSDoc rules, but also supports Google Closure Compiler annotations.

_typedefsParser.FunctionType: The meta information about the function.

NameTypeDescription
args*!Array<!_typedefsParser.Type>The arguments of the function.
return*_typedefsParser.TypeThe return type of the function. When the value is set to null, it menas the function does not have a return. If the return was actuall null, it would be specified as return: { name: 'null' }.
this!_typedefsParser.TypeThe type of the this argument specified as function(this: Type).
new!_typedefsParser.TypeThe type of the new argument specified as function(new: Type).

_typedefsParser.Type: The representation of a type.

NameTypeDescription
nullablebooleanWhether the type is nullable. This is defined by writing ? before the type name to state nullability and ! otherwise. The parser does not infer nullability from types being primitive and Function/function.
namestringThe name of the type.
union!Array<!_typedefsParser.Type>If the type is defined as a union, e.g., (string|number), contains the united types. Must include parenthesis.
record!Object<string, _typedefsParser.Type>If the type is a record, contains its representation. If a property of the record does not have a type, it will be set to null.
application!Array<!_typedefsParser.Type>The application of the type, e.g., the inner type of Object&lt;Application&gt;.
function!_typedefsParser.FunctionTypeThe function info with args and return if the type is a function.
optionalbooleanIf the type is returned as an optional argument of a function (function(string=)), this will be set to true.
import parser from '@typedefs/parser'

logHeading('Applications')
log(parser('!Object<string, Promise<Array<!Type>>>'))

logHeading('Unions (parenthesis are required)')
log(parser('(string | number | !Promise<?(string | symbol)>)'))

logHeading('Records')
log(parser(`{
  a: string, b: ?number, c,
  d: !Promise<Array<{e: number}>>,
  f: { g: boolean }
}`))

logHeading('Functions')
log(parser(`function(this: Type, string, function()=): function(): null`))
Applications:
------------

{ nullable: false,
  name: 'Object',
  application: 
   [ { name: 'string' },
     { name: 'Promise',
       application: 
        [ { name: 'Array',
            application: [ { nullable: false, name: 'Type' } ] } ] } ] }

Unions (parenthesis are required):
---------------------------------

{ union: 
   [ { name: 'string' },
     { name: 'number' },
     { nullable: false,
       name: 'Promise',
       application: 
        [ { nullable: true,
            union: [ { name: 'string' }, { name: 'symbol' } ] } ] } ] }

Records:
-------

{ record: 
   { a: { name: 'string' },
     b: { nullable: true, name: 'number' },
     c: null,
     d: 
      { nullable: false,
        name: 'Promise',
        application: 
         [ { name: 'Array',
             application: [ { record: { e: { name: 'number' } } } ] } ] },
     f: { record: { g: { name: 'boolean' } } } } }

Functions:
---------

{ name: 'function',
  function: 
   { return: 
      { name: 'function',
        function: { return: { name: 'null' }, args: [] } },
     args: 
      [ { name: 'string' },
        { name: 'function',
          function: { return: null, args: [] },
          optional: true } ],
     this: { name: 'Type' } } }

Art Deco © Art Deco 2019 Tech Nation Visa Tech Nation Visa Sucks

Keywords

FAQs

Package last updated on 26 Apr 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