New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

babel-plugin-jsdoc-to-condition

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-jsdoc-to-condition

A babel plugin which creates validation code from jsdoc comments

latest
Source
npmnpm
Version
0.3.4
Version published
Maintainers
1
Created
Source

jsdoc-to-condition Build Status

Babel plugin which сreates validation code from jsdoc comments

Example

Before:

/**
 * @param {number} param - this is a param.
 * @param {string} b - this is a param.
 * @param {string[]} [c] - this is a param.
 */
function lonelyFunction(param, b, c) {
}

After:

/**
 * @param {number} param - this is a param.
 * @param {string} b - this is a param.
 * @param {string[]} [c] - this is a param.
 */
function lonelyFunction(param, b, c) {
  if (!(typeof param === 'number')) {
    console._warn('actual.js:6:0: Expected `param` to have type number, got: ' + typeof param);
  }

  if (!(typeof b === 'string')) {
    console._warn('actual.js:6:0: Expected `b` to have type string, got: ' + typeof b);
  }

  if (!(c === undefined || Array.isArray(c) && c.every(function (n) {
    return typeof n === 'string';
  }))) {
    console._warn('actual.js:6:0: Expected `c` to have type Array.<string>=, got: ' + typeof c);
  }
}

Usage

yarn add babel-plugin-jsdoc-to-condition --dev
// .babelrc
{
    "plugins": [
        ["jsdoc-to-condition", {
            "ignore": ["node_modules/"],
            "logger": "debugger; console.info"
        }]
    ]
}

Keywords

babel

FAQs

Package last updated on 11 Sep 2017

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