# function-usage-counter **Repository Path**: a2689737232/function-usage-counter ## Basic Information - **Project Name**: function-usage-counter - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: develop - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-01-12 - **Last Updated**: 2025-01-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # function-usage-counter 一个用于统计前端项目中函数调用次数的工具。支持分析 JavaScript、TypeScript、JSX 和 TSX 文件。 ## 特性 - 📊 统计函数调用次数 - 🔍 支持 JS、TS、JSX、TSX 文件 - 📁 为每个分析的文件生成独立的统计报告 - 🚀 支持命令行和程序化使用 - ⚡ 支持 glob 模式匹配文件 ## 安装 ### 全局安装 `npm install -g function-usage-counter` 默认模式:只统计 React API `function-counter "src//.{ts,tsx}"` 统计所有函数调用 function-counter "src//.{ts,tsx}" --all ### 命令行选项 ```shell bash Options: -V, --version 输出版本号 -a, --all 统计所有函数调用 (默认: false) -f, --functions 要统计的特定函数列表,用逗号分隔 -r, --react-only 只统计 React API (默认: true) -h, --help 显示帮助信息 ``` ### API 使用 ```typescript import { FunctionCounter } from "function-counter"; // 默认模式:只统计 React API const counter = new FunctionCounter(); await counter.analyze("src//.{ts,tsx}"); // 统计指定的函数 const counter = new FunctionCounter({ reactOnly: false, includeFunctions: ["myCustomHook", "useState", "useEffect"], }); await counter.analyze("src//.{ts,tsx}"); // 统计所有函数 const counter = new FunctionCounter({ reactOnly: false, }); await counter.analyze("src//.{ts,tsx}"); ``` ## 输出示例 ```json { "useState": 15, "useEffect": 8, "useMemo": 5, "useCallback": 3 } ``` ## 支持的 React API - useState - useEffect - useContext - useReducer - useCallback - useMemo - useRef - useImperativeHandle - useLayoutEffect - useDebugValue - createContext - memo - forwardRef ## 开发 npm install npm run build ## 许可证 MIT © 2024