babel-plugin-jsdoc-to-condition
v0.3.4
Published
A babel plugin which creates validation code from jsdoc comments
Downloads
4
Maintainers
Readme
jsdoc-to-condition
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"
}]
]
}