Strip console, alert, and debugger statements from JavaScript code
JavaScript
Latest commit 981c7f7 Oct 6, 2015 @sindresorhus tweaks
Permalink
Failed to load latest commit information.
.editorconfig tweaks Oct 5, 2015
.gitattributes init Jan 11, 2014
.gitignore init Jan 11, 2014
.jshintrc init Jan 11, 2014
.travis.yml tweaks Oct 5, 2015
cli.js tweaks Oct 5, 2015
index.js prevent memory leak Mar 12, 2015
package.json tweaks Oct 5, 2015
readme.md tweaks Oct 5, 2015
test.js prevent memory leak Mar 12, 2015

readme.md

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.

Usage

$ npm install --save strip-debug
const 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

$ npm install --global strip-debug
$ strip-debug --help

  Usage
    $ strip-debug <input file> > <output file>
    $ cat <input file> | strip-debug > <output file>

  Example
    $ strip-debug src/app.js > dist/app.js
    $ cat src/app.js | strip-debug > dist/app.js

License

MIT © Sindre Sorhus