Package Exports
- @didnhdj/fnmap
- @didnhdj/fnmap/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@didnhdj/fnmap) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
fnmap
AI code indexing tool for analyzing JS/TS code structure and generating structured code maps
Features
- 🚀 Fast Analysis: Quickly analyze JavaScript/TypeScript code structure using AST
- 📊 Structured Output: Generate
.fnmapindex files with imports, functions, classes, and constants - 🔗 Call Graph: Track function call relationships and dependencies
- 🎯 Git Integration: Process only changed files for efficient workflows
- ⚙️ Flexible Configuration: Support for multiple configuration methods
- 🔌 Pre-commit Hook: Integrate seamlessly with git hooks
- 📦 Programmatic API: Use as a library to process code strings directly
- 🎨 Smart Filtering: Automatically skip type definition files and type-only files
- 🌍 Cross-Platform: Normalized path handling for Windows, macOS, and Linux
Installation
npm install -g @didnhdj/fnmapOr use in your project:
npm install --save-dev @didnhdj/fnmapQuick Start
Initialize Configuration
fnmap --initThis interactive command will:
- Create a
.fnmaprcconfiguration file in your project root - Add fnmap-generated files to
.gitignore(optional) - Automatically append fnmap format documentation to:
CLAUDE.md(project-level instructions for Claude AI)~/.claude/CLAUDE.md(user-level global instructions)AGENTS.md(project-level agent instructions)- Or any custom file path you specify
The appended documentation helps AI assistants (like Claude) understand the .fnmap format, enabling them to:
- Quickly navigate your codebase using the index
- Locate functions and classes by line number
- Understand code structure and call graphs
- Make more informed code suggestions
Basic Usage
# Process files based on configuration
fnmap
# Process specific directory
fnmap --dir src
# Process specific files
fnmap --files index.js,utils.js
# Process git changed files
fnmap --changed
# Process git staged files (for pre-commit hook)
fnmap --staged
# Show detailed processing logs
fnmap --log --dir src
# Clear generated files
fnmap --clearConfiguration
fnmap supports multiple configuration methods (in priority order):
.fnmaprc- JSON configuration file.fnmaprc.json- JSON configuration filepackage.json#fnmap- fnmap field in package.json
Configuration Example
.fnmaprc
{
"enable": true,
"include": [
"src/**/*.js",
"src/**/*.ts",
"src/**/*.jsx",
"src/**/*.tsx"
],
"exclude": [
"node_modules",
"dist",
"build"
]
}package.json
{
"fnmap": {
"enable": true,
"include": ["src/**/*.js", "src/**/*.ts"],
"exclude": ["dist"]
}
}Output Files
.fnmap Index File
The .fnmap file contains structured information about your code:
@FNMAP src/
#utils.js Utility functions
<fs:readFileSync,writeFileSync
<path:join,resolve
readConfig(filePath) 10-25 Read configuration file
parseData(data) 27-40 Parse data →JSON.parse
saveFile(path,content) 42-50 Save file →fs.writeFileSync,path.join
@FNMAPFormat Description:
#filename- File name and description<module:members- Imported modules and membersfunctionName(params) startLine-endLine description →calls- Function information with call graphClassName:SuperClass startLine-endLine- Class information.methodName(params) line description →calls- Instance method+methodName(params) line description →calls- Static method$constName line description- Constant definition ($prefix)>export1,export2,default- Exports (>prefix, supportsdefault,type:Name)
CLI Options
Usage: fnmap [options] [files...]
Options:
-v, --version Show version number
-f, --files <files> Process specified files (comma-separated)
-d, --dir <dir> Process all code files in directory
-p, --project <dir> Specify project root directory (default: current directory)
-c, --changed Process only git changed files (staged + modified + untracked)
-s, --staged Process only git staged files (for pre-commit hook)
-m, --mermaid [mode] Generate Mermaid call graph (file=file-level, project=project-level)
-l, --log Show detailed processing logs
--init Create default config file and setup project (interactive)
--clear Clear generated files (.fnmap, *.fnmap, *.mermaid)
-h, --help Display help informationProgrammatic API
fnmap can be used as a library in your Node.js applications.
Processing Code Strings
import { processCode } from '@didnhdj/fnmap';
const code = `
export function hello(name) {
console.log('Hello, ' + name);
}
`;
const result = processCode(code, { filePath: 'example.js' });
if (result.success) {
console.log('Functions:', result.info.functions);
console.log('Imports:', result.info.imports);
console.log('Call Graph:', result.info.callGraph);
} else {
console.error('Parse error:', result.error);
}Processing Files
import { processFile } from '@didnhdj/fnmap';
const result = processFile('./src/utils.js');
if (result.success) {
console.log('Analysis result:', result.info);
}API Types
// Process result type
type ProcessResult = ProcessSuccess | ProcessFailure;
interface ProcessSuccess {
success: true;
info: FileInfo;
}
interface ProcessFailure {
success: false;
error: string;
errorType: ErrorType;
loc?: { line: number; column: number };
}
// File info structure
interface FileInfo {
imports: ImportInfo[];
functions: FunctionInfo[];
classes: ClassInfo[];
constants: ConstantInfo[];
callGraph: CallGraph;
isPureTypeFile: boolean; // Whether file only contains type definitions
}Use Cases
1. AI Assistant Integration
fnmap is designed to help AI coding assistants understand your codebase better:
# Initialize and setup AI documentation
fnmap --init
# Generate code index for your project
fnmap --dir srcThe .fnmap files help AI assistants:
- Navigate large codebases efficiently
- Find specific functions/classes by name and line number
- Understand module dependencies and call graphs
- Provide context-aware code suggestions
Recommended workflow with Claude Code or similar AI tools:
- Run
fnmap --initto add format documentation toCLAUDE.md - Generate index files with
fnmap --dir src - AI assistants will automatically read
.fnmapfiles for context - Update index when code changes with
fnmap --changed
2. Pre-commit Hook
Add to .husky/pre-commit or .git/hooks/pre-commit:
#!/bin/sh
fnmap --staged
git add .fnmapThis automatically updates the .fnmap index when committing code.
3. CI/CD Integration
# .github/workflows/ci.yml
- name: Generate Code Index
run: |
npm install -g @didnhdj/fnmap
fnmap --dir src
git diff --exit-code .fnmap || echo "Code index updated"4. Code Review
# Generate index for changed files
fnmap --changed
# Show detailed logs during analysis
fnmap --log --changedSupported File Types
.js- JavaScript.ts- TypeScript.jsx- React JSX.tsx- React TypeScript.mjs- ES Modules
Auto-filtered files:
.d.ts,.d.tsx,.d.mts- Type definition files- Files containing only
typeorinterfacedeclarations (pure type files)
Limitations
To ensure performance and safety, fnmap has the following default limits:
- File Size: Maximum 10MB per file
- Directory Depth: Maximum recursion depth of 50 levels
How It Works
- AST Parsing: Uses
@babel/parserto parse code into Abstract Syntax Tree - Structure Analysis: Traverses AST to extract imports, functions, classes, constants
- Call Graph: Tracks function call relationships and dependencies
- Index Generation: Generates compact
.fnmapfiles with structured information
Examples
Example 1: Analyze Single File
fnmap --files src/utils.jsOutput: ```
fnmap - AI Code Indexing Tool
Analyzing: src/utils.js ✓ Imports: 3, Functions: 5, Classes: 0, Constants: 2
Generating .fnmap index... ✓ src/utils.fnmap
================================================== Complete! Analyzed: 1, Failed: 0
### Example 2: Analyze Directory
```bash
fnmap --dir srcGenerates:
src/.fnmap- Code index for all files in src directory
Example 3: Git Workflow
# Make changes to code
git add .
# Generate index for staged files
fnmap --staged
# Add updated index
git add .fnmap
# Commit
git commit -m "Update feature"Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT
Related Projects
- @babel/parser - JavaScript parser
- @babel/traverse - AST traversal
- Mermaid - Diagram generation