Automatically adds var assert = require('assert');
to your code, if not imported/required assert
module.
npm install babel-plugin-auto-import-assert
via Babel CLI
$ babel --plugins babel-plugin-auto-import-assert /path/to/src/target.js > /path/to/build/target.js
or shortly,
$ babel --plugins auto-import-assert /path/to/src/target.js > /path/to/build/target.js
via Babel API
var babel = require('babel-core');
var jsCode = fs.readFileSync('/path/to/src/target.js');
var transformed = babel.transform(jsCode, {
presets: [...],
plugins: ['babel-plugin-auto-import-assert']
});
console.log(transformed.code);
via .babelrc
{
"presets": [
...
],
"env": {
"development": {
"plugins": [
"babel-plugin-auto-import-assert"
],
}
}
}
$ babel /path/to/src/target.js > /path/to/build/target.js
For given math.js
below,
'use strict';
function add (a, b) {
assert(!isNaN(a));
assert.equal(typeof b, 'number');
assert.ok(!isNaN(b));
return a + b;
}
Run babel
with --plugins auto-import-assert
to transform code.
$ babel --plugins auto-import-assert /path/to/demo/math.js > /path/to/build/math.js
Add import assert from 'assert';
to your code.
'use strict';
var assert = require('assert');
function add(a, b) {
assert(!isNaN(a));
assert.equal(typeof b, 'number');
assert.ok(!isNaN(b));
return a + b;
}
npm test
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
MIT