A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://npmjs.org/package/unassertify below:

unassertify - npm

unassertify

Browserify transform for unassert: Encourages programming with assertions by providing tools to compile them away.

RELATED MODULES INSTALL
$ npm install --save-dev unassertify
HOW TO USE via CLI
$ $(npm bin)/browserify -t unassertify /path/to/src/target.js > /path/to/build/target.js
via API
const 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'));
});
EXAMPLE

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.js

You will see assert calls disappear.

'use strict';
function add(a, b) {
    return a + b;
}
SUPPORTED PATTERNS

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).

unassertify also removes assert variable declarations,

and assignments.

Auto Variable Tracking

unassert automatically removes assertion calls based on their imported variable names.

So if import declaration is as follows,

unassert removes all strictAssert, ok, eq calls.

AUTHOR CONTRIBUTORS OUR SUPPORT POLICY

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.

LICENSE

Licensed under the MIT license.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4