unassertify

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

  • 所有者: unassert-js/unassertify
  • 平台:
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

unassertify

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

unassert

Build Status
NPM version
Dependency Status
License

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

var source = require('vinyl-source-stream');
var browserify = require('browserify');
var glob = require('glob'),

gulp.task('production_build', function() {
    var files = glob.sync('./src/*.js');
    var 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';

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;
}

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.fail(actual, expected, message, operator)
  • assert.throws(block, [error], [message])
  • assert.doesNotThrow(block, [message])
  • assert.ifError(value)
  • console.assert(value, [message])

unassertify also removes assert variable declarations,

  • var assert = require("assert")
  • var assert = require("power-assert")

and assignments.

  • assert = require("assert")
  • assert = require("power-assert")

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.

主要指標

概覽
名稱與所有者unassert-js/unassertify
主編程語言JavaScript
編程語言JavaScript (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2015-05-26 14:47:57
推送於2023-01-09 08:15:15
最后一次提交2022-08-07 11:09:44
發布數13
最新版本名稱v3.0.1 (發布於 2022-08-07 11:09:44)
第一版名稱v1.0.0 (發布於 2015-05-27 00:07:08)
用户参与
星數78
關注者數3
派生數5
提交數121
已啟用問題?
問題數2
打開的問題數1
拉請求數6
打開的拉請求數1
關閉的拉請求數0
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?