apiscan
v1.0.5
Published
CLI tool for analyzing API usage and field usage in TypeScript codebases
Downloads
21
Maintainers
Readme
APIScan
🔍 A powerful CLI tool for analyzing API usage and field usage in TypeScript/JavaScript codebases.
APIScan helps you understand which APIs are being used in your codebase and whether specific fields from API responses are actually being utilized. Perfect for API cleanup, refactoring, and understanding code dependencies.
Features
- 🎯 API Usage Analysis: Check if specific API endpoints are being used
- 📊 Field Usage Analysis: Analyze which fields from API responses are actually used
- 🔍 Pattern Matching: Support for path parameters like
/api/v1/orders/{id} - 🎨 UI Rendering Detection: Identify fields that are rendered in JSX/UI components
- 📝 Multiple Type Definitions: Show all locations where a field is defined
- 🌈 Beautiful Output: Colorful and well-formatted analysis results
- 💬 Interactive Mode: User-friendly prompts for easy usage
Installation
Global Installation
npm install -g apiscanUsing without installation
npx apiscanUsage
Interactive Mode (Recommended)
apiscanThis will start an interactive session where you'll be prompted to enter:
- API pattern to search for
- Field names to analyze (optional)
- Project path
- Verbose output preference
Direct Usage
# Basic API usage check
apiscan "/api/v1/orders"
# API with field analysis
apiscan "/api/v1/orders/{id}" "lastExecutedAt,orderNo"
# Specify project path
apiscan "/api/v1/orders" "fieldName" --project /path/to/your/project
# Enable verbose output
apiscan "/api/v1/orders" "fieldName" --verboseExamples
Check API Usage
apiscan "/api/v1/trading/orders/histories/{type}"Analyze Specific Fields
apiscan "/api/v1/orders/{id}" "lastExecutedAt,status,amount"Output Example
🔍 Analyzing API usage...
┌─────────────────┬──────────────────────────────┐
│ API Pattern │ /api/v1/orders/{id} │
│ Project │ /Users/currybob/src/my-project │
│ Analyzed Files │ 127 files │
└─────────────────┴──────────────────────────────┘
📊 API Usage Analysis Result
✅ API Usage: Found in 5 locations
📍 Usage Locations:
• services/OrderService.ts:25
const response = await fetch('/api/v1/orders/123')
📊 Field Analysis Result: lastExecutedAt
✅ Type Definitions: Found in 3 locations
1. interface Order in types/Order.ts:10
lastExecutedAt: string | null;
2. interface OrderItem in types/OrderItem.ts:18
lastExecutedAt?: string;
3. type OrderHistory in types/History.ts:23
lastExecutedAt: string;
✅ Field Usage: Used in 8 locations
Field Access:
• OrderService.ts:35 - order.lastExecutedAt
• orderHelpers.ts:42 - { lastExecutedAt } = order
UI Rendering:
• OrderList.tsx:156 - <span>{order.lastExecutedAt}</span>
✅ UI Rendering: Rendered in 3 locations
Analysis completed! 🎉 (1.2s)Use Cases
- API Cleanup: Find unused API endpoints before deprecation
- Field Analysis: Identify unused fields in API responses
- Refactoring: Understand field dependencies before making changes
- Documentation: Get insights into how APIs are actually used
- Performance: Optimize API responses by removing unused fields
Supported File Types
- TypeScript (
.ts,.tsx) - JavaScript (
.js,.jsx)
Pattern Matching
APIScan supports flexible API pattern matching:
- Exact paths:
/api/v1/orders - Path parameters:
/api/v1/orders/{id} - Multiple parameters:
/api/v1/users/{userId}/orders/{orderId}
Requirements
- Node.js 14.0.0 or higher
- TypeScript/JavaScript project
Development
# Clone the repository
git clone https://github.com/currycurrybob/apiscan.git
cd apiscan
# Install dependencies
pnpm install
# Build the project
pnpm run build
# Run tests
pnpm test
# Development mode
pnpm run devContributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT © currybob
Changelog
1.0.0
- Initial release
- API usage analysis
- Field usage analysis
- Interactive CLI interface
- Support for TypeScript AST analysis
