Getting Started
Requirements
- Node.js >= 18
- TypeScript project with a
tsconfig.json
Installation
Install dittory as a dev dependency:
sh
$ npm install -D dittorysh
$ pnpm add -D dittorysh
$ yarn add -D dittorysh
$ bun add -D dittoryOr run directly without installing:
sh
$ npx dittorysh
$ pnpm dlx dittorysh
$ yarn dlx dittorysh
$ bunx dittoryBasic Usage
sh
# Analyze ./src directory (default)
$ dittory
# Analyze a specific directory
$ dittory ./path/to/src
# Set minimum usage count (default: 2)
$ dittory --min=3
# Analyze specific targets
$ dittory --target=react-components # React components only
$ dittory --target=functions # Functions and class methods only
$ dittory --target=all # Both (default)
# Debug mode
$ dittory --debug # Show verbose outputQuick Example
Given this codebase:
tsx
export function Button({ variant, children, onClick }) {
return (
<button className={`btn-${variant}`} onClick={onClick}>
{children}
</button>
);
}tsx
import { Button } from '../components/Button';
export function Home() {
return <Button variant="primary" onClick={() => {}}>Click me</Button>;
}tsx
import { Button } from '../components/Button';
export function About() {
return <Button variant="primary" onClick={() => {}}>Learn more</Button>;
}Running dittory will output:
Button src/components/Button.tsx:1
Constant Arguments:
- variant = "primary"
Usages (2):
- src/pages/Home.tsx:5
- src/pages/About.tsx:5
---
Found 1 function(s) with constant arguments out of 3 function(s).This tells you that variant is always "primary" across all usages, suggesting you could make it the default value.
Next Steps
- Learn about CLI Options for more control
- Configure dittory with a Config File
- Understand the Limitations of the analysis