神刀安全网

babel-plugin-jsdoc-to-assert: Runtime type checking for JSDoc

babel-plugin-jsdoc-to-assert babel-plugin-jsdoc-to-assert: Runtime type checking for JSDoc

Babel plugin forjsdoc-to-assert.

This plugin JSDoc to assertion method for runtime testing.

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

to

/**  * @param {number} param - this is a param.  * @param {string} b - this is a param.  * @param {string[]} [c] - this is a param.  */ function myFunc(param, b, c) {   console.assert(typeof param === 'number');   console.assert(typeof b === 'string'); }

Installation

npm install babel-plugin-jsdoc-to-assert 

Usage

Via .babelrc

{   "plugins": [     "jsdoc-to-assert"   ] }

In development only:

{   "presets": [     "es2015"   ],   "env": {     "development": {       "plugins": [         "jsdoc-to-assert"       ]     }   } }

If build files with NODE_ENV=production , don’t convert JSDoc to assert.

"build": "NODE_ENV=production babel src --out-dir lib --source-maps", 

Tests

npm test 

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request 😀

License

MIT

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » babel-plugin-jsdoc-to-assert: Runtime type checking for JSDoc

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
分享按钮