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

comment-bear

v1.0.0

Published

Universal comment remover for multiple programming languages with TypeScript support

Readme

GitHub npm Tests License

🐻 A fast and friendly tool for removing comments from code in multiple programming languages. Built with TypeScript and thoroughly tested with 788+ tests to ensure reliability and quality.

✨ Features

  • 🌐 Language Support:

    • Full Support: JavaScript, TypeScript, Python, Java, C#, C, C++, HTML, CSS, SQL
    • Basic Support (using generic comment patterns): PHP, Go, Rust, Swift, YAML, JSON, XML
    • More languages coming soon!
  • 🔍 Automatic language detection by file extension or content

  • 📝 Preserve license comments (optional)

  • 🔒 Type safety with full TypeScript support

  • High performance with minimal dependencies

  • 🧪 Dry-run mode for preview

  • 📦 Easy integration with Node.js and TypeScript projects

Note on Language Support:

  • Full Support: Dedicated comment remover with language-specific rules
  • Basic Support: Uses generic comment patterns that work for most cases but might not handle all edge cases
  • We're actively working on adding more languages and improving existing support

📦 Installation

npm install comment-bear

🚀 Quick Start

TypeScript

import { removeComments } from 'comment-bear';

const code = `
// This is a comment
const hello = () => {
  console.log("Hello World"); // Inline comment
};
`;

const result = removeComments(code, { language: 'javascript' });
console.log(result.code);
// Output:
// const hello = () => {
//   console.log("Hello World");
// };

JavaScript (CommonJS)

const { removeComments } = require('comment-bear');

const code = '# Python comment\nprint("Hello")';
const result = removeComments(code, { language: 'python' });
console.log(result.code); // print("Hello")

JavaScript (ES Modules)

import { removeComments } from 'comment-bear';

const result = removeComments(myCode, { filename: 'script.js' });

📖 API Documentation

removeComments(code: string, options?: RemoveOptions): RemoveResult

Main function for removing comments.

Parameters

  • code (string): Input code to process
  • options (RemoveOptions, optional): Configuration options

RemoveOptions

interface RemoveOptions {
  language?: Lang;              // Explicitly specify language
  filename?: string;            // Filename for auto-detection
  preserveLicense?: boolean;    // Preserve license comments (default: false)
  dryRun?: boolean;            // Test mode without changes (default: false)
  keepEmptyLines?: boolean;    // Preserve empty lines (default: false)
}

RemoveResult

interface RemoveResult {
  code: string;                 // Processed code
  removedCount: number;         // Number of comments removed
  detectedLanguage?: Lang;      // Auto-detected language
}

Supported Languages (Lang)

type Lang = 
  | "javascript" | "typescript" | "python" | "ruby" 
  | "java" | "csharp" | "c" | "cpp"
  | "html" | "css" | "sql" | "yaml"
  | "json" | "xml" | "php" | "go" 
  | "rust" | "swift";

🎯 Usage Examples

Automatic Language Detection

import { removeComments } from 'comment-bear';

// By filename
const result1 = removeComments(code, { filename: 'script.py' });
console.log(result1.detectedLanguage); // "python"

// By content
const htmlCode = '<!DOCTYPE html><!-- Comment --><html></html>';
const result2 = removeComments(htmlCode);
console.log(result2.detectedLanguage); // "html"

Preserving License Comments

const code = `
/*! MIT License - Copyright (c) 2025 */
// Regular comment
const x = 5;
`;

const result = removeComments(code, {
  language: 'javascript',
  preserveLicense: true
});

console.log(result.code);
// Output:
// /*! MIT License - Copyright (c) 2025 */
// const x = 5;

Dry-run Mode

const code = '// Comment\nconst x = 5;';

const result = removeComments(code, {
  language: 'javascript',
  dryRun: true
});

console.log(result.code === code); // true (code was not modified)
console.log(result.removedCount);  // 1 (number of comments that would be removed)

Working with Different Languages

Python

const pythonCode = `
# This is a comment
def hello():
    """Docstring"""
    print("Hello")  # Inline comment
`;

const result = removeComments(pythonCode, { language: 'python' });

Java

const javaCode = `
// Single line comment
/* Multi-line
   comment */
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello"); // Inline
    }
}
`;

const result = removeComments(javaCode, { language: 'java' });

HTML

const htmlCode = `
<!-- This is a comment -->
<div class="container">
  <!-- Another comment -->
  <p>Content</p>
</div>
`;

const result = removeComments(htmlCode, { language: 'html' });

SQL

const sqlCode = `
-- Single line comment
/* Multi-line
   comment */
SELECT * FROM users;
`;

const result = removeComments(sqlCode, { language: 'sql' });

🧪 Testing

# Run tests
npm test

# Run tests with coverage
npm test -- --coverage

# Watch mode
npm test -- --watch

🏗️ Development

# Clone the repository
git clone https://github.com/yourusername/comment-bear.git
cd comment-bear

# Install dependencies
npm install

# Build
npm run build

# Watch mode for development
npm run dev

📁 Project Structure

comment-bear/
├── src/
│   ├── index.ts              # Main entry point
│   ├── types.ts              # TypeScript types
│   ├── detectors/            # Language detectors
│   │   └── language-detector.ts
│   └── removers/             # Language-specific removers
│       ├── javascript-remover.ts
│       ├── python-remover.ts
│       ├── css-html-remover.ts
│       ├── sql-remover.ts
│       ├── c-style-remover.ts
│       └── other-remover.ts
├── test/                     # Test
├── dist/                     # Compiled files (auto-generated)
├── package.json
├── tsconfig.json
└── README.md

🤝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📝 License

MIT License - see the LICENSE file for details.

🙏 Acknowledgments

📞 Contact

🗺️ Roadmap

  • [ ] CLI tool
  • [ ] Support for more languages (Kotlin, Scala, Haskell)
  • [ ] Editor plugins (VS Code, IntelliJ)
  • [ ] GitHub Action for automatic comment removal
  • [ ] Stream API for large file processing
  • [ ] Configuration files (.ucremoverrc)

⭐ If you find this project useful, give it a star on GitHub!