Code Diff Tool
Professional-grade code comparison utility featuring syntax highlighting, JSON sorting, smart formatting, and secure client-side execution.
About
In strict development environments, sending proprietary code to external servers for comparison is a security violation. This tool operates exclusively within your browser's Local Runtime Environment, ensuring that sensitive configuration files, API keys, and algorithms never traverse the network. It bridges the gap between desktop IDEs and web utilities by offering granular, character-level difference detection.
Accuracy in code review dictates that identical data structures should be treated as equal, regardless of formatting. Unlike standard string comparators, this utility includes intelligent pre-processors: it can prettify minified JavaScript, sort JSON keys alphabetically, and normalize XML structures before performing the diff. This eliminates false positives caused by linter rules or serialization discrepancies.
Formulas
The comparison engine utilizes the Myers algorithm to compute the Shortest Edit Script (SES). The goal is to maximize the number of matching items in the trace. The edit distance D is defined as:
Where N and M are the lengths of the sequences. To determine similarity percentage S, we calculate:
For character-level precision inside modified lines, a secondary Levenshtein distance calculation is performed on the specific substrings.
Reference Data
| Diff Type | Visual Indicator | Algorithmic Cost | Use Case |
|---|---|---|---|
| Identity | = Grey | O(1) | Unchanged code blocks |
| Insertion | + Green (Bg) | O(N) | New features, added logic |
| Deletion | − Red (Bg) | O(N) | Deprecated code removal |
| Mutation | Δ Yellow/Blue | O(M×N) | Variable rename, typo fix |
| Whitespace | Dimmed | NULL | Indentation fixes (Tabs vs Spaces) |
| Move | Arrow → | Heuristic | Function reordering |
| Conflict | ! Striped | Manual | Merge conflicts (HEAD vs Incoming) |