0.3.0 • Published 7 years ago

jsdoc-to-condition v0.3.0

Weekly downloads
6
License
MIT
Repository
github
Last release
7 years ago

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

0.3.0

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago