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

@drmhse/remove-comments

v1.5.0

Published

A robust, zero-dependency CLI tool for removing comments from source code using token-based state machine parsing. Supports JavaScript, TypeScript, Java, Kotlin, Python, Vue, React, and Dart with advanced template literal processing.

Readme

@drmhse/remove-comments

npm version

A robust, zero-dependency CLI tool for removing comments from source code across multiple programming languages. Implements token-based state machine parsing to safely handle complex language constructs while preserving code functionality.

Features

  • Advanced Parsing Engine: Uses token-based state machine with context awareness for strings, template literals, regular expressions, and escape sequences
  • Template Literal Support: Correctly processes JavaScript template expressions ${...} while preserving nested string content
  • Comprehensive Language Support:
    • JavaScript/TypeScript (.js, .ts, .jsx, .tsx) - Full ES6+ support including template literals
    • Java/Kotlin (.java, .kt, .kts) - C-style comments with proper escape handling
    • Python (.py) - Hash comments and docstring processing
    • Vue (.vue) - Script tag processing with component-aware parsing
    • Dart (.dart) - C-style comments with raw string support
  • Zero Dependencies: Self-contained executable requiring no additional packages
  • Git Integration: Respects .gitignore patterns and monorepo structures
  • Safe Operation: Dry-run mode with detailed preview of all modifications

Usage

Execute directly using npx without requiring project installation.

Preview Changes (Recommended)

Perform a dry run to preview modifications before execution:

npx @drmhse/remove-comments@latest --dry-run

Directory Processing

Process all supported files in the current directory:

npx @drmhse/remove-comments@latest

Target a specific subdirectory:

npx @drmhse/remove-comments@latest src/

Single File Processing

Process an individual file:

npx @drmhse/remove-comments@latest src/main.js

Command Line Options

Usage: remove-comments [options] [path]

Options:
  --dry-run    Preview changes without modifying files
  --help       Display usage information
  --version    Display version information

Arguments:
  path         Target file or directory (default: current directory)

Implementation Details

Parsing Architecture

The tool employs a token-based state machine parser that maintains context awareness across different language constructs:

  • State Management: Tracks current parsing context (code, strings, comments, template literals, escape sequences)
  • Context Preservation: Maintains nested state information for accurate context restoration
  • Token Classification: Distinguishes between comment markers and similar patterns within strings or other contexts

Language-Specific Processing

JavaScript/TypeScript Family:

  • Template literal expressions (${...}) are processed as JavaScript contexts
  • Comments within template expressions are removed while preserving nested strings
  • Regular expression literals are protected from comment-like patterns
  • Full ES6+ syntax support including arrow functions and destructuring

Java/Kotlin:

  • C-style comment processing with proper escape sequence handling
  • Multi-line string and text block support
  • Raw string literal protection in Kotlin

Vue Components:

  • Script tag content extraction and processing
  • Template and style blocks remain unmodified
  • Component-aware parsing maintains Vue.js compatibility

Python:

  • Hash-style comment removal
  • Docstring processing with triple-quote detection
  • String literal preservation with proper escaping

React/JSX:

  • JSX comment syntax ({/* ... */}) preprocessing
  • Standard JavaScript comment processing
  • JSX attribute and expression context awareness

License

MIT