jsdoc-to-condition

0.3.0 • Public • Published

jsdoc-to-condition Build Status

Creates validation code from jsdoc comments

Example

/**
 * @param {[string, number?]} a
 * @param {Object.<string, number>} b
 * @param {string|number} c
 */

// generates the following:

((Array.isArray(a) && (typeof a[0] === 'string') && ((a[1] == null) || (typeof a[1] === 'number')))) &&
(((!!b && (typeof b === 'object') && !Array.isArray(b)) && Object.keys(b).every(function(k){return ((typeof k === 'string') && (typeof b[k] === 'number'));}))) &&
(((typeof c === 'string') || (typeof c === 'number')))

Usage

yarn add jsdoc-to-condition --dev
import {parseType} from 'jsdoc-to-condition';

console.log(parseType(`{string} varName`)[0].validation);
// ((typeof varName === 'string'))

Docs

For full reference on supported comment types see the tests folder.

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i jsdoc-to-condition

Weekly Downloads

1

Version

0.3.0

License

MIT

Last publish

Collaborators

  • jakwuh