Skip to content

Getting Started

Requirements

  • Node.js >= 18
  • TypeScript project with a tsconfig.json

Installation

Install dittory as a dev dependency:

sh
$ npm install -D dittory
sh
$ pnpm add -D dittory
sh
$ yarn add -D dittory
sh
$ bun add -D dittory

Or run directly without installing:

sh
$ npx dittory
sh
$ pnpm dlx dittory
sh
$ yarn dlx dittory
sh
$ bunx dittory

Basic 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 output

Quick 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

Released under the MIT License.