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 🙏

© 2025 – Pkg Stats / Ryan Hefner

clean-context

v0.1.2

Published

Robust, safety-first code cleaner for AI context. Strips comments while protecting strings, URLs, and regex.

Downloads

321

Readme

clean-context

The robust code cleaner for AI context generation.

clean-context strips comments and whitespace noise from code files. Unlike standard compilers, it is designed for LLM Context, meaning it prioritizes token reduction while strictly protecting strings, URLs, and Regex literals.

⚡️ Why clean-context?

  • Token Efficient: Drastically reduces file size for LLM prompts.
  • Safety First: Uses a "Consumer Pattern" regex strategy to ensure http://website.com inside a string isn't truncated by //.
  • Smart Line Removal: Automatically removes the empty whitespace left behind when a full-line comment is deleted.
  • Zero Dependencies: Lightweight and fast.

🚀 Quick Start

CLI

# Clean a file and output to console
npx clean-context script.js

# Clean and save to new file
npx clean-context script.js -o clean.js

# Force a specific language strategy
npx clean-context raw-data.txt --lang .py

Programmatic API

const { clean } = require('clean-context');

// 1. Clean a file (Auto-detects extension)
const cleanCode = clean('./src/index.js');

// 2. Clean a string
const raw = `const x = 10; // comment`;
const result = clean(raw, { lang: '.js' });

{ } Supported Languages

clean-context supports 40+ languages out of the box by mapping file extensions to robust stripping strategies.

| Language / Framework | Extensions | Comment Style | | :--- | :--- | :--- | | JavaScript / TypeScript | .js, .jsx, .ts, .tsx, .mjs, .cjs | //, /* ... */ | | Python | .py | # (Triple quotes preserved) | | Java / Kotlin / Scala | .java, .kt, .kts, .scala | //, /* ... */ | | C / C++ / C# | .c, .cpp, .h, .cs | //, /* ... */ | | Go / Rust / Swift | .go, .rs, .swift | //, /* ... */ | | PHP | .php | //, /* ... */ | | Ruby / Perl | .rb, .pl | # | | Shell / Bash / Zsh | .sh, .bash, .zsh | # | | Config & Data | .yaml, .yml, .toml, .properties, .conf | # | | DevOps | Dockerfile, Makefile | # | | Web | .html, .xml, .svg, .vue, .svelte | <!-- ... --> | | Styles | .css, .scss, .less, .sass | /* ... */, // (for preprocessors) | | SQL | .sql | --, /* ... */ | | Markdown | .md, .markdown | <!-- ... --> |

Smart Fallbacks

If a specific extension isn't listed, you can force a strategy using the --lang flag:

  • Use .js for any C-style language (supports // and /* */).
  • Use .py for any Hash-style language (supports #).
  • Use .html for any XML-style language (supports <!-- -->).

🛡️ Safety Features

We take extra care not to break your code context.

| Feature | Behavior | | :--- | :--- | | Strings | "http://example.com" is preserved (not stripped at //). | | Regex Literals | /^https:\/\// in JS is preserved. | | Triple Quotes | """Docstrings""" in Python are preserved. | | Hash Colors | color: "#ff0000" in Configs/Code is preserved. |

License

MIT

{ github.com/mgks }

Website Badge Sponsor Badge