Skip to content

A tool for seamless sequence comparison, crafting patches, and effortless synchronization

License

Notifications You must be signed in to change notification settings

codecShivam/TSDiffTool

Repository files navigation

TSDiffTool: TypeScript-Powered File Diff Tool

TSDiffTool is an elegant file diffing and patching tool built in TypeScript, highlighting edit distance and patch generation concepts.

Key Features

  • Text File Differences: Determines and calculates the minimal changes required to transform one text file into another.
  • Patch Generation: Creates concise patch files representing the identified differences.
  • Patch Application: Modifies files based on a provided patch.

Algorithm Insights

The core algorithm, utilizing dynamic programming for edit distance (Levenshtein distance), boasts the following complexities:

  • Time Complexity: O(N * M) (N and M are lengths of input files).
  • Space Complexity: O(min(N , M)) for storing the distance matrix.

The time complexity of the edit distance algorithm is O(N * M) in the worst case. However, Hirschberg's algorithm might have a smaller constant factor, leading to potentially better performance in practice.

Usage

  1. Installation:

    npm install
  2. Generate a Diff:

    ts-node index.ts diff <file1> <file2> > <file.patch>
    • <file1> and <file2>: The paths to the text files you want to compare.
  3. Apply a Patch:

    ts-node index.ts patch <file1> <file.patch>
    • <file1>: The path to the text file you want to patch.
    • <file.patch>: The patch file generated from the diff operation.

Examples

Explore the - examples directory for practical usage scenarios.

Code Overview

Edit Distance Algorithm

// Sample code snippet for editDistance function
function editDistance<T>(s1: T[], s2: T[]): [Action, number, T][] {
  // Implementation details...
  return patch;
}

Subcommands

// Sample code snippet for DiffSubcommand
class DiffSubcommand extends Subcommand {
  // Implementation details...
}

// Sample code snippet for PatchSubcommand
class PatchSubcommand extends Subcommand {
  // Implementation details...
}

// Sample code snippet for HelpSubcommand
class HelpSubcommand extends Subcommand {
  // Implementation details...
}

Contributing

Contributions, pull requests, and suggestions are encouraged to enhance TSDiffTool.

License

TSDiffTool is released under the MIT License.

About

A tool for seamless sequence comparison, crafting patches, and effortless synchronization

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published