1. babel-plugin-empower-assert
Babel plugin to convert assert to power-assert at compile time
babel-plugin-empower-assert
Package: babel-plugin-empower-assert
Created by: power-assert-js
Last modified: Mon, 13 Jun 2022 04:01:11 GMT
Version: 2.0.0
License: MIT
Downloads: 18,040
Repository: https://github.com/power-assert-js/babel-plugin-empower-assert

Install

npm install babel-plugin-empower-assert
yarn add babel-plugin-empower-assert

power-assert

Build Status
NPM version
License

babel-plugin-empower-assert is a Babel plugin to convert assert to power-assert at compile time.

INSTALL

$ npm install --save-dev babel-plugin-empower-assert power-assert

CAUTION

Babel7 is incompatible with Babel6.

For Babel6, you need to use the 1.x release of babel-plugin-empower-assert.

$ npm install --save-dev [email protected]

HOW TO USE

via .babelrc (Recommended)

 {
  "presets": [
    ...
  ],
  "env": {
    "development": {
      "plugins": [
        "babel-plugin-empower-assert"
      ],
    }
  }
}
$ babel /path/to/src/target.js > /path/to/build/target.js

via Babel CLI

$ babel --plugins babel-plugin-empower-assert /path/to/src/target.js > /path/to/build/target.js

or shortly,

$ babel --plugins empower-assert /path/to/src/target.js > /path/to/build/target.js

via Babel API

 var babel = require('@babel/core');
var jsCode = fs.readFileSync('/path/to/src/target.js');
var transformed = babel.transform(jsCode, {
    presets: [...],
    plugins: ['babel-plugin-empower-assert']
});
console.log(transformed.code);

EXAMPLE

For given math.js below,

 'use strict';

var assert = require('assert');

function add (a, b) {
    assert(!isNaN(a));
    assert.equal(typeof b, 'number');
    assert.ok(!isNaN(b));
    return a + b;
}

Run babel with --plugins empower-assert to transform code.

$ babel --plugins empower-assert /path/to/demo/math.js > /path/to/build/math.js

You will see assert is converted to power-assert.

 'use strict';

var assert = require('power-assert');

function add(a, b) {
    assert(!isNaN(a));
    assert.equal(typeof b, 'number');
    assert.ok(!isNaN(b));
    return a + b;
}

AUTHOR

LICENSE

Licensed under the MIT license.

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin