Skip to content

Remove or strip arguments from function calls in and with JavaScript

License

Notifications You must be signed in to change notification settings

jtangelder/reduce-args

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Remove or strip arguments from function calls in and with JavaScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published