-
-
Notifications
You must be signed in to change notification settings - Fork 9
getTextDiff #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
DoneDeal0
wants to merge
14
commits into
main
Choose a base branch
from
text-diff
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
getTextDiff #34
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ebfc55a to
6cf30a4
Compare
943efdf to
aee6be8
Compare
42b0ec3 to
8d21774
Compare
6ef2035 to
3d054eb
Compare
43173c7 to
0e3ec70
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🚀 NEW FEATURE:
getTextDiffCompares two texts and returns a structured diff at a character, word, or sentence level.
FORMAT
Input
previousText: the original text.currentText: the current text.optionsseparationwhether you want acharacter,wordorsentencebased diff.accuracy:normal(default): fastest mode, simple tokenization.high: slower but exact tokenization. Handles all language subtleties (Unicode, emoji, CJK scripts, locale‑aware segmentation when a locale is provided).detectMoves:false(default): optimized for readability. Token moves are ignored so insertions don’t cascade and break equality (recommended for UI diffing).true: semantically precise, but noisier — a single insertion shifts all following tokens, breaking equality.ignoreCase: iftrue,helloandHELLOare considered equal.ignorePunctuation: iftrue,hello!andhelloare considered equal.locale: the locale of your text. Enables locale‑aware segmentation in high accuracy mode.Output
USAGE
WITHOUT MOVES DETECTION
This is the default output. Token moves are ignored so insertions don’t cascade and break equality. Updates are rendered as two entries (
added+deleted). The algorithm uses longest common subsequence (LCS), similar to GitHub diffs.Input
Output
{ type: "text", + status: "updated", diff: [ { value: 'The', index: 0, previousIndex: 0, status: 'equal', }, - { - value: "brown", - index: null, - previousIndex: 1, - status: "deleted", - }, - { - value: "fox", - index: null, - previousIndex: 2, - status: "deleted", - }, + { + value: "orange", + index: 1, + previousIndex: null, + status: "added", + }, + { + value: "cat", + index: 2, + previousIndex: null, + status: "added", + }, + { + value: "has", + index: 3, + previousIndex: null, + status: "added", + }, { value: "jumped", index: 4, previousIndex: 3, status: "equal", }, - { - value: "high", - index: null, - previousIndex: 4, - status: "deleted", - } ], }WITH MOVE DETECTION
If you prefer a semantically precise diff, activate the
detectMovesoption. Direct token swaps are consideredupdated.Input
Output
{ type: "text", + status: "updated", diff: [ { value: 'The', index: 0, previousIndex: 0, status: 'equal', }, + { + value: "orange", + index: 1, + previousValue: "brown", + previousIndex: null, + status: "updated", + }, + { + value: "cat", + index: 2, + previousValue: "fox", + previousIndex: null, + status: "updated", + }, + { + value: "has", + index: 3, + previousIndex: null, + status: "added", + }, + { + value: "jumped", + index: 4, + previousIndex: 3, + status: "moved", + }, - { - value: "high", - index: null, - previousIndex: 4, - status: "deleted", - } ], }📊 BENCHMARK
(Superdiff uses its
normalaccuracy settings to match diff's behavior)