strip-debug

Strip console, alert, and debugger statements from JavaScript code

npm install strip-debug
19 downloads in the last day
360 downloads in the last week
1 731 downloads in the last month

strip-debug Build Status

Strip console, alert, and debugger statements from JavaScript code

Useful for making sure you didn't leave any logging in production code.

Also available as gulp/grunt/broccoli plugins.

Install

$ npm install --save strip-debug

Example

var stripDebug = require('strip-debug');

stripDebug('function foo(){console.log("foo");alert("foo");debugger;}').toString();
//=> function foo(){void 0;void 0;}

API

stripDebug(input)

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.

input

Type: String, Object

Pass in a string of JavaScript code or a Esprima compatible AST.

CLI

You can also use it as a CLI app by installing it globally:

$ npm install --global strip-debug

Usage

$ strip-debug src/app.js > dist/app.js

or pipe something to it:

$ echo 'function foo(){console.log("bar")}' | strip-debug
#=> function foo(){}

License

MIT © Sindre Sorhus

npm loves you