npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

console-clean

v1.0.4

Published

Interactive CLI to find and selectively remove console statements from your codebase

Readme

console-clean

Interactive CLI tool to find and selectively remove console statements from your codebase.

Think git add -p but for cleaning up debug logs.

Installation

# Run directly with npx
npx console-clean

# Or install globally
npm install -g console-clean

# Or install as dev dependency
npm install --save-dev console-clean

Usage

Interactive Mode (Default)

Scan your codebase and interactively select which console statements to remove:

console-clean
# or
console-clean ./src

This will:

  1. Scan all JS/TS files
  2. Show each console statement with context
  3. Let you choose: Remove, Keep, Remove all of type, etc.
  4. Preview changes before applying

Scan Mode

List all console statements without removing them:

# Table output
console-clean scan

# JSON output (for CI/tooling)
console-clean scan --json

# Scan specific directory
console-clean scan --path ./src

Clean Mode

Remove all console statements without interaction:

# Remove all (with confirmation)
console-clean clean

# Skip confirmation
console-clean clean --force

# Dry run (show what would be removed)
console-clean clean --dry-run

Configuration

Create a config file in your project root:

.consolecleanrc (JSON)

{
  "include": ["src/**/*", "lib/**/*"],
  "exclude": ["**/*.test.*", "**/*.spec.*"],
  "types": ["log", "debug", "info"],
  "keep": ["error", "warn"],
  "respectGitignore": true,
  "ignoreComments": ["console-clean-ignore", "keep-console"]
}

console-clean.config.js (ESM)

export default {
  include: ['src/**/*'],
  exclude: ['**/*.test.*'],
  types: ['log', 'debug'],
  keep: ['error', 'warn'],
};

package.json

{
  "consoleclean": {
    "types": ["log", "debug"],
    "keep": ["error", "warn"]
  }
}

Ignore Comments

Mark console statements to preserve:

// console-clean-ignore
console.log('This will be skipped');

console.log('This too'); // console-clean-ignore

/* console-clean-ignore */
console.warn('Block comment works too');

Options

Global Flags

  • --path, -p - Directory to scan (default: .)
  • --config, -c - Path to config file

Interactive Mode Flags

  • --no-preview - Skip diff preview before applying

Scan Mode Flags

  • --json - Output as JSON

Clean Mode Flags

  • --force, -f - Skip confirmation prompt
  • --dry-run - Show changes without applying

Examples

# Interactive mode in src directory
console-clean ./src

# Scan and output JSON
console-clean scan --json > console-report.json

# Remove all console.log and console.debug (keep errors/warnings)
console-clean clean

# Dry run to preview changes
console-clean clean --dry-run

# Force remove without confirmation
console-clean clean --force

How It Works

  1. Scanner: Uses fast-glob to find JS/TS files, respects .gitignore
  2. Parser: Uses Babel to parse files and detect console statements
  3. Modifier: Uses magic-string for surgical removal without breaking code
  4. Interactive: Uses inquirer for smooth terminal UI

Features

  • ✓ Detects all console.* methods (log, warn, error, info, debug, etc.)
  • ✓ Interactive selection with context preview
  • ✓ Safe removal preserving code structure
  • ✓ Respects .gitignore patterns
  • ✓ Supports ignore comments
  • ✓ TypeScript and JSX support
  • ✓ Dry run mode
  • ✓ JSON output for CI/tooling

Supported Console Methods

All standard console methods:

  • log, warn, error, info, debug, trace
  • table, dir, group, groupEnd, groupCollapsed
  • time, timeEnd, timeLog
  • assert, count, countReset
  • clear, profile, profileEnd

License

MIT

Author

Nabil Benhamou

Contributing

Issues and PRs welcome at https://github.com/thebiltheory/console-clean