jsdoc-to-condition
v0.3.0
Published
Creates validation code from jsdoc comments
Downloads
3
Readme
jsdoc-to-condition
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