Package Exports
- unassert
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (unassert) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
unassert
Encourage Design by Contract (DbC) by writing assertions in production code, and compiling them away from release.
RELATED MODULES
- unassertify: Browserify transform to remove assertions on build
- babel-plugin-unassert: Babel plugin to remove assertions on build
- webpack-unassert-loader: A webpack loader to remove assertions on production build
INSTALL
$ npm install --save-dev unassertEXAMPLE
For given math.js below,
'use strict';
var assert = require('assert');
function add (a, b) {
console.assert(typeof a === 'number');
assert(!isNaN(a));
assert.equal(typeof b, 'number');
assert.ok(!isNaN(b));
return a + b;
}Apply unassert then generate modified code to console.
var esprima = require('esprima');
var escodegen = require('escodegen');
var unassert = require('unassert');
var fs = require('fs');
var path = require('path');
var filepath = path.join(__dirname, 'math.js');
var ast = esprima.parse(fs.readFileSync(filepath));
var modifiedAst = unassert(ast);
console.log(escodegen.generate(modifiedAst));Then you will see assert calls disappear.
'use strict';
function add(a, b) {
return a + b;
}Note: unassert supports removal of power-assert declarations (var assert = require('power-assert');) too.
SUPPORTED PATTERNS
Assertion expressions are removed when they match patterns below. In other words, unassert removes assertion calls that are compatible with Node.js standard assert API (and console.assert).
assert(value, [message])assert.ok(value, [message])assert.equal(actual, expected, [message])assert.notEqual(actual, expected, [message])assert.strictEqual(actual, expected, [message])assert.notStrictEqual(actual, expected, [message])assert.deepEqual(actual, expected, [message])assert.notDeepEqual(actual, expected, [message])assert.deepStrictEqual(actual, expected, [message])assert.notDeepStrictEqual(actual, expected, [message])assert.fail(actual, expected, message, operator)assert.throws(block, [error], [message])assert.doesNotThrow(block, [message])assert.ifError(value)console.assert(value, [message])
unassert also removes assert variable declarations,
var assert = require("assert")var assert = require("power-assert")import assert from "assert"import assert from "power-assert"
and assignments.
assert = require("assert")assert = require("power-assert")
AUTHOR
LICENSE
Licensed under the MIT license.