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

decomment.js

v1.0.0

Published

Remove all comments from modern JavaScript and TypeScript files via a simple CLI.

Readme

decomment.js

Remove every comment from modern JavaScript and TypeScript files with a single command. The CLI understands JSX, decorators, Flow, TypeScript, and the file extensions used across React, Next.js, and Node.js projects.

Highlights

  • Works with .js, .cjs, .mjs, .jsx, .ts, .tsx, .cts, .mts (configurable via --extensions)
  • Accepts individual files or entire directories (recursively)
  • Safe by default: dry-run mode plus explicit --overwrite gating for in-place edits
  • Write stripped sources somewhere else via --out <file|dir>
  • JSON summaries for scripting plus a programmatic Node API
  • Built on top of @babel/parser, so it keeps pace with the latest language features

Installation

npm install --global decomment.js
# or
npx -p decomment.js decommentjs --help

CLI Usage

Usage: decommentjs [options] <targets...>

Remove comments from modern JavaScript / TypeScript sources.

Arguments:
  targets                   File(s) or directories to process.

Options:
  -o, --out <path>          Write stripped files to this path (file or directory).
      --dry-run             Preview the files that would be written without modifying anything.
      --overwrite           Allow overwriting the input files or existing outputs.
  -e, --extensions <list>   Comma-separated list of file extensions to include.
      --json                Emit a machine-readable JSON summary.
      --silent              Suppress human-readable logs (useful when piping JSON).
  -h, --help                Display help for command

Supported extensions: .js, .cjs, .mjs, .jsx, .ts, .tsx, .cts, .mts

Common examples

# Preview what would change
decommentjs src --dry-run

# Overwrite files in place (requires explicit flag)
decommentjs src --overwrite

# Output to a sibling directory (creates it if needed)
decommentjs src --out dist/stripped

# Process a single file and write to another file
decommentjs component.jsx --out component.strip.jsx

# Emit JSON for scripting
decommentjs app --overwrite --json --silent > report.json

# Limit processed extensions
decommentjs src --extensions .js,.jsx --overwrite

Operational details

  • Directories are traversed recursively; symbolic links are skipped to avoid accidental loops.
  • Only files whose extension matches the allowlist are read or written.
  • When --out is set:
    • Directories mirror the source tree structure.
    • Files are written even if no comments were removed so the output tree is complete.
  • Without --out, the tool requires --overwrite to avoid accidental mutation.
  • --json returns { summaries: [...], totals: { ... } }, mirroring the CLI stats.

Node.js API

const { stripCommentsFromCode, stripPath } = require('decomment.js');

stripCommentsFromCode(code, parserOptions?)

Removes every comment node from the provided string.

Returns:

{
  code: string;          // comment-free source
  commentCount: number;  // number of removed comments
  removedChars: number;  // total character count removed
  removedRanges: Array<{ start: number; end: number }>;
}

You can pass any @babel/parser option (for example a custom plugins array) via parserOptions.

stripPath(targetPath, options?)

Strips an individual file or an entire directory tree.

Options:

| Option | Type | Default | Description | | ------ | ---- | ------- | ----------- | | dryRun | boolean | false | Collect stats without writing files. | | overwrite | boolean | false | Required for in-place edits or when replacing existing outputs. | | outPath | string | undefined | Write results to this file or directory. Required if overwrite is false and you’re not in dry-run mode. | | extensions | string | string[] | Set | built-in list | Override the extension allowlist (provide .js-style entries). | | parserPlugins | string[] | internal presets | Override the parser plugin list. |

Result:

{
  target: string;
  outputBase: string | null;
  filesScanned: number;
  filesChanged: number;
  commentsRemoved: number;
  bytesRemoved: number;
  results: Array<{
    inputPath: string;
    outputPath: string;
    commentCount: number;
    removedChars: number;
    changed: boolean;
    wroteFile: boolean;
  }>;
}

Development

git clone <repo>
cd decomment.js
npm install
npm test

The test suite performs both unit-level (stripCommentsFromCode) and integration (stripPath) checks using temporary files.


License

MIT