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

ast-stripper

v1.0.33

Published

Strip method bodies from source code files

Readme

AST Stripper

A command-line tool to strip method bodies from source code files using tree-sitter. This tool helps you focus on the structure of your code by removing implementation details.

Supported Languages

  • Java
  • Go
  • Python
  • PHP
  • C/C++
  • JavaScript/JSX
  • TypeScript/TSX
  • C#
  • Rust
  • Kotlin
  • Swift
  • Ruby

Installation

npm install -g ast-stripper

Usage

Command Line

# Process a file and output to stdout
ast-stripper path/to/your/file.java

# Process a file and save to a new file
ast-stripper path/to/your/file.java -o stripped.java

API Usage

const { stripMethodBodies, isLanguageSupported } = require('ast-stripper');

// 检查文件是否支持
const isSupported = isLanguageSupported('example.java'); // 返回 true

// 处理文件
if (isSupported) {
  const strippedCode = stripMethodBodies('example.java');
  console.log(strippedCode);
}

Example

Input file (example.java):

public class Example {
    public void method1() {
        System.out.println("Hello");
        int x = 1 + 1;
    }
    
    private String method2() {
        return "World";
    }
}

After running ast-stripper example.java:

public class Example {
    public void method1() {}
    
    private String method2() {}
}

License

MIT

ast-stripper (web-tree-sitter version)

依赖

  • 仅依赖 web-tree-sitter,无需本地编译原生模块。
  • 需要各语言的 .wasm 文件(tree-sitter 语言包的 WebAssembly 版本)。

准备 wasm 语言包

  1. 新建 wasm-languages/ 目录(与 src/strip-method-bodies.ts 里的路径一致)。
  2. 从各 tree-sitter 语言的 GitHub Release 页面下载对应的 .wasm 文件,例如:
  3. 将下载的 .wasm 文件放入 wasm-languages/ 目录。

自动下载 wasm 语言包

你也可以运行以下命令,自动下载所有支持的 wasm 语言包:

npm run download-wasms

用法

1. 安装依赖

npm install

2. 编译 TypeScript

npm run build

3. 使用 API(异步)

const { stripMethodBodies, stripMethodBodiesFromContent } = require('ast-stripper');

(async () => {
  const code = `public class Test { public void method1() { System.out.println("Hello"); } }`;
  const result = await stripMethodBodiesFromContent(code, 'test.java');
  console.log(result);
})();

或处理文件:

(async () => {
  const result = await stripMethodBodies('path/to/Test.java');
  console.log(result);
})();

4. 运行测试

node test.js

注意事项

  • 所有 API 都是 async/Promise 风格,需用 await.then()
  • 必须确保 wasm-languages/ 目录下有对应的 .wasm 文件,否则会报错。
  • 你可以根据需要扩展 src/strip-method-bodies.ts 里的 languageWasmMap,支持更多语言。