npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

unassertify

v3.0.1

Published

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

Downloads

57,186

Readme

unassertify

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

unassert

Build Status NPM version Code Style License

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

  • 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

Auto Variable Tracking

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