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

@reverse-craft/smart-fs

v2.0.5

Published

Core file processing library for code beautification, truncation, and analysis - supports multiple languages with AST-based and fallback processing

Readme

@reverse-craft/smart-fs

智能代码处理库,提供代码美化、截断、搜索、分析和转换功能,支持多语言和 Source Map 生成。

功能特性

  • 代码美化 - 格式化压缩/混淆代码,生成 Source Map(可在 Chrome DevTools 中设置断点)
  • 智能截断 - 截断超长字符串,保留行号和代码结构
  • 代码搜索 - 在美化后的代码中搜索,返回原始文件位置
  • 变量分析 - 基于 AST 作用域分析,查找变量/函数的定义和引用
  • 代码转换 - 应用自定义 Babel 插件进行代码转换

支持的语言

| 语言 | 美化 | AST 截断 | Source Map | |------|------|----------|------------| | JavaScript/TypeScript | ✓ | ✓ | ✓ | | JSON | ✓ | - | - | | HTML/XML | ✓ | - | - | | CSS | ✓ | - | - | | 其他 | 回退模式 | 回退模式 | - |

安装

npm install @reverse-craft/smart-fs

快速开始

import { smartRead, smartSearch, findUsage } from '@reverse-craft/smart-fs';

// 读取并处理文件
const result = await smartRead('./dist/app.min.js', {
  charLimit: 300,      // 字符串截断长度
  maxLineChars: 500,   // 每行最大字符数
});
console.log(result.code);

// 搜索代码
const searchResult = await smartSearch('./dist/app.min.js', 'function', {
  contextLines: 2,
  caseSensitive: false,
});
console.log(searchResult.formatted);

// 查找变量用法
const usageResult = await findUsage('./dist/app.min.js', 'myFunction');
console.log(usageResult.formatted);

API

便捷函数

smartRead(filePath, options?)

读取文件并进行美化和截断处理。

const result = await smartRead('./app.min.js', {
  startLine: 1,        // 起始行(可选)
  endLine: 100,        // 结束行(可选)
  charLimit: 300,      // 字符串截断长度
  maxLineChars: 500,   // 每行最大字符数
  saveLocal: false,    // 是否保存美化后的文件
});

smartSearch(filePath, query, options?)

在美化后的代码中搜索,返回原始文件位置。

const result = await smartSearch('./app.min.js', 'decrypt', {
  isRegex: false,
  caseSensitive: false,
  contextLines: 2,
  maxMatches: 50,
});

findUsage(filePath, identifier, options?)

查找变量/函数的所有定义和引用。

const result = await findUsage('./app.min.js', '_0x1234', {
  targetLine: 42,      // 指定行号精确定位
  maxReferences: 10,
});

模块导出

库导出以下模块,可按需使用:

// 语言检测
import { detectLanguage, getLanguageInfo, isFullySupportedLanguage } from '@reverse-craft/smart-fs';

// 代码美化
import { beautifyCode, ensureBeautified } from '@reverse-craft/smart-fs';

// 代码截断
import { truncateCode, truncateCodeFromFile, truncateFallback } from '@reverse-craft/smart-fs';

// 代码搜索
import { searchInCode, formatSearchResult } from '@reverse-craft/smart-fs';

// 变量分析
import { analyzeBindings, formatAnalysisResult } from '@reverse-craft/smart-fs';

// 代码转换
import { applyCustomTransform, loadBabelPlugin } from '@reverse-craft/smart-fs';

输出示例

smartRead 输出

/path/to/app.min.js (1-20/5000)
Src=原始位置(用于设置断点)
 1 L1:0       var _0x1234 = function() {
 2 L1:25        var data = "SGVsbG8gV29ybGQ=...[TRUNCATED 50000 CHARS]...base64==";
 3 L1:50078    return decode(data);
 4 L1:50100  };

smartSearch 输出

/path/to/app.min.js
Query="decrypt" (literal, case-insensitive)
Src=原始位置(用于设置断点)
Matches: 3
--- Line 42 ---
  40 L1:1000    function process(data) {
  41 L1:1020      var key = getKey();
>>42 L1:1050      return decrypt(data, key);
  43 L1:1080    }

findUsage 输出

/path/to/app.min.js
Identifier="_0x1234"
Src=原始位置(用于设置断点)
Bindings: 1 (Targeted at line 10)
--- Targeted Scope (const) ---
📍 Definition:
      5 L1:100      const _0x1234 = function() {
🔎 References (3):
     10 L1:200      return _0x1234(); ◀── hit
     15 L1:300      _0x1234.call(this);
     20 L1:400      console.log(_0x1234);

相关包

工作原理

  1. 美化: 使用 esbuild 格式化压缩代码并生成 Source Map
  2. 截断: 使用 meriyah 解析 AST,截断长字符串同时保留换行符
  3. 映射: 使用 source-map-js 将美化后的行映射回原始位置

使用场景

  • 逆向分析混淆/压缩的 JavaScript
  • 理解第三方压缩库
  • 在美化代码中设置断点调试原始代码

License

MIT