package
Browserify transform for unassert: Encourages programming with assertions by providing tools to compile them away
npm install unassertifyGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Browserify transform for unassert: Encourages programming with assertions by providing tools to compile them away.
$ npm install --save-dev unassertify$ $(npm bin)/browserify -t unassertify /path/to/src/target.js > /path/to/build/target.jsconst source = require('vinyl-source-stream');
const browserify = require('browserify');
const glob = require('glob'),
gulp.task('production_build', function() {
const files = glob.sync('./src/*.js');
const b = browserify({entries: files});
b.transform('unassertify');
return b.bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest('./dist'
For given math.js below,
'use strict';
const assert = require('node: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;
}Run browserify with -t unassertify to transform file.
$ $(npm bin)/browserify -t unassertify /path/to/demo/math.js > /path/to/build/math.jsYou will see assert calls disappear.
'use strict';
function add(a, b) {
return a + b;
}Assertion expressions are removed when they match patterns below. In other words, unassertify 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.match(string, regexp[, message])assert.doesNotMatch(string, regexp[, message])assert.throws(block, [error], [message])assert.doesNotThrow(block, [message])await assert.rejects(asyncFn, [error], [message])await assert.doesNotReject(asyncFn, [error], [message])assert.fail([message])assert.fail(actual, expected, message, operator)assert.ifError(value)console.assert(value, [message])unassertify also removes assert variable declarations,
import assert from "assert"import assert from "assert/strict"import assert from "node:assert"import assert from "node:assert/strict"import * as assert from "assert"import * as assert from "node:assert"import * as assert from "assert/strict"import * as assert from "node:assert/strict"import { strict as assert } from "assert"import { strict as assert } from "node:assert"import { default as assert } from "assert"import { default as assert } from "node:assert"const assert = require("assert")const assert = require("node:assert")const assert = require("assert/strict")const assert = require("node:assert/strict")const assert = require("assert").strictconst assert = require("node:assert").strictconst { strict: assert } = require("assert")const { strict: assert } = require("node:assert")and assignments.
assert = require("assert")assert = require("node:assert")assert = require("assert/strict")assert = require("node:assert/strict")assert = require("assert").strictassert = require("node:assert").strictunassert automatically removes assertion calls based on their imported variable names.
So if import declaration is as follows,
import strictAssert, { ok, equal as eq } from 'node:assert/strict';unassert removes all strictAssert, ok, eq calls.
We support Node under maintenance. In other words, we stop supporting old Node version when their maintenance ends.
This means that any other environment is not supported.
NOTE: If unassertify works in any of the unsupported environments, it is purely coincidental and has no bearing on future compatibility. Use at your own risk.
Licensed under the MIT license.
Estimated unpacked size across 11 packages.
1.3 MB
Includes dependencies.
6 direct · 1 outdated
^8.0.0
8.19.0
^2.3.7
2.3.8
^2.0.0
2.0.2
^2.0.0
2.1.0
^1.1.1
2.0.0
^0.3.1
0.3.1