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

@tomatobybike/decomment

v0.1.6

Published

Safely remove comments from JavaScript, TypeScript, JSX, TSX, and Vue files using AST.

Readme

📦 decomment

decomment is a CLI tool to safely remove comments from JavaScript, TypeScript, JSX, TSX, and Vue files.

It performs AST-based comment removal to ensure code behavior is never changed. The tool is designed for production codebases, CI pipelines, and teams that care about safety, auditability, and reversibility.

Remove comments — and nothing else.


Features

  • AST-based removal of single-line (//) and block (/* */) comments
  • Preserves comments with specified prefixes (e.g. eslint-, @license)
  • Supports JavaScript, MJS, JSX, TSX, and Vue (script section)
  • Glob patterns for batch processing
  • Optional configuration via decomment.config.js
  • Dry-run mode to preview changes
  • Statistics output (removed / kept comments)
  • Automatic backup with full rollback support
  • Cross-platform (Windows / macOS / Linux)

Installation

Global (recommended)

npm install -g @tomatobybike/decomment

or

yarn global add @tomatobybike/decomment --ignore-engines

Yarn v1 global install is not recommended due to legacy dependency constraints.

Local development

yarn add @tomatobybike/decomment

Usage

# Remove comments
decomment [options] [files/globs]

# Restore files from backups
decomment restore

# Remove all backup files
decomment clean

If no files or globs are provided, decomment scans the current directory by default.


Options

| Option | Description | | ------------ | -------------------------------------------- | | --dry-run | Preview changes without writing files | | --keep | Comma-separated comment prefixes to preserve | | --stats | Show number of comments removed and kept | | -h, --help | Show help message |

Default preserved prefixes:

eslint-, @license, @preserve

Examples

Remove comments from the current project (default behavior)

decomment

Equivalent to:

decomment "**/*.{js,mjs,jsx,tsx,vue}"

Automatically excludes:

  • node_modules
  • dist
  • build
  • .git

Preview changes (dry-run)

decomment "src/**/*.js" --dry-run --stats

Process multiple file types

decomment "src/**/*.{js,mjs,jsx,tsx,vue}" --stats

Preserve specific comment prefixes

decomment "src/**/*.{js,ts}" --keep eslint-,@license --stats

Configuration (decomment.config.js)

An optional configuration file can be placed at the project root.

export default {
  include: ["src/**/*.{js,mjs,jsx,tsx,vue}", "test/**/*.{js,mjs,jsx,tsx,vue}"],
  keep: ["eslint-", "@license", "@preserve"],
};

Config precedence

  1. CLI file/glob arguments
  2. config.include
  3. Default glob (**/*.{js,mjs,jsx,tsx,vue})

Backup & Safety

For each processed file, decomment creates a single backup:

<file>.decomment.bak
  • The backup is overwritten on subsequent runs
  • Designed for intentional, one-shot operations
  • Guarantees full reversibility

Restore & Cleanup

Restore files from backup

decomment restore

Restores files from their .decomment.bak backups.


Remove all backup files

decomment clean

Deletes all .decomment.bak files in the matched scope.


🔍 Comparison with Other Tools

| Feature / Tool | decomment | strip-comments | comment-strip | Babel / esbuild / Terser | | --------------------- | ------------------------------- | -------------- | -------------- | ------------------------ | | AST-based (safe) | ✅ Yes | ❌ Regex-based | ❌ Regex-based | ✅ Yes | | Preserves semantics | ✅ Guaranteed | ❌ Risky | ❌ Risky | ❌ Not guaranteed | | Removes only comments | ✅ Yes | ⚠️ Mostly | ⚠️ Mostly | ❌ No (build output) | | JSX / TSX support | ✅ Yes | ⚠️ Partial | ⚠️ Partial | ✅ Yes | | Vue SFC support | ✅ Script section only | ❌ No | ❌ No | ⚠️ Limited | | Preserve prefixes | ✅ Yes (--keep) | ❌ No | ❌ No | ⚠️ Limited | | Dry-run mode | ✅ Yes | ❌ No | ❌ No | ❌ No | | Statistics output | ✅ Yes | ❌ No | ❌ No | ❌ No | | Backup & rollback | ✅ Yes | ❌ No | ❌ No | ❌ No | | Glob batch processing | ✅ Yes | ⚠️ Limited | ⚠️ Limited | ⚠️ Build-specific | | Config file support | ✅ Yes | ❌ No | ❌ No | ❌ No | | CI / pre-commit ready | ✅ Designed for it | ❌ No | ❌ No | ⚠️ Not intended | | Risk of breaking code | Very Low | Medium | Medium | High | | Primary use case | Production codebase hygiene | Small scripts | Small scripts | Build & minification |


🧠 Why decomment Exists

  • Regex-based tools do not understand syntax and can break code
  • Build tools modify structure, formatting, and semantics
  • decomment removes comments — and nothing else

If you care about safety, reviewability, and deterministic output, this tool is built for you.


🏆 When to Use decomment

  • You want zero behavior changes
  • You need auditable CI output
  • You must preserve ESLint and license comments
  • You work with modern JS / TS / Vue codebases
  • You want safe and reversible operations

🚫 When NOT to Use decomment

  • You just need quick text cleanup
  • You already minify source code
  • You do not care about accidental removals

npm Scripts Integration (Recommended)

decomment is designed to work naturally with npm scripts for safe and repeatable workflows.

{
  "scripts": {
    "decomment": "decomment",
    "decomment:check": "decomment --dry-run --stats",
    "decomment:fix": "decomment --stats",
    "decomment:restore": "decomment restore",
    "decomment:clean": "decomment clean"
  }
}

Common workflows

# Preview comment removal (no file changes)
npm run decomment:check

# Remove comments and create backups
npm run decomment:fix

# Restore all files from backups
npm run decomment:restore

# Remove all .decomment.bak files
npm run decomment:clean

🪝 Pre-commit Hook (Husky)(Optional / Advanced)

Pre-commit Hook (Husky) – Optional

You can integrate decomment into a pre-commit workflow to automatically remove comments before each commit.

⚠️ This is optional and recommended only for teams that already use Husky.

Setup

npm install -D husky
npx husky install
npx husky add .husky/pre-commit

Example .husky/pre-commit

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

echo "🧹 Running decomment..."

npx decomment "src/**/*.{js,mjs,jsx,tsx,vue}" \
  --keep eslint-,@license,@preserve \
  --stats

License

MIT License