Strip
console
,alert
, anddebugger
statements from JavaScript code with whitelist
Useful for making sure you didn't leave any logging in production code.
Also available as gulp/grunt/broccoli plugins.
$ npm install --save berstend/strip-debug-arbitrary
var stripDebug = require('strip-debug-arbitrary');
stripDebug('function foo(){console.log("foo");alert("foo");debugger;}').toString();
//=> function foo(){void 0;void 0;}
Returns the modified Esprima AST which can be used to make additional modifications.
Call .toString()
to get the stringified output.
To prevent any side-effects, console.*
/alert*
is replaced with void 0
instead of being stripped.
Type: string
, object
Pass in a string of JavaScript code or a Esprima compatible AST.
Type: string
Optional: Pass the name of the statement to remove (e.g. "log"), if none is given "console" is being used.
Type: array
Optional: Pass an array of properties to exclude (e.g. ["warn", "error"])
MIT © Sindre Sorhus & berstend