- Notifications
You must be signed in to change notification settings - Fork5
Browserify transform for unassert: Encourages programming with assertions by providing tools to compile them away.
License
unassert-js/unassertify
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Browserify transform forunassert: Encouragesprogramming with assertions by providing tools to compile them away.
- unassert: Encourages programming with assertions by providing tools to compile them away.
- babel-plugin-unassert: Babel plugin for unassert
- webpack-unassert-loader: Webpack loader for unassert
- gulp-unassert: Gulp plugin for unassert
- unassert-cli: CLI for unassert
- rollup-plugin-unassert: RollupJS plugin for unassert
$ npm install --save-dev unassertify
$ $(npm bin)/browserify -t unassertify /path/to/src/target.js > /path/to/build/target.js
constsource=require('vinyl-source-stream');constbrowserify=require('browserify');constglob=require('glob'),gulp.task('production_build',function(){constfiles=glob.sync('./src/*.js');constb=browserify({entries:files});b.transform('unassertify');returnb.bundle().pipe(source('bundle.js')).pipe(gulp.dest('./dist'));});
For givenmath.js
below,
'use strict';constassert=require('node:assert');functionadd(a,b){console.assert(typeofa==='number');assert(!isNaN(a));assert.equal(typeofb,'number');assert.ok(!isNaN(b));returna+b;}
Runbrowserify
with-t unassertify
to transform file.
$ $(npm bin)/browserify -t unassertify /path/to/demo/math.js > /path/to/build/math.js
You will see assert calls disappear.
'use strict';functionadd(a,b){returna+b;}
Assertion expressions are removed when they match patterns below. In other words, unassertify removes assertion calls that are compatible with Node.js standardassert API (andconsole.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").strict
const assert = require("node:assert").strict
const { 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").strict
assert = require("node:assert").strict
unassert 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 allstrictAssert
,ok
,eq
calls.
We support Node under maintenance. In other words, we stop supporting old Node version whentheir 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 theMIT license.
About
Browserify transform for unassert: Encourages programming with assertions by providing tools to compile them away.
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.