uncommenter
v1.0.0
Published
Remove comments from 55+ programming languages. Zero dependencies.
Maintainers
Readme
uncommenter
Remove comments from 55+ programming languages. Zero dependencies. Works everywhere.
The same context-aware parser that powers uncommenter.com, available as an npm package and CLI tool.
Install
npm install uncommenterGlobal CLI:
npm install -g uncommenterQuick Start
As a library
import { uncomment } from "uncommenter";
const result = uncomment('const x = 1; // comment', 'javascript');
console.log(result.processed); // "const x = 1;\n"
console.log(result.commentsRemoved); // 1Auto-detection
import { uncomment, detectLanguage } from "uncommenter";
// Detect by filename
const result = uncomment(code, undefined, "app.py");
// Detect by content
const lang = detectLanguage(code);
console.log(lang.name); // "Python"CLI
# Process a file in-place
uncommenter src/app.ts
# Recursive directory
uncommenter src/ -r
# Preview changes
uncommenter src/ -r --diff --dry-run
# Pipe mode
cat main.py | uncommenter --stdin -l python
# List all 55+ languages
uncommenter languagesAPI
uncomment(source, languageId?, filename?, options?)
Removes comments from source code.
source— the code stringlanguageId— language ID (e.g."python") or omit for auto-detectionfilename— filename for extension-based detectionoptions—{ preserveDocstrings: true, preserveShebangs: true, preserveTodos: false }
Returns { original, processed, language, linesRemoved, commentsRemoved }
detectLanguage(content, filename?)
Auto-detects the programming language from content and/or filename.
removeComments(source, config, options)
Low-level parser. Pass a LanguageConfig directly.
languages
Array of all 55 LanguageConfig objects.
Supported Languages
JavaScript, TypeScript, Python, Java, C, C++, C#, Go, Rust, Ruby, PHP, Swift, Kotlin, Scala, R, Perl, Lua, Shell/Bash, PowerShell, SQL, HTML, CSS, SCSS, YAML, TOML, XML, Haskell, Elixir, Dart, Objective-C, MATLAB, Julia, Groovy, Clojure, F#, VB.NET, Assembly, Zig, Nim, OCaml, Erlang, Fortran, Lisp, Prolog, COBOL, Pascal, Ada, CoffeeScript, V, Crystal, Solidity, Terraform, Dockerfile, Makefile
License
MIT
