npm

Need private packages and team management tools?Check out npm Orgs. »

reduce-args

0.0.1 • Public • Published

reduce-args

Remove function calls or strip arguments in javascript code. Useful for removing debug messages in a production build. The next step after using this small tool, would be to compress the code with something like UglifyJS.

Uses Recast for parsing the code.

Example

invariant(isArray(obj), "obj should be an array!");

...becomes...

invariant(isArray(obj));

Usage

var reduceArgs = require('reduce-args');
 
var min = reduceArgs(testCode, [
    // removes all console.*() calls
    { test: /^console./, removeCall: true },
    
    // keeps only the argument at index 0 at calls to invariant()
    { test: /^invariant$/, keepArgs: [0] },
    
    // drops all arguments to invariant()
    { test: /^invariant$/, keepArgs: [] },
    
    // drops the argument at index 1, and keeps the rest
    { test: /^invariant$/, stripArgs: [1] }
]);
 
console.log(min.code);

See the tests for more details.

Install

npm install reduce-args

Keywords

none

install

npm i reduce-args

Downloadsweekly downloads

2

version

0.0.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability