Conversation
ebfc55a to
6cf30a4
Compare
943efdf to
aee6be8
Compare
42b0ec3 to
8d21774
Compare
6ef2035 to
3d054eb
Compare
8a4fa0b to
d5372fd
Compare
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
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 slower — 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)